Parametric Curves ================= Motivation ---------- How do we represent a curve? - for a line through space - for some value f(t) used in an animation - etc. Simple question, complicated answers. Basic strategies ---------------- a) Function: e.g. in 2D: y = f(x) Disadvantage: can't represent some curves b) Implicit: f(x,y) = 0 Disadvantage: hard to evaluate c) Parametric: x = f1(u), y = f2(u) Disadvantage: u does not have obvious geometric meaning. We will mostly use parametric form. d) Subdivision: points plus algorithmic rules. In many cases, this is (surprisingly) equivalent to a parametric representation. More on this later, not today. What might we want to do with curves? ------------------------------------- a) Evaluation: . Find location of "all" points on curve (with "all" perhaps being discretized) . Find location of a particular point on curve... - how this is specified depends on representation - x = f(u)... easy to find for particular u. b) Modeling: . Allow user to specify a desired curve (where they are likely working in 'visual' space) . Allow user to intuitively *modifying* a curve. c) Prove/mandate certain properties: . Continuity - For example, is the derivative of the curve continuous? Draw curve that is not G1 continuous. Draw curve that is G1 continuous. - Define continuity: G = geometric (i.e. direction of derivative) C = mathematical (i.e. direction and magnitude of derivative) [more later on the G/C distinction] 0 = position 1 = derivative 2 = 2nd derivative etc. . For example, is the frequency content bandlimited? (normally we don't insist on this) Some of these things are harder to do in certain representations than in others. In particular, modelling can be quite tricky. What did people do before computers? ----------------------------------- - long strips of metal or wood - put weights on them - note: this usually gives G2 continuity Some possible mathematical representations ------------------------------------------ a) Line segments - but can't do better than G0 continuity - often we want something better, particularly if we don't know precision at which we want to evaluate curve yet. b) Sum of sinusoids - allows guarantees on frequency content - hard to control other properties like continuity or lack thereof particularly if piecing together several pieces c) Polynomials - easy to control derivative properties - behave poorly if order of polynomial gets too high - coefficients do *not* behave intuitively (but, we can work around this...) Cubic polynomials ----------------- f(u) = Ax^3 + Bx^2 + Cx + D Cubic is minimum degree that allows both position and first derivatives at endpoints to be independently controlled. Higher degrees are possible too (and allow better control over higher orders of continuity). But higher order polynomials are also harder to control; they tend to want to oscillate. We typically use cubic polynomials in computer graphics. More complex curves (more wiggles -> use splines) ------------------------------------------------- We create more complex curves with piecewise cubic functions. Several ways to do this... more details later. Example: |<--- cubic #1 --->|<--- cubic #2 --->|<--- cubic #3 --->| ... (remember that we are plotting f(u) here. you get more interesting curves by with full plot of (x(u), y(u))). Modelling ---------- Suppose we specify each cubic completely independently. How the heck do we choose the coefficients to get the curve we want? A0 = ? A1 = ? In theory we can make positions match up, and even derivatives. But not at all intuitive to do so. Can we come up with some other parameterization (really basis) of the cubic function that has more meaning??? Specifying position and slope of endpoints ------------------------------------------ This one is called a Hermite Curve. left endpoint (u=0): position = p0 slope = s0 right endpoint (u=1): position = p1 slope = s1 Plug and chug... A(0)^3 + B(0)^2 + C(0) + D = p0 A(1)^3 + B(1)^2 + C(1) + D = p1 3A(0)^2 + 2B(0) + C = s0 3A(1)^2 + 2B(1) + C = s1 OK, so now we see that it is possible to use a different basis for specifying the polynomal. Basis #1: A, B, C, D Basis #2: p0, p1, s0, s1 How could I specify slope in a graphical modeling tool? (tangent line) Specifying position of endpoints plus two other points ------------------------------------------------------ could do this leave as an exercise for the reader... we refer to these points as *control points* Intuitive example: * * * * | | | | note equidistant spacing of u coordinates Approximating control points ---------------------------- So far we have "directly" manipulated points and slopes on the curve, except for the original A,B,C,D basis. By specifying four positions, we have what are called "interpolating" control points. It turns out to be useful (for reasons to come soon...) to be able to control the curve with points that *influence* it, but do not actually lie *on* it. i.e. using approximating (non-interpolating) control points. This is just going to be using a different basis. Intuitive example: * * * * | | | | note equidistant spacing of u coordinates How do we do this mathematically? What we're going to do is to use a basis that consists of four different cubic curves. The weight for each one is specified by one of the control points. The four curves are the Berstein polynomials: b0(u) = (1-u)^3 b1(u) = 3u(1-u)^2 b2(u) = 3u^2(1-u) b3(u) = u^3 Show polynomials... [Figure from Watt, pg. 72, right side] Note that b0(u) + b1(u) + b2(u) + b3(u) = 1 A curve constructed using the Bernstein polynomials is called a Bezier curve. Note: The plots so far have been of the form f(u). But for a 2D spatial curve, you have fx(u) and fy(u). And you usually plot fx(u) and fy(u) on the x/y axes, leaving 'u' invisible. In this form, the control points look like (x,y). You still have four of them. See examples from Watt, pg. 72, left side and pg 73. Piecewise cubic curves ---------------------- We said earlier that if we wanted to build more complex curves, we'd do it with piecewise cubic curves. again, plotting f(u): |<--- cubic #1 --->|<--- cubic #2 --->|<--- cubic #3 --->| ... But once we decide to do this, things get more complicated. Reason: we typically want to insure some amount of continuity between the adjacent curves. Defintely G0. Usually G1. Sometimes G2. Consider what happens for Bezier curves. We get G0 continuity, but not G1 or G2. But we typically want at least G1 continuity. We could impose additional rules to try to force continuity, but this rapidly causes the whole curve manipulation to get geometrically non-intuitive. So instead we need to rethink how our control points work. The key insight: if we want the nearby cubics to share many of their properties (such as derviatives at endpoints), then it makes sense for them to share control points. That way, a change to one control point makes a change to two (or more) cubics. One simple form of this is uniform B-splines. Uniform B-splines ----------------- Four control vertices, just like before. But basis functions are somewhat different. We are going to use a single 4-unit-wide cubic curve, but then shift it for each control point. See Watt pg. 81 for the 4-wide cubic curve. The four shifted versions of the curve (truncated to [0,1] range) are: B0(u) = 1/6 u^3 B1(u) = 1/6 (-3u^3 + 3u^2 + 3u + 1) B2(u) = 1/6 (3u^3 - 6u^2 + 4) B3(u) = 1/6 (1-u)^3 defined for u=[0,1] Show figure from Watt, pg. 82, at bottom. Control points are just the weights for the four functions. With this sceme, none of the control points are interpolated. B-splines have C2 continuity!! But do not interpolate *any* of their control points. Other things you will hear about -------------------------------- * Non-uniform B-splines: With *uniform* B-splines, the control points are located at uniform intervals in u. Not the case for *non-uniform* B-splines. * Rational splines (e.g. NURBS -- non-uniform *RATIONAL* B-splines) f(u) = fx(u) ---- fw(u) f(u) = (fx(u) fy(u)) -----, ----- fw(u) fw(u)) Advantages: - invariance properties under perspective projection - exact representation of conic sections GEOMETRIC VS. PARAMETRIC CONTINUITY =================================== (details of this can be skipped if necessary) G0 = curve segments join together G1 = directions of tangent vectors two curves are equal (but not necessarily the magnitudes of the tangent vectors) tangent_vector_1 = k * tangent_vector_2 k > 0 C1 = directions *AND* magnitudes of tangent vectors are equal. This is 'parametric continuity'. Cn = directions *AND* magnitudes d^n/dt^n [Q(t)] for all derivatives through 'n'th derivative are equal. The tanget vector Q'(t) is the velocity of a point on the curve with respect to the parameter 't'. ... In general, C1 continuity implies G1 continuity, but the converse is generally not true. ... There is a special case in which C1 continuity does *not* imply G1 continuity: When both segments' tangent vectors are [0 0 0] at the join point. In this case, the tangent vectors are indeed equal, but their (geometric) directions can be different. --------- Example of G1 continuity but not C1 continuity: curve #1: x(u) = u y(u) = u curve #2: x(u) = 2u y(u) = 2u with a join point at u=0. In both cases the tangent vector has a normalized direction of (0.5, 0.5). But the magnitudes of the directions are different: (1,1) in the first case, but (2,2) in the second case.