curves jim van verth ([email protected]). essential math for games animation problem: want to...
TRANSCRIPT
Curves
Jim Van Verth ([email protected])
Essential Math for Games
Animation
• Problem: want to replay stored set of transformations Generated by artist Generated by motion capture
• Two main issues Replaying position Replaying orientation
Essential Math for Games
Animation of Position
• Set of points representing position
• Three issues to handle Frame rate higher than sample rate Reduce number of samples to save
memory Blend between two animation sets
Essential Math for Games
Animation of Position
• Idea: use set of points to define a function
• Can then sample points along that function to find new positions
• Two possibilities: Interpolation (passes through points) Approximation (passes near points)
Essential Math for Games
Parametric Curve
• Function Q(t) Maps parameter t to point on curve Q Commonly broken into ( x(t), y(t), z(t) ) Called space curve Derivative is tangent ( x'(t), y'(t), z'(t) )
Essential Math for Games
Linear Interpolation
• Two points define a line
• Can generate new points between them
Essential Math for Games
• Do this using parameterization of line
Q(t) = P0 + t (P1 – P0) = (1 – t) P0 + t P1
• Parameter t controls position on line
• Curve only defined where t in [0,1]
Linear Interpolation
P0
P1
Essential Math for Games
Multiple Points
• Can linearly interpolate from point to point (piecewise linear curve)
• Problem: get discontinuity at each point
• I.e. not smooth
Demo
Essential Math for Games
Continuity
• Continuous function has no ‘gaps’
• C-continuity Number indicates derivative continuity I.e. C1 means 1st derivative continuous Tangents equal at joins
• G-continuity Tangents point in same direction
Essential Math for Games
Hermite Curves
• One solution
• Idea: Cubic curve between each point
• Tangents at each point specify how curve should go
• Piecewise Hermite spline
Demo
Essential Math for Games
Hermite Curves
• For points P0,P1 and tangents P'0,P'1 function is:
P0P1
P'1P'0
Essential Math for Games
Hermite Curves
• At each sample, two tangents – in and out
• For smooth curve (C1) Make them equal
• Smooth curve but change in speed (G1) Same direction, different lengths
• For crease (C0) Different directions
Essential Math for Games
• Export from commercial tools May have to tweak to guarantee results
• Export from homemade tools
• Clamped, natural, cyclic, acyclic splines Maintain C2 continuity Solution to system of linear equations
Computing Tangents
Essential Math for Games
• Catmull-Rom spline Tangent half vector between neighboring
points
Tangent undefined at end points
Computing Tangents
Pi-1
Pi
Pi+1
Essential Math for Games
Bezier Curve
• Instead of two tangents, have two approximating control points Curve doesn’t pass through control points Their position controls shape of curve Curve lies in convex hull
Essential Math for Games
Bezier Curve
• For points P0, P1, P2, P3 function is:
P0
P1
P2
P3
Essential Math for Games
Bezier Curve
• Control points provide good user interface
• Align control points between curve segments for continuity
Essential Math for Games
De Castlejau's method
• Fast Bezier subdivision
• Find percentage along each segment, then along resulting segments
• Result is control pts for two subcurves
P0
P1P2
P3
Essential Math for Games
De Castlejau’s Method
• Useful for rendering Subdivide until only “straight” subcurves Straight if P1 & P2 are close to P0P3
• Useful for measuring length Subdivide until ||P0P1|| + ||P1P2|| + ||P2P3|| is
close to ||P0P3||
Add up all the sublengths
Essential Math for Games
B-splines
• Generally curve approximates points, i.e. doesn’t pass through them
• Continuous through 2nd derivative
• Provides local control
Essential Math for Games
NURBS
• Non-Uniform Rational B-Splines
• Non-uniform = curve segments have unequal spacing by parameter
• Rational = can apply weights to sample points (good for conic sections)
• Result: very useful, but not cheap
• Mostly used for parametric surfaces
Essential Math for Games
References
• Parent, Rick, Computer Animation: Algorithms and Techniques, Morgan Kaufmann, 2002.
• Bartels, Beatty, Barsky, An Introduction to Splines for use in Computer Graphics & Geometric Modelling, Morgan Kaufmann, 1987.
• Rogers and Adams, Mathematical Elements for Computer Graphics, McGraw-Hill, 1989.
• Rogers, An Introduction to NURBS: With Historical Perspective, Morgan Kaufmann, 2000.