* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Parametric Curves
Survey
Document related concepts
Transcript
Curves Interpolation • Bresenham’s line drawing algorithm is nothing more than a form of interpolation – Given two points, find the location of points in between them – The function (in this case it’s a line) must pass through the given points, by definition Curves • We’ll look at two techniques for generating curves – Interpolation – Approximation • We’ll also see that interpolation is very restrictive when considering parametric curves • Approximation is a much better approach Parametric Curves • Similar to what we saw with lines x x x x t y y y y t 0 0 1 1 0 0 0 t 1 • The parameter t is used to map out a set of (x, y) pairs that represent the line Parametric Curves • In the case of a curve we concern the parametric function is of the form – Q(u) = (x(u), y(u), z(u)) in 3 dimension • The derivative of Q(u) is of the form – Q’(u) = (x’(u), y’(u), z’(u)) • Significance of the derivative? – It is the tangent vector to a given location (u) on the curve Derivative Parametric Curves • In the case of object drawing, u is a spatial parameter • Q(0) is the start of the curve and Q(1) is the end, as was the case for the parametric line Parametric Curves • Curvature ρ Osculating circle of radius ρ touches the curve at exactly 1 point • Curvature k = 1/ ρ • The higher the curvature, the more the curve bends at the given point Parametric Curves • From calculus, a function f is continuous at a value x0 if lim f ( x ) f ( x0) x x0 • In layman’s terms, we can draw the curve without ever lifting our pen from the drawing surface • f(x) is continuous over an interval (a,b) if it is continuous for every point in the interval • We call this C0 continuity Parametric Curves Continuous over (a,b) – C0 a b Continuous over (a,b) – C0 b a Parametric Curves • From calculus, a function’s derivative f’ is continuous at a value x0 if lim f ' ( x ) f ' ( x0) x x0 • In layman’s terms, there are no “sharp” changes in direction • f’(x) is continuous over an interval (a,b) if it is continuous for every point in the interval • We call this C1 (tangential) continuity Parametric Curves Continuous derivative over (a,b) – C1 a b Discontinuous derivative over (a,b) – not C1 b a Parametric Curves • When we need to join two curves at a single point we can guarantee C1 continuity across the joint – Just make sure that the tangents of the two curves at the join are of equal length and direction • If the tangents at the joint are of identical direction but differing lengths (change in curvature) then we have G1 continuity Lagrange Polynomials • To generate a function that passes through every specified point, the type of function depends on the number of specified points – Two points → linear function – Three points → quadratic function – Four points → cubic function • Generating such functions makes use of Lagrange polynomials Lagrange Polynomials • The general form is n P(t ) Pk Ln ,k t k 0 (t t 0)(t t1)...(t t k 1)(t t k 1)...(t t n) L t ( )( )...( t t t t t t (t t ) L t ( ) t t n,k k 0 k n n,k i 0 ,i k 1 i k i • Let’s look at an example k )(t k t k 1)...(t k t n ) k 1 Lagrange Polynomials • For two points: t t P(t ) 1 t t 0 t t P t t P 0 1 0 1 1 0 • For the starting point (t0=0) and ending point (t1=1) 1 0 t t P(t ) P 0 0 1 1 0 P1 P(t ) (1 t ) P0 (t ) P1 Lagrange Polynomials • For three points: t t t t P(t ) 1 2 t t t t 0 2 t t t t 0 1 t t t t P t t t t P t t t t P 0 1 0 2 0 1 0 1 2 1 2 0 2 2 • And it only gets worse for larger numbers of points • Suffice it to say, this isn’t the most optimum way to draw curves – Too many operations per point – Too complex if the artist decides to change the curve 2 A Better Way • The problem with Lagrange polynomials lies in the fact that we try to make the curve pass through all of the specified points • A better way is to specify points that control how the curve passes from one point to the next • We do so by specifying a cubic function controlled by four points • The four points are called boundary conditions Hermite Boundary Conditions P0 P’0 • Two points • Two tangent vectors P1 P’1 Cubic Functions This is why it’s called a “cubic” function • Generalized form Q(u ) a u b u c u D 3 2 • Derivative Q' (u ) 3a u 2b u c 2 • Our goal is to “solve” these equations in “closed form” so that we can generate a series of points on the curve Cubic Functions • There are four unknown values in the equation – a, b, c, and D (remember, a, b, c, and D are vectors in x, y, z) • We need to use these equations to generate values of x, y, and z along the curve • We can generate a closed form solution (solve the equations for x, y, and z) since we have four boundary conditions u = 0 → Q(0) = P0 and Q’(0) = P’0 u = 1 → Q(1) = P1 and Q’(1) = P’1 Solution of Equations • Go to the white board… Implementation • So, all you have to do to generate a curve is to implement this vector equation: ' ' a 2 P0 2 P1 P0 P1 b 3P0 3P1 2 P0' P1' c P0' D P0 Q (u ) au 3 bu 2 cu D • by stepping 0 ≤ u ≤ 1 P0, P1, P0’ and P1’ are vectors in x, y, z so there are really 12 coefficients to be computed and you’ll be implementing 3 equations for Q(u) Qx (u ), Q y (u ), Qz (u ) Implementation • Note that you’ll have to estimate the step size for u or…(any ideas?) • …use your Bresenham code to draw short straight lines between the points you generate on the curve (to fill gaps) • There is no trick (that I’m aware of) comparable to the Bresenham approach Bezier Curves • Similar derivation to Hermite • Different boundary conditions – Bezier uses 2 endpoints and 2 control points (rather than 2 endpoints and 2 slopes) Bezier Curves Control points Endpoints Implementation • So, all you have to do to generate a curve is to implement this vector equation: a P0 3P1 3P2 P3 b 3P0 6 P1 3P2 c 3P0 3P1 D P0 Q (u ) au 3 bu 2 cu D • by stepping 0 ≤ u ≤ 1 P0, P1, P2 and P3 are vectors in x, y, z so there are really 12 coefficients to be computed and you’ll be implementing 3 equations for Q(u) Qx (u ), Q y (u ), Qz (u ) Hermite vs. Bezier • Hermite is easy to control continuity at the endpoints when joining multiple curves to create a path – But difficult to control the “internal” shape of the curve • Bezier is easy to control the “internal” shape of the curve – But a little more (not much) difficult to control continuity at the endpoints when joining multiple curves to create a path • Bottom line is, when creating a path you have to be very selective about endpoints and adjacent control points (Bezier) or tangent slopes (Hermite) Result • Go to the demo program… • My code generates a Hermite curve that is of C1 continuity – As I generate new segments along the curve I join them by keeping the adjoining tangent vectors equal