Vous êtes sur la page 1sur 0

Cyrus Beck Algorithm for Two-dimensional Parametric Line Clipping for Convex

Boundaries


General Discussion (Background)

Cyrus and Beck developed an algorithm for clipping to arbitrary convex regions. Cyrus-
Beck algorithm uses the normal vector for determining whether a point is inside, on, or outside a
window.

Consider a convex planar polygon R.
Consider the parametric representation of a line from P
1
to P
2

P(t) =P
1
+( P
2
P
1
) t 0 t 1

If f is a boundary point of the convex region R and n is an inner normal for one of its
boundaries, then for any particular value of t, i.e. any particular point on line P
1
P
2

n [ P(t) f ] <0 implies that the vector P(t) f is pointed away from the interior of R,
n [ P(t) f ] =0 implies that P(t) f is perpendicular to the normal,
n [ P(t) f ] >0 implies that the vector P(t) f is pointed toward the interior of R.

n[ P(t) f ] >0
f


Together these conditions show that for a convex polygon, an infinite line, which
intersects the boundary of the region, does so at precisely two points. Further, these two points
do not lie on the same boundary edge. Thus n [ P(t) f ] =0 has only one solution. If the point
f lies in the boundary edge for which n is the inner normal, then that point (t) on the line P(t)
which satisfies this condition is the intersection of the line and the boundary edge.


n [ P(t) f ] =0
n [ P(t) f ] <0
OUT IN
Formal Statement of Cyrus-Beck Algorithm

Parametric representation of a line from P
1
to P
2
is P(t) =P
1
+( P
2
P
1
) t, 0 t 1 . .(1)

If f is a boundary point of the convex region R and n is an inner normal for that boundary,

n
i
[ P(t) f
i
] i =1, 2, 3, . (2)

is positive, zero or negative for a point on the parametric line interior to the region, on the region
boundary or exterior to the region respectively.

This relation is applied for each boundary edge, i, of the region. Combining eqns. (1) and (2)
yields the condition for a point on the parametric line which lies on the boundary of the region,
i.e., the intersection point as

n
i
[ P
1
+( P
2
P
1
) t f
i
] =0
or, n
i
[ P
1
f
i
] +n
i
[ P
2
P
1
] t =0 (3)


Let D = P
2
P
1
, the direction of the line,
w
i
= P
1
- f
i
, a weighting factor ( proportional to the distance from the end point of the line to
the boundary point)

(3) becomes t ( n
i
D ) +w
i
n
i
= 0
or, t =- w
i
n
i
/ D n
i
D 0 i =1, 2, 3, .. (4)

D n
i
= 0 if D =0, which implies P
2
=P
1
, i.e. a point
or, D and n
i
are perpendicular, i.e. the line does not intersect the edge.

If P
2
=P
1
then for w
i
n
i
< 0, the point is outside
= 0, on the boundary of
>0, inside
the region or window.

Eqn. (4) is used to obtain the t values for the intersection of the line with each edge of the
window.
Each intersection point is classified as potentially entering (PE) (if D n
i
>0) or potentially
leaving (PL) (if D n
i
<0)

PE with the largest t [i.e. t
E
=max(0, all t
E
)] and PL with the smallest t [i.e. t
L
=min(1, all t
L
)]is
found out.
If t
L
<t
E
, the line is rejected. If the line has not been rejected, then t
E
and t
L
define the endpoints
of the clipped line.
Algorithm
Cyrus_Beck (P
1
, P
2
, n
i,
f
i
, k)
{
Input: P
1
, P
2
(endpoints of line to be clipped),
k (no. of edges of the clipping region),
n
i
(k normal vectors, one for each edge),
f
i
(k boundary points, one in each edge)
/* D is the direction of the line, P
2
- P
1
*/
/* w
i
is the weighting factor, P
1
- f
i
*/
/* t
E
, t
L
are the t values at potentially entering and potentially leaving intersections
respectively*/

/* initialize parameter limits, assuming the entire line is visible*/
t
E
=0;
t
L
=1;
D =P
2
- P
1
; /* calculate the directrix D */
for i =1 to k /* for each edge of the clipping window */
{
calculate w
i
, D.n
i
and w
i
. n
i
for this value of i
if (D n
i
!=0 ) /* the line is not a point */
{
t =- w
i
n
i
/ D n
i
; /*calculate t*/
/* use sign of D n
i
to categorize as PE (Potentially Entering) or PL
(Potentially Leaving) */
if ( D n
i
>0 ) /* PE */
{
if (t >1 )
the line lies entirely outside the clip polygon, so it can be rejected;
else
t
E
=max ( t
E
, t );
}
else /* if PL */
{
if (t <0 )
the line lies entirely outside the clip polygon, so it can be rejected;
else
t
L
=min ( t
L
, t );
}
}
else /* if D n
i
=0 */
if (w
i
n
i
<0)
the line is trivially invisible or an invisible point, so it can be rejected;

} /* end for */
if ( t
E
>t
L
)
return null;
else
return P(t
E
) and P(t
L
) as true clip intersections;
}




















PE
E
1
E
2
E
3
E
4
E
5
E
6
t
2
t
3
t
4
t
6
PL
PE
PL
PL
P
2
t
1
t
5
PE
P
1





Potentially entering intersections (t
E
) : t
1
, t
5
, t
6
. t
Emax
=t
6
Potentially leaving intersections (t
L
): t
3
, t
4
, t
2
. t
Lmin
=t
3
t
6
<=t
3
, hence visible portion is from P(t
6
) to P(t
3
).

Vous aimerez peut-être aussi