Bezier Clipping
Bezier Clipping
Bezier Clipping
Lecture #6
In this lecture, we will discuss how to locate intersections of curves and surfaces and extract parts of surfaces bounded by curves (trimming).
1
1.1
Intersection of Curves
Introduction
Suppose we are given two parametric curves f (u), g(v), and we want to nd the intersection points, that is, pairs of parameter values u0 , v0 , such that f (u0 ) = g(v0 ). We consider 2D curves, so we can write f (u) = [fx (u) fy (u)]T and g(v) = [gx (v) gy (v)]T . Then u0 , v0 satisfy fx (u0 ) gx (v0 ) = 0 fy (u0 ) gy (v0 ) = 0 If the curves are cubic Bezier curves, then this is a system of two cubic equations in two variables. Generally, there are two approaches to solve such polynomial equations. 1. Algebraic approach using exact arithmetic. This approach is robust, but slow. 2. Numerical approach, using approximate calculations with machine accuracy. This approach is not robust. An example is given g 1:
1.2
We start with a simple case to illustrate some general paradigms in the intersection algorithms. We assume that the Bezier curve is cubic throughout this section, though the method can be generalized to any degree. Since the curve is cubic, the number of intersection points can be from 0 to 3. Let the parametric form of the line be (t) = q0 + rt (1)
G22.3033-002: Lecture #6
Left: two curves with 1 intersection point. Mid, Right: after small perturbation, 2 or 0 intersection points can occur.
q0 Figure 2: Intersection of a line and a surface. Here q0 is xed point on the line, r is the direction vector. The normal of the line is n = [ry rx ] (the direction vector rotated by 90 degrees). The implicit equation for the line can be written as n (p q0 ) = 0, or
y x ry x + rx y (rx q0 ry q0 ) = 0
we use the notation L(x, y) = ax + by + c for the right-hand side of the implicit line equation. The coordinate (x, y) of the intersection point of a cubic Bezier curve and the line will be the solution of the system f (u) = [x y]T L(x, y) = 0 (2) (3)
G22.3033-002: Lecture #6
where f (u) is a cubic equation. Combining the two equations we obtain a cubic equation for u: L(fx (u), fy (u)) = 0 (4)
There is a formula to express explicitly the solutions of cubic equation, but it is relatively complex and not that easy to evaluate numerically in a stable way; furthermore there are no explicit formulas for degrees higher than ve. In practice, iterative methods are typically used to solve equations of degree as low as as three. For example, Newtons method is a well-known iterative method used for solving nonlinear equations (see g 3). 1. Pick up initial value x0 . 2. Apply the iterative formula xn+1 = xn
f (xn ) f (xn )
F(u)
F (u0 )
u1 = u0
F (u0 ) F (u0 )
u0
Figure 3: Newton Method. Newtons method is easy to implement, it has potential problems: 1. It is not guaranteed to converge, if f is not twice differentiable, or the initial value is too far from the root, or f (0) = 0 at the root. 2. It nds one solution, not all possible solutions.
G22.3033-002: Lecture #6
1.3
Bezier clipping
We introduce a method called Bezier clipping which guarantees convergence and nds all solutions under certain conditions. Let Bi (u) be the cubic Bernstein polynomials. Since they form a basis for cubic polynomials, we can always write the equation L(fx (u), fy (u)) = 0 as as 3 Pi Bi (u) = 0 i=0 We will add one dimension, to make the above equation into equations: i [ Pi ]T Bi (u) = [u 0]T . 3 3 Recall the denition Bi (u) = Ci (1 u)3i ui , we can directly verify the rst identity. (5)
(6)
So, instead of solving equation L(fx (u), fy (u)) = 0, we look for the intersecting points of curve C with u-axis. Here C is the 2D Bezier curve with control points [0, P0 ]T , [ 1 , P1 ]T , 3 [ 2 , P2 ]T , [1, P3 ]T . 3 Initially, we know that the u value of intersection points is inside the interval [0, 1] if it exists. Using the convex hull property of the Bezier curve, we observe that the intersection points have to be in the intersection of the convex hull of the control points and the u-axis. Suppose the convex hull intersects the u-axis at two points umin , umax , such that 0 umin umax 1. Then we know the intersection point(s) of the Bezier curve and u-axis will be inside [umin , umax ]. Now we subdivide C into three segments, with u ranging in [0, umin ], [umin , umax ], and [umax , 1] respectively. We know that [0, umin ], [umax , 1] can be safely discarded. Now we can iterate by replacing [0, 1] by [umin , umax ].
1.4
Intersection of Curves
Suppose we want to intersect two Bezier curves f (u) and g(v). By convex hull property, if f (u) intersects with g(v), then f (u) has to intersect with convex hull of control points of g(v). Since the convex hull is bounded by four line segments, we can use Bezier clipping to compute intersections how to compute the intersection with them. Once the two intersection points u1 , u2 (with the convex hull) are determined, we can use them to clip f (u) to a shorter segment f (u) : u [u1 , u2 ]. (see g 5) Now we reverse the role of f and g: we clip g 1 = g against the convex hull of f 2 (u) to get g 2 (v). Repeat the above procedure, we get two sequences of curve segments: f 1 (u), f 2 (u), 3 f (u)... and g 1 (v), g 2 (v), g 3 (v) ... which will converge to the intersection points.
Things become more complicated since the set of intersection points of two surfaces can have complex topology. For curves, the topology is very simple: the intersection is a nite set of
G22.3033-002: Lecture #6
F(u)
( 2 , P2 ) 3
(0, P0 )
Figure 4: Bezier Clipping. isolated points, unless parts of the curves coincide. Let f (u, v) and g(s, t) be two surface patches, we make some assumptions: 1. A boundary curve E of f (u, v) intersects g(s, t). 2. The intersection of f (u, v) and g(s, t) is a simple curve, . Then we can nd the intersection curve by 1. Intersect E with g(s, t) to get a point P0 on . 2. From P0 we step in the direction of the tangent to the intersection curve. 3. Then we locate the next point on the intersection curve by solving equations f (u, v) g(s, t) = 0. Comments:
G22.3033-002: Lecture #6
f(u)
g(v)
g(u, v)
P0
Figure 6: Intersecting surfaces 1. We can use Bezier clipping when we try to locate P0 .
2. The intersection set may or may not be a simple curve. For example, it can be a loop as shown in the gure below. This problem can be resolved by loop detection and subdivision, as it is discussed in the paper presented today. Once a loop is detected, we
G22.3033-002: Lecture #6
subdivide the surface patch, until all the loops are separated into simple curves.
Surface Trimming
Trimming can be used to create holes in patches. This operation is very important: once a hole is made, a handle can be attached along the boundary of the hole. In this way we can change the topology of the surface to have arbitrary genus. Consider Bezier surface shown in the gure below. The traditional approach is to dene a closed Bezier curve in the parameter domain of the surface: f : R R2 , s (u, v). Let us examine what happens when we do this in more detail. The boundary curve of the hole on the surface is the composite mapping g(f (s)). If the f is cubic Bezier curve and g is bi-cubic patch, then g f is of degree 9 in s. This leads to problems when we try to attach another patch along the curve: 1. If we continue using bi-cubic patches, then we have to match bi-degree 3 patch and the degree 9 curve along the hole boundary, which is not always possible. As the result, cracks can occur. 2. If we allow use higher order Bezier patches for handles, then we need degree 9 for the rst handle attached. But if we want to attach a second handle to the rst one, we will have to use a degree 27 patch. Required patch degree will grow exponentially.
G22.3033-002: Lecture #6
g(u,v)
v f(s)
s u
Figure 8: Trimming, attaching handles. In practice, approximation is used instead of high order patch which leads to cracks in this type of surface representations. Using subdivision surfaces provides an alternative solution. Instead of introducing a curve in the parameter domain to make a hole, we make a new mesh for the patch with a hole as shown in the gure below. In greater detail this problem is considered in a paper by Litke and others.
G22.3033-002: Lecture #6
g(u,v) g(u,v)