Curves and Curved Surfaces Adapted by FFL from CSE167: Computer Graphics Instructor: Ronen Barzel UCSD, Winter 2006
Outline for today Summary of Bézier curves Piecewise-cubic curves, B-splines Surface Patches 1
Curves: Summary Use a few control points to describe a curve in space Construct a function x(t) moves a point from start to end of curve as t goes from 0 to 1 tangent to the curve is given by derivative x (t) We looked at: Linear -- trivial case, just to get oriented Bézier curves -- in particular, cubic p 1 p 2 p 1 p 1 p 3 p 0 p 0 Linear Quadratic Cubic p 0 p 2 2
Linear Interpolation: Summary Given two points p 0 and p 1 Curve is line segment between them p 0. 0<t<1 t=0. p 1 t=1 Three ways of writing expression: x(t) (1 t)p 0 (t)p 1 Weighted average of the control points x(t) (p 1 p 0 )t p 0 Polynomial in t 1 1 x(t) p 0 p 1 t 1 0 1 Matrix form 3
Cubic Bézier Curve: Summary Given four points p 0, p 1, p 2, p 3 curve interpolates the endpoints intermediate points adjust shape: tangent handles p 1 Recursive geometric construction de Casteljau algorithm p 0 x Three ways to express curve Weighted average of the control points: Bernstein polynomials Polynomial in t Matrix form p 2 p 3 4
Cubic Bézier: Bernstein Polynomials x(t) B 0 t p 0 B 1 t p 1 B 2 t p 2 B 3 t p 3 The cubic Bernstein polynomials : B 0 t t 3 3t 2 3t 1 B 1 t 3t 3 6t 2 3t B 2 t 3t 3 3t 2 t t 3 B 3 B i (t) 1 Notice: Weights always add to 1 B 0 and B 3 go to 1 -- interpolating the endpoints 5
Cubic Bézier: Polynomial, Matrix, Notation Polynomial in t : x(t) at 3 bt 2 ct d Matrix form: x(t) p 0 p 1 p 2 p 3 G Bez a p 0 3p 1 3p 2 p 3 b 3p 0 6p 1 3p 2 c 3p 0 3p 1 d p 0 1 3 3 1 t 3 3 6 3 0 t 2 3 3 0 0 t 1 0 0 0 1 T B Bez (New) Notation: Bez(t,p 0,p 1,p 2,p 3 ) x(t) for the given control points 6
Tangent to Cubic Bézier Polynomial in t : x (t) 3at 2 2bt c Matrix form: x (t) p 0 p 1 p 2 p 3 G Bez a p 0 3p 1 3p 2 p 3 b 3p 0 6p 1 3p 2 c 3p 0 3p 1 d p 0 1 3 3 1 3t 2 3 6 3 0 2t 3 3 0 0 1 1 0 0 0 0 T B Bez d not used in tangent Notation: Bez (t,p 0,p 1,p 2,p 3 ) x (t) for the given control points 7
n th -order Bézier curve B i n n xt B n i t p i t i0 n i 1 tni t B 0 1 B 1 1 t t 1 B 2 0 t t 2 2t 1 B 3 0 t t 3 3t 2 3t 1 t t B 2 1 t 2t 2 2t B 3 1 t 3t 3 6t 2 3t B 2 2 t t 2 B 3 2 t 3t 3 3t 2 B 3 3 t t 3 8
Evaluate/draw curves by: Sampling uniformly in t x(t) x(0.5) x(1.0) x(0.25) x(0.75) x(0.0) Adaptive/Recursive Subdivision x(t) 9
Outline for today Summary of Bézier curves Piecewise-cubic curves, B-splines Surface Patches 10
More control points Cubic Bézier curve limited to 4 control points Cubic curve can only have one inflection Need more control points for more complex curves With k points, could define a k-1 order Bézier But it s hard to control and hard to work with The intermediate points don t have obvious effect on shape Changing any control point can change the whole curve Want local support: each control point only influences nearby portion of curve 11
Piecewise Curves With a large number of points Construct a curve that is a sequence of simple (low-order) curves end-to-end Known as a piecewise polynomial curve E.g., a sequence of line segments: a piecewise linear curve E.g., a sequence of cubic curve segments: a piecewise cubic curve In this case, piecewise Bézier 12
Continuity For the whole curve to look smooth, we need to consider continuity: C 0 continuity: no gaps. The segments must match at the endpoints C 1 continuity: no corners. The tangents must match at the endpoints C 2 continuity: tangents vary smoothly (curvatures match). (smoother curves.) Note also: G 1, G 2, etc. continuity Looks at geometric continuity without considering parametric continuity Roughly, means that the tangent directions must match, but not the magnitudes Gets around bad parametrizations Often it s what we really want, but it s harder to compute 13
Constructing a single curve from many Given N curve segments: x 0 (t), x 1 (t),, x N-1 (t) Each is parameterized for t from 0 to 1 Define a new curve, with u from 0 to N: x(u) x 0 (u), 0 u 1 x 1 (u 1), 1 u 2 x N 1 (u N 1), N 1 u N x(u) x i (u i), where i u (and x(n) x N 1 (1)) Alternate: u also goes from 0 to 1 x(u) x i (Nu i), where i Nu 14
Piecewise-Linear curve Given N+1 points p 0, p 1,, p N Define curve: x(u) Lerp(u i,p i,p i1 ), i u i 1 (1 u i)p i (u i)p i1, i u p 0 p 1 x(1.5) x(2.9) p 2 p 3 p 4 p 5 x(5.25) p 6 N+1 points define N linear segments x(i)=p i C 0 continuous by construction G 1 at p i when p i-1, p i, p i+1 are collinear C 1 at p i when p i -p i-1 = p i+1 -p i 15
Piecewise Bézier curve: segments Given 3N 1 points p 0,p 1, Define N Bézier segments:,p 3N x 0 (t) B 0 (t)p 0 B 1 (t)p 1 B 2 (t)p 2 B 3 (t)p 3 x 1 (t) B 0 (t)p 3 B 1 (t)p 4 B 2 (t)p 5 B 3 (t)p 6 x N 1 (t) B 0 (t)p 3N 3 B 1 (t)p 3N 2 B 2 (t)p 3N 1 B 3 (t)p 3N p 7 p 8 p 0 p 1 x 0 (t) p 2 p 3 x 1 (t) p 6 x 2 (t) p 9 x 3 (t) p 10 p 11 p 12 p 4 p 5 16
Piecewise Bézier curve x(u) x 0 ( 1 u), 0 u 3 3 x 1 ( 1 u 1), 3 u 6 3 x N 1 ( 1 3 u (N 1)), 3N 3 u 3N 1 x(u) x i u i 3, where i 1 u 3 x 2 (t) x(8.75) x 0 (t) x 1 (t) x 3 (t) x(3.5) 17
Piecewise Bézier curve 3N+1 points define N Bézier segments x(i)=p 3i C 0 continuous by construction G 1 continuous at p 3i when p 3i-1, p 3i, p 3i+1 are collinear C 1 continuous at p 3i when p 3i -p 3i-1 = p 3i+1 -p 3i C 2 is harder to get p 4 p 2 p 1 p 2 P 3 p p 1 P 6 p 3 6 p 4 p 5 p 0 p 0 C 1 discontinuous C 1 continuous p 5 18
Piecewise Bézier curves Used often in 2D drawing programs. Inconveniences: Must have 4 or 7 or 10 or 13 or (1 plus a multiple of 3) points Not all points are the same UI inconvenience: Interpolate, approximate, approximate, interpolate, Math inconvenience: Different weight functions for each point. UI solution: Bézier Handles Math solution: B-spline 19
UI for Bézier Curve Handles Bézier segment points: Interpolating points presented normally as curve control points Approximating points presented as handles on the curve points UI features: All curve control points are the same Can have option to enforce C 1 continuity (www.blender.org) 20
Blending Functions Evaluate using Sliding window Local support: Window spans 4 points Window contains 4 different Bernstein polynomials Window moves forward by 3 units when u passes to next Bézier segment Evaluate matrix in window: x(u) t 3 t 2 t 1 T 1 3 3 1 3 6 3 0 3 3 0 0 1 0 0 0 B Bez p 3i p 3i1 p 3i2 p 3i 3 G Bez where t 1 3 u i and i 1 u 3 21
B-spline blending functions Still a sliding window, but use same weight function for every point Weight function goes to 0 outside the 4-point neighborhood local support -- each spot on curve only affected by neighbors Shift window by 1, not by 3 No discrete segments: every point is the same 1 3 3 1 1 3 6 3 0 x(u) t 3 t 2 t 1 6 3 0 3 0 1 4 1 0 T B B spline p i p i1 p i2 p i 3 G B spline where t u i and i u 22
B-Spline Widely used for surface modeling Intuitive behavior Local support: curve only affected by nearby control points Techniques for inserting new points, joining curves, etc. Does not interpolate endpoints Not a problem for closed curves Sometimes use Bézier blending at the ends But wait, there s more! Rational B-Splines Non-uniform Rational B-Splines (NURBs) 23
Rational Curves Big drawback of all cubic curves: can t make circles! Nor ellipses, nor arcs. I.e. can t make conic sections. Rational B-spline: Add a weight to each point. Homogeneous point: use w. Weight causes point to pull more (or less). With proper points & weights, can do circles. pull more pull less Rational B-splines widely used for surface modeling Need UI to adjust the weight. Often hand-drawn curves are unweighted, but automatically-generated curves for circles etc. have weights. 24
Non-Uniform Rational B-Spline (NURBS) Don t assume that control points are equidistant in u Introduce knot vector that describes the separation of the points. Features Allows tighter bends or corners. Allows corners (C 1 discontinuity). Certain knot values turn out to give a Bézier segment. Allows mixing interpolating (e.g. at endpoints) & approximating. Math is messier Read about it in references. Very widely used for surface modeling Can interactively create as if uniform. Techniques for cutting, inserting, merging, filleting, revolving, etc 25
Outline for today Summary of Bézier curves Piecewise-cubic curves, B-splines Surface Patches 26
Curved Surfaces Remember the overview of curves: Described by a series of control points A function x(t) Segments joined together to form a longer curve Same for surfaces, but now 2 dimensions Described by a mesh of control points A function x(u,v) Patches joined together to form a bigger surface. 27
Parametric Surface Patch x(u,v) describes a point in space for any given (u,v) pair u,v each range from 0 to 1 Rectangular topology v x(0.8,0.7) z y u x(0.4,v) x(u,0.25) x Parametric curves: For fixed u 0, have a v curve x(u 0,v) For fixed v 0, have a u curve x(u,t 0 ) For any point on the surface, there are a pair of parametric curves that go through point v 1 0 u 1 28
Parametric Surface Tangents The tangent to a parametric curve is also tangent to the surface For any point on the surface, there are a pair of (parametric) tangent vectors Note: not necessarily perpendicular to each other v x v Notation: u The tangent along a u curve, AKA the tangent in the u direction, is written as: x (u,v) or u u x(u,v) or x (u,v) u The tangent along a v curve, AKA the tangent in the v direction, is written as: x v (u,v) or v x(u,v) or x v (u,v) x u Note that each of these is a vector-valued function: At each point x(u,v) on the surface, we have tangent vectors u x(u,v) and v x(u,v) 29
Parametric Surface Normal Get the normal to a surface at any point by taking the cross product of the two parametric tangent vectors at that point. Order matters! n x v x u n(u,v) x x (u,v) u v (u,v) Typically we are interested in the unit normal, so we need to normalize n * (u,v) x x (u,v) u v (u,v) n(u,v) n* (u,v) n * (u,v) 30
Polynomial Surface Patches x(s,t) is typically polynomial in both s and t Bilinear: x(s,t) ast bs ct d x(s,t) (at b)s (ct d) -- hold t constant linear in s x(s,t) (as c)t (bs d) -- hold s constant linear in t Bicubic: x(s,t) as 3 t 3 bs 3 t 2 cs 3 t 2 ds 3 es 2 t 3 fs 2 t 2 gs 2 t hs 2 ist 3 jst 2 kst ls mt 3 nt 2 ot p x(s,t) (at 3 bt 2 ct d)s 3 (et 3 ft 2 gt h)s 2 (it 3 jt 2 kt l)s (mt 3 nt 2 ot p) -- hold t constant cubic in s x(s,t) (as 3 es 2 is m)t 3 (bs 3 fs 2 js n)t 2 (cs 3 gs 2 ks o)t (ds 3 hs 2 ls p) -- hold s constant cubic in t 31
Bilinear Patch (control mesh) A bilinear patch is defined by a control mesh with four points p 0, p 1, p 2, p 3 AKA a (possibly-non-planar) quadrilateral Compute x(u,v) using a two-step construction p 2 p 3 v p 0 p 1 u 32
Bilinear Patch (step 1) For a given value of u, evaluate the linear curves on the two u-direction edges Use the same value u for both: q 0 =Lerp(u,p 0,p 1 ) q 1 =Lerp(u,p 2,p 3 ) p 2 q 1 p 3 v p 0 q 0 p 1 u 33
Bilinear Patch (step 2) Consider that q 0, q 1 define a line segment. Evaluate it using v to get x x Lerp(v,q 0,q 1 ) p 2 q 1 v x p 3 p 0 q 0 p 1 u 34
Bilinear Patch (full) Combining the steps, we get the full formula x(u,v) Lerp(v,Lerp(u,p 0,p 1 ),Lerp(u,p 2,p 3 )) p 2 q 1 v x p 3 p 0 q 0 p 1 u 35
Bilinear Patch (other order) Try the other order: evaluate first in the v direction r 0 Lerp(v,p 0,p 2 ) r 1 Lerp(v,p 1,p 3 ) p 2 v r 0 r 1 p 3 p 0 p 1 u 36
Bilinear Patch (other order, step 2) Consider that r 0, r 1 define a line segment. Evaluate it using u to get x x Lerp(u,r 0,r 1 ) p 2 v r 0 x r 1 p 3 p 0 p 1 u 37
Bilinear Patch (other order, full) The full formula for the v direction first: x(u,v) Lerp(u,Lerp(v,p 0,p 2 ), Lerp(v,p 1,p 3 )) p 2 v r 0 x r 1 p 3 p 0 p 1 u 38
Bilinear Patch (either order) It works out the same either way! x(u,v) Lerp(v, Lerp(u,p 0,p 1 ), Lerp(u,p 2,p 3 )) x(u,v) Lerp(u, Lerp(v,p 0,p 2 ), Lerp(v,p 1,p 3 )) p 2 q 1 v r 0 x r 1 p 3 p 0 q 0 p 1 u 39
Bilinear Patch 40
Bilinear patch formulations As a weighted average of control points: x(u,v) (1 u)(1 v)p 0 u(1 v)p 1 (1 u)vp 2 uvp 3 In polynomial form: x(u,v) (p 0 p 1 p 2 p 3 )uv (p 1 p 0 )u (p 2 p 0 )v p 0 41
Bilinear patch: Matrix form We have this matrix form for linear curves: x(t) p 0 p 1 1 1 t 1 0 1 Can derive this for bilinear patches: x x (u,v) v 1 x y (u,v) v 1 x z (u,v) v 1 1 1 1 0 1 0 1 1 1 0 1 1 V T Compactly, we have: x(u,v) V T C x U V T C y U V T C z U BT Lin p 0 x p 2 x p 0 y p 2 y p 0z p 2z where G x,y,z p 1x p 3x p 1y p 3y p 1z p 3z 1 1 u 1 0 1 1 1 u 1 0 1 1 1 u 1 0 1 U B Lin C x B T Lin G x B Lin C y B T Lin G y B Lin C z B T Lin G z B Lin are constants 42
Bilinear Patch Properties of the bilinear patch: Interpolates the control points The boundaries are straight line segments connecting the control points If the all 4 points of the control mesh are co-planar, the patch is flat If the points are not coplanar, get a curved surface saddle shape, AKA hyperbolic paraboloid The parametric curves are all straight line segments! a (doubly) ruled surface: has (two) straight lines through every point Kinda nifty, but not terribly useful as a modeling primitive 43
Bézier Control Mesh A bicubic patch has a grid of 4x4 control points, p 0 through p 15 Defines four Bézier curves along u: p 0,1,2,3 ; p 4,5,6,7 ; p 8,9,10,11 ; p 12,13,14,15 Defines four Bézier curves along v: p 0,4,8,12 ; p 1,6,9,13 ; p 2,6,10,14 ; p 3,7,11,15 Evaluate using same approach as bilinear p 12 p13 v p 4 p 5 p 0 p 1 p 8 p 9 p 14 p 10 p 11 p15 u p 2 p 6 p 7 p3 44
Bézier patch (step 1) Evaluate all four of the u-direction Bézier curves at u, to get points q 0 q 3 q 0 Bez(u,p 0,p 1,p 2,p 3 ) q 1 Bez(u,p 4,p 5,p 6,p 7 ) q 2 Bez(u,p 8,p 9,p 10,p 11 ) q 3 Bez(u,p 12,p 13,p 14,p 15 ) p 12 p13 q 3 v p 8 p 9 p 4 p 5 q 2 q 1 p 14 p15 p 0 p 1 u q 0 p 2 p 6 p 7 p 10 p 11 p3 45
Bézier patch (step 2) Consider that points q 0 q 3 define a Bézier curve; evaluate it at v x(u,v) Bez(v,q 0,q 1,q 2,q 3 ) p 12 p13 q 3 v p 8 p 9 p 4 p 5 q 2 q 1 x p 14 p15 p 0 p 1 u q 0 p 2 p 6 p 7 p 10 p 11 p3 46
Bézier patch (either order) Sure enough, you get the same result in either order. q 0 Bez(u,p 0,p 1,p 2,p 3 ) r 0 Bez(v,p 0,p 4,p 8,p 12 ) q 1 Bez(u,p 4,p 5,p 6,p 7 ) r 1 Bez(v,p 1,p 5,p 9,p 13 ) q 2 Bez(u,p 8,p 9,p 10,p 11 ) r 2 Bez(v,p 2,p 6,p 10,p 14 ) q 3 Bez(u,p 12,p 13,p 14,p 15 ) r 3 Bez(v,p 3,p 7,p 11,p 15 ) x(u,v) Bez(v,q 0,q 1,q 2,q 3 ) x(u,v) Bez(u,r 0,r 1,r 2,r 3 ) v p 4 p 5 q 2 q 1 p 0 p 1 p 12 r 0 r 1 p 8 p 9 p13 q 3 x p 14 p15 r 2 r 3 u q 0 p 2 p 6 p 7 p 10 p 11 p3 47
Bézier patch Properties: Convex hull: any point on the surface will fall within the convex hull of the control points Interpolates 4 corner points. Approximates other 12 points, which act as handles The boundaries of the patch are the Bézier curves defined by the points on the mesh edges The parametric curves are all Bézier curves 48
Evaluating a Bézier patch Most straightforward: follow the 2-step construction Lets you evaluate patch using existing methods for evaluting curves Won t write out the weighted average or polynomial forms But can do matrix form 49
Bézier patch, matrix form U u 1 u 3 u 2 V v 1 v 3 v 2 B Bez C x B T Bez G x B Bez C y B T Bez G y B Bez G x C z B T Bez G z B Bez xu,v V T C x U V T C y U V T C z U 1 3 3 1 3 6 3 0 3 3 0 0 1 0 0 0 T B Bez p 0 x p 1x p 2 x p 3x p 4 x p 5 x p 6 x p 7 x, G p 8 x p 9 x p 10 x p 11x y =, G z = p 12 x p 13x p 14 x p 15 x 50
Bézier patch, matrix form C x stores the coefficients of the bicubic equation for x C y stores the coefficients of the bicubic equation for y C z stores the coefficients of the bicubic equation for z G x stores the geometry (x components of the control points) G y stores the geometry (y components of the control points) G z stores the geometry (z components of the control points) B Bez is the basis matrix (Bézier basis) U and V are the vectors formed from the powers of u and v Compact notation Leads to efficient method of computation Can take advantage of hardware support for 4x4 matrix arithmetic 51
Tangents of Bézier patch The q and r curves we constructed are actually the parametric curves at x(u,v) Remember, tangents to surface = tangents to parametric curves. So we can compute the tangents using the same construction curves! Notice that the tangent in the u direction is for the curve that varies in u, i.e. for the r curve; Similarly, the tangent in the v direction is for the q curve. (Get the normal as usual by taking cross product of the tangents.) v p 4 p 5 q 2 q 1 p 0 p 1 p p 13 12 r 0 r 1 p 8 p 9 q 3 x x v p 14 x p 15 u r 2 r 3 u q 0 p 2 p 6 p 7 p 10 p 11 p3 52
Tangents of Bézier patch, construction x v q 0 Bez(u,p 0,p 1,p 2,p 3 ) q 1 Bez(u,p 4,p 5,p 6,p 7 ) q 2 Bez(u,p 8,p 9,p 10,p 11 ) q 3 Bez(u,p 12,p 13,p 14,p 15 ) (u,v) Be z (v,q 0,q 1,q 2,q 3 ) v p 0 p 1 p p 13 12 r 0 r 1 p 8 p 9 p 4 p 5 q 2 q 1 q 3 x x v x u r 0 Bez(v,p 0,p 4,p 8,p 12 ) r 1 Bez(v,p 1,p 5,p 9,p 13 ) r 2 Bez(v,p 2,p 6,p 10,p 14 ) r 3 Bez(v,p 3,p 7,p 11,p 15 ) (u,v) Be z (u,r 0,r 1,r 2,r 3 ) p 14 x p 15 u r 2 r 3 u q 0 p 2 p 6 p 7 p 10 p 11 p3 53
Tangents of Bézier patch, matrix form The matrix form makes it easy to evaluate the tangents directly: u 3 u 2 U u 1 U x u (u,v) 3u 2 2u 1 0 x(u,v) V T C x U V T C y U V T C z U V V T C x U V T C y U V T C z U v 3 v 2 v 1 x v (u,v) V 3v 2 2v 1 0 V T C x U V T C y U V T C z U 54
Tessellating a Bézier patch Uniform tessellation is most straightforward Evaluate points on a grid Compute tangents at each point, take cross product to get per-vertex normal Draw triangle strips (several choices of direction) Adaptive tessellation/recursive subdivision Potential for cracks if patches on opposite sides of an edge divide differently Tricky to get right, but can be done. 55
Building a surface from Bézier patches Lay out grid of adjacent meshes For C 0 continuity, must share points on the edge Each edge of a Bézier patch is a Bézier curve based only on the edge mesh points So if adjacent meshes share edge points, the patches will line up exactly. But we have a crease 56
C 1 continuity across Bézier edges We want the parametric curves that cross each edge to have C 1 continuity So the handles must be equal-and-opposite across the edge: http://www.spiritone.com/~english/cyclopedia/patches.html 57
Modeling with Bézier patches Original Utah teapot specified as Bézier Patches 58
Modeling Headaches Original Teapot isn t watertight spout & handle intersect with body no bottom hole in spout gap between lid and body Rectangular topology makes it hard to: join or abut curved pieces build surfaces with holes build surfaces with awkward topology or structure 59
Advanced surface modeling B-spline patches For the same reason as using B-spline curves More uniform behavior Better mathematical properties Does not interpolate any control points. 60
Advanced surface modeling NURBS surfaces. Can take on more shapes conic sections kinks Can blend, merge, fillet, Still has rectangular topology, though.. 61
Advanced surface modeling Trim curves: cut away part of surface Implement as part of tessellation/rendering And/or construct new geometry 62
Subdivision Surfaces Arbitrary mesh, not rectangular topology Not parametric No u,v parameters Can make surfaces with arbitrary topology or connectivity Work by recursively subdividing mesh faces Per-vertex annotation for weights, corners, creases Used in particular for character animation: One surface rather than collection of patches Can deform geometry without creating cracks 63