Introduction to Computer Graphics Modeling (1) April 13, 2017 Kenshi Takayama
Parametric curves X & Y coordinates defined by parameter t ( time) Example: Cycloid x t = t sin t y t = 1 cos t Tangent (aka. derivative, gradient) vector: x t, y t Polynomial curve: x t = i a i t i 2
Cubic Hermite curves Cubic polynomial curve interpolating derivative constraints at both ends (Hermite interpolation) x 0 = x 0 x 1 = x 1 x (0) = x 0 x 1 = x 1 x 0 1 t 4 constraints 4 DoF needed 4 coefficients cubic x t = a 0 + a 1 t + a 2 t 2 + a 3 t 3 x t = a 1 + 2a 2 t + 3a 3 t 2 Coeffs determined by substituting constrained values & derivatives x 0 = a 0 = x 0 x 1 = a 0 + a 1 + a 2 + a 3 = x 1 x 0 = a 1 = x 0 x 1 = a 1 + 2 a 2 + 3 a 3 = x 1 a 0 = x 0 a 1 = x 0 a 2 = 3 x 0 + 3 x 1 2 x 0 x 1 a 3 = 2 x 0 2 x 1 + x 0 + x 1 3
Bezier curves Input: 3 control points P 0, P 1, P 2 Coordinates of points in arbitrary domain (2D, 3D,...) Output: Curve P t satisfying P 0 = P 0 P 1 = P 2 while being pulled by P 1 P 0 t=0 P 1 P t =? Eq. of Bezier curve P 2 t=1 P t = 1 t P 0 + t P 2 Eq. of line segment 4
P 1 Bezier curves 1 t t Eq. of line P 12 t P 01 t = 1 t P 0 + t P 1 P 12 t = 1 t P 1 + t P 2 P 01 0 = P 0 P 12 1 = P 2 Eq. of line P 01 t t P 0 t 1 t P 012 t 1 t P 2 Idea: Interpolate the interpolation As t changes 0 1, smoothly transition from P 01 to P 12 P 012 t = 1 t P 01 t + t P 12 t = 1 t 1 t P 0 + t P 1 + t 1 t P 1 + t P 2 = 1 t 2 P 0 + 2t 1 t P 1 + t 2 P 2 Quadratic Bezier curve 5
Bezier curves P 1 P 01 t = 1 t P 0 + t P 1 P 12 t = 1 t P 1 + t P 2 P 01 0 = P 0 P 12 1 = P 2 P 0 P 2 Idea: Interpolate the interpolation As t changes 0 1, smoothly transition from P 01 to P 12 P 012 t = 1 t P 01 t + t P 12 t = 1 t 1 t P 0 + t P 1 + t 1 t P 1 + t P 2 = 1 t 2 P 0 + 2t 1 t P 1 + t 2 P 2 Quadratic Bezier curve 6
Cubic Bezier curve Quad. Bezier P 123 t P 2 Exact same idea applied to 4 points P 0, P 1, P 2 P 3 : As t changes 0 1, transition from P 012 to P 123 P 012 t P 1 Quad. Bezier t 1 t P 0123 t P 3 P 0123 t = 1 t P 012 t + t P 123 t P 0 = 1 t 1 t 2 P 0 + 2t 1 t P 1 + t 2 P 2 + t 1 t 2 P 1 + 2t 1 t P 2 + t 2 P 3 = 1 t 3 P 0 + 3t 1 t 2 P 1 + 3t 2 1 t P 2 + t 3 P 3 Cubic Bezier curve 7
Cubic Bezier curve Exact same idea applied to 4 points P 0, P 1, P 2 P 3 : P 1 P 2 As t changes 0 1, transition from P 012 to P 123 P 0123 t P 3 P 0123 t = 1 t P 012 t + t P 123 t P 0 = 1 t 1 t 2 P 0 + 2t 1 t P 1 + t 2 P 2 + t 1 t 2 P 1 + 2t 1 t P 2 + t 2 P 3 = 1 t 3 P 0 + 3t 1 t 2 P 1 + 3t 2 1 t P 2 + t 3 P 3 Cubic Bezier curve Can easily control tangent at endpoints ubiquitously used in CG 8
n-th order Bezier curve Input: n+1 control points P 0,, P n P t = n i=0 nc i t i 1 t n i P i b i n (t) Bernstein basis function 1 t 4 P 0 + Quartic (4 th ) Quintic (5 th ) 4t 1 t 3 P 1 + 6t 2 1 t 2 P 2 + 4t 3 1 t P 3 + t 4 P 4 1 t 5 P 0 + 5t 1 t 4 P 1 + 10t 2 1 t 3 P 2 + 10t 3 1 t 2 P 3 + 5t 4 1 t P 4 + t 5 P 5 9
Cubic Bezier curves & cubic Hermite curves Cubic Bezier curve & its derivative: P t = 1 t 3 P 0 + 3t 1 t 2 P 1 + 3t 2 1 t P 2 + t 3 P 3 P (t) = 3 1 t 2 P 0 + 3 1 t 2 2t(1 t) P 1 + 3 2t 1 t t 2 P 2 + 3t 2 P 3 Derivatives at endpoints: P 0 = 3P 0 + 3P 1 P 1 = P 0 + 1 3 P 0 P 1 = 3P 2 + 3P 3 P 2 = P 3 1 3 P 1 P (0) P 2 P 1 P 3 Different ways of looking at cubic curves, essentially the same P 0 P (1) 10
Evaluating Bezier curves Method 1: Direct evaluation of polynomials Simple & fast, could be numerically unstable Method 2: de Casteljau s algorithm Directly after the recursive definition of Bezier curves More computation steps, numerically stable Also useful for splitting Bezier curves 11
Drawing Bezier curves In the end, everything is drawn as polyline Main question: How to sample paramter t? Method 1: Uniform sampling Simple Potentially insufficient sampling density Method 2: Adaptive sampling If control points deviate too much from straight line, split by de Casteljau s algorithm 12
Further control: Rational Bezier curve Another view on Bezier curve: Weighted average of control points w 0 = w 2 = 1 P 012 t = 1 t 2 P 0 + 2t 1 t P 1 + t 2 P 2 = λ 0 t P 0 + λ 1 t P 1 + λ 2 t P 2 Important property: partition of unity λ 0 t + λ 1 t + λ 2 t = 1 t Multiply each λ i t by arbitrary coeff w i : ξ i t = w i λ i (t) Normalize to obtain new weights: λ i t = ξ i t j ξ j t Non-polynomial curve can represent arcs etc. 13
Cubic splines x x 0 (t) x 1 (t) x 2 (t) x 3 (t) x 4 (t) Series of connected cubic curves Piecewise-polynomial Share value & derivative at every transition of intervals (C 1 continuity) t 0 t 1 t 2 t 3 t 4 t 5 t Parameter range can be other than [0, 1] Assumption: t k < t k+1 Given values as only input, we want to automatically set derivatives Curve tool in PowerPoint 14
Cubic Catmull-Rom spline Cubic function x k (t) for range t k t t k+1 is defined by adjacent constrained values x k 1, x k, x k+1, x k+2 x x k+1 x k 1 x k (t) x k+2 x k t k 1 t k t k+1 t k+2 t 15
Cubic Catmull-Rom spline: Step 1 As t k t k+1, interpolate such that x k x k+1 Line l k (t) = 1 t t k t k+1 t k x k + t t k t k+1 t k x k+1 x l k 1 (t) l k (t) l k+1 (t) t k 1 t k t k+1 t k+2 t 16
Cubic Catmull-Rom spline: Step 2 As t k 1 t k+1, interpolate such that l k 1 l k Quadratic curve q k (t) = 1 t t k 1 t k+1 t k 1 l k 1 (t) + t t k 1 t k+1 t k 1 l k (t) Passes through 3 points t k 1, x k 1, t k, x k, t k+1, x k+1 x q k (t) q k+1 (t) t k 1 t k t k+1 t k+2 t 17
Cubic Catmull-Rom spline: Step 3 As t k t k+1, interpolate such that q k q k+1 Cubic curve x k t = 1 t t k t k+1 t k q k t + t t k t k+1 t k q k+1 (t) x x k (t) Summary: Derivative at each CP is defined by a quadratic curve passing through its adjacent CPs Each interval is a cubic curve satisfying derivative constraints at both ends t k 1 t k t k+1 t k+2 t 18
Evaluating cubic Catmull-Rom spline P t 3 = P 3 P t 1 = P 1 P t t 1 t t 2 P t 2 = P 2 P t 0 = P 0 A recursive evaluation algorithm for a class of Catmull-Rom splines [Barry,Colgman,SIGGRAPH88] 19
Ways of setting parameter values t k (aka. knot sequence) Assume: t 0 = 0 Uniform t k = t k 1 + 1 Chordal t k = t k 1 + P k 1 P k Centripetal t k = t k 1 + P k 1 P k Parameterization of Catmull-Rom Curves [Yuksel,Schaefer,Keyser,CAD11] 20
Application of cubic Catmull-Rom spline: Hair modeling Parameterization of Catmull-Rom Curves [Yuksel,Schaefer,Keyser,CAD11] 21
B-spline Another way of defining polynomial spline Represent curve as sum of basis functions Cubic basis is the most commonly used Deeply related to subdivision surfaces Next lecture Non-Uniform Rational B-Spline Non-Uniform = varying spacing of knots (t k ) Rational = arbitrary weights for CPs (Complex stuff, not covered) Cool Flash demo: http://geometrie.foretnik.net/files/nurbs-en.swf 22
Parametric surfaces One parameter Curve P(t) Two parameters Surface P s, t Cubic Bezier surface: Input: 4 4=16 control points P ij P s, t = 3 i=0 3 j=0 b i 3 s b j 3 t P ij Bernstein basis functions b 3 0 t = 1 t 3 b 3 1 t = 3t 1 t 2 b 3 2 t = 3t 2 (1 t) b 3 3 t = t 3 23
3D modeling using parametric surface patches Pros Can compactly represent smooth surfaces Can accurately represent spheres, cones, etc Cons Hard to design nice layout of patches Hard to maintain continuity across patches Often used for designing man-made objects consisting of simple parts 24
Pointers http://en.wikipedia.org/wiki/bezier_curve http://antigrain.com/research/adaptive_bezier/ https://groups.google.com/forum/#!topic/comp.graphics.algorithms/2 FypAv29dG4 http://en.wikipedia.org/wiki/cubic_hermite_spline http://en.wikipedia.org/wiki/centripetal_catmull%e2%80%93rom_splin e 25