(HERMITE) CURVES Reference: http://en.wikipedia.org/wiki/Cubic_Hermite_spline Lecture #4 BASIC IDEA [Adobe Illustrator / Inkscape demo] [Uses] A dynamic curve defined by: Hermite Curve Control Points (Points) Tangents (Vectors) Hermite Curves are one of the simpler curves. Others include: Bezier NURBS (Non-uniform rational Basis Spline) … Hermite curves (unlike some) actually pass through the control points. NURBS, for example, don’t. Options: Allow discontinuities? [2 tangents per C.P.] Loop? [Last C.P. & Normal = First] NURBS Curve CALCULATING (DRAW) POINTS Suppose we have a curve segment defined by: 2 control points (𝑝0 is the start, 𝑝1 is the end) 2 tangent directions (𝑡 0 at the start point, 𝑡1 at the end point) This is a vector (it might be calculated from a tangent “handle”: a position) Curves are usually defined with a parametric formula Involves a parameter, u, which goes from 0.0 (at the start) to 1.0 (at the end) We can generate intermediate points using this formula: 𝑝(𝑢) = 𝑎 𝑝 0 + 𝑏𝑡 0 + 𝑐 𝑝1 + 𝑑 𝑡 1 𝑎 = 2𝑢 3 − 3𝑢 2 + 1 𝑏 = 𝑢 3 − 2𝑢 2 + 𝑢 𝑐 = −2𝑢 3 + 3𝑢 2 𝑑 = 𝑢3 − 𝑢2 A COMPLETE CURVE Just have 0 – n control points (and a matching tangent) When generating the complete curve Look segment-by-segment (each segment has a 0 <= t <= 1) If we have n control points, there are (n-1) segments. DrawList In pygame it is handy to store a “draw list” of generated points Perhaps controlled by a “resolution” variable? Just use pygame.draw.line to connect them Done!