Graphics Reference
In-Depth Information
procedure DrawLine ( integer x 0 , y 0 , z 0 , x 1 , y 1 , z 1 )
{ We assume that (x 1 - x 0 ) ≥ (y 1 - y 0 ) ≥ (z 1 - z 0 ) .
The procedure Draw (x,y,z) is assumed to draw a voxel at location (x,y,z) on the
three-dimensional raster. }
begin
integer dx, dy, dz, d xy , posInc xy , negInc xy , d xz , posInc xz , negInc xz , x, y, z;
dx := x 1 - x 0 ; dy := y 1 - y 0 ; dz := z 1 - z 0 ;
d xy := 2*dy - dx; posInc xy := 2*dy; negInc xy := 2*(dy - dx);
d xz := 2*dz - dx; posInc xz := 2*dz; negInc xz := 2*(dz - dx);
x := x 0 ; y := y 0 ; z := z 0 ;
Draw (x, y, z);
while x < x 1 do
begin
if d xy £ 0
then
begin
d xy := d xy + posInc xy ;
if d xz £ 0
then d xz := d xz + posInc xz ;
else
begin
d xz := d xz + negInc xz ;
z := z + 1;
end
end
else
begin
d xy := d xy + negInc xy ;
if d xz £ 0
then d xz := d xz + posInc xz ;
else
begin
d xz := d xz + negInc xz ;
z := z + 1;
end
y := y + 1;
end ;
x := x + 1;
Draw (x, y, z);
end
end ;
Algorithm 10.4.1.1.
A 26-connected line drawing.
Search WWH ::




Custom Search