Graphics Reference
In-Depth Information
boolean function LB_Clip ( ref real x0, y0, x1, y1; real xmin, ymin, xmax, ymax)
{ This function clips the segment from (x0, y0) to (x1, y1) against the window
[xmin, xmax]¥[ymin, ymax]. It returns false if the segment is entirely outside the
window and true otherwise. In the latter case the variables x0, y0, x1, and y1 will
also have been modified to specify the final clipped segment. }
begin
real t0, t1, dx, dy;
boolean more;
t0 := 0; t1 := 1; dx := x1 - x0;
Findt (-dx,x0 - xmin,t0,t1,more); { left bdry }
if more then
begin
Findt (dx,xmax - x0,t0,t1,more); { right bdry }
if more then
begin
dy := y1 - y0;
Findt (-dy,y0 - ymin,t0,t1,more); { bottom bdry }
if more then
begin
Findt (dy,ymax - y0,t0,t1,more); { top bdry }
if more then
begin { clip the line }
if t1 < 1 then
begin { calculate exit point }
x1 := x0 + t1*dx;
y1 := y0 + t1*dy;
end ;
if t0 > 0 then
begin { calculate entry point }
x0 := x0 + t0*dx;
y0 := y0 + t0*dy;
end ;
end
end
end
end ;
return (more);
end ;
procedure Findt ( real denom, num; ref real t0, t1; ref boolean more)
begin
real r;
more := true ;
Algorithm 3.2.3.2.
The Liang-Barsky line-clipping algorithm.
Search WWH ::




Custom Search