Вы находитесь на странице: 1из 2

Cyrus Beck line clipping algorithm:

The Cyrus-Beck algorithm is of O(N) complexity algo., and it is primarily


intended for a clipping a line in the parametric form against a convex
polygon in 2 dimensions or against a convex polyhedra in 3 dimensions.

The Cyrus-Beck line clipping algorithm uses vector ideas to compute a line clipped to a
convex polygon. Here the input would be the line L and the polygon. The parametric
vector form for a straight line can be written as-
P(t) = P0 + t (P1 - P0)
The above equation is a "mathematical" shorthand for the pair of equations:
x(t) = x0 + t(x1 - x0)
y(t) = y0 + t(y1 - y0)
this equation can be turned into computer code easily.
Consider any edge E from the polygon. Let Q be any point on
the edge E and consider there is a vector from Q to any point on the line L. Since the
point is on the line L, it has to satisfy the vector form of the line equation. Thus, there is a
value t with P(t) producing the point, so that the vector then becomes P(t) - Q.
Using the OUTER NORMAL, N, to the edge E, we can
decide inside/outside for the point P(t) by examining the sign of the dot product of N and
P(t)-Q.
The outer normal is the one which lies in the outside. In function terms we would write
this as dotproduct (N, P(t)-Q). The sign will be based on the cos(A) where A = angle
between N and P(t)-Q and this angle will tell us inside/outside
if (dotProduct(N,P(t)-Q) > 0)
P(t) is OUTSIDE //since A < 90 degrees

else if (dotProduct(N,P(t)-Q) < 0)


P(t) is INSIDE //since A > 90 degrees

else
P(t) SHOULD BE ON EDGE E

Since we want the intersection of line L and edge E, this last case is the one that where
we want (dotProduct (N,P(t)-Q) = 0).
Using this result in P(t)= P0 + t(P1 - P0) . and solving for t by using various vector and
scalar/vector and dot product rules we get -
t = - dotProduct(N,P0-Q) / dotProduct(N,P1-P0)

Here if the numerator > 0 then N is the outer normal and convexity means that L misses
the clipping area entirely. If the numerator is < 0 then L is on the inside BUT there will
be NO intersection with the edge E to compute so we can go on. If numerator == 0 then E
and L are the same line and the problem is finished.

* the cyrus beck algorithm is very similar to Liang-Barsky algorithm. The difference is
that Liang-Barsky is a simplified Cyrus-Beck variation that was optimized for a
rectangular clip window.

Вам также может понравиться