CS 551/651 Advanced Graphics Arc Length Assignment 1 • • • • • Due Week from Thursday Building a Cubic Bézier curve OpenGL/Glut Insert up to 100 points Render Bézier curve using recursive subdivision • Left mouse button to add, middle to move, and right to remove • FLTK is extra credit Papers for Next Tuesday Presenters Needed • Tour Into the Picture • William T. Reeves, Particle systems - a technique for modelling a class of fuzzy objects. In SIGGRAPH '83, Computer graphics 17, 3, July 1983. • " Animation of plant development," Przemyslaw Prusinkiewicz, Mark S.Hammel, and Eric Mjolsness. Siggraph 1993. Arc Length • Arc length is the distance along the curve • To ensure constant speed of curve evaluation, perform arc length parameterization of curve – Compute a mapping offline of arc length values to parameter values – Analytically compute arc length Arc Length • Given parameters u1 and u2, find LENGTH(u1, u 2) • Given an arc with length s and a parameter u1, find u2 s.t. LENGTH (u1, u2) is s • Can we compute s = G(u) = distance from start of curve to point at u? • If so, G-1 is used to build arc length parameterized curve: P(G-1(s)) Analytic Computation x P(u ) u2 u2 dP length(u1, u 2) s du du u1 u1 Cubic curve example: P(u ) au 3 bu 2 cu d dP / du 3au 2 2bu c 3au u2 s u1 2 2 2bu c du dP / du du 2 Forward Differencing • Sample curve a many parameter values • Create piecewise linear representation of curve from parameter evaluations • Compute linear distance between samples • Store distances in table • Limitations/Shortcomings? Adaptive Approach • Adaptively subdivide • First step, compare: – length (start, middle) + length (middle, end) – length (start, end) • If error is too large, subdivide • Use link list to store data Numerical Computation • Numerical methods exist to approximate integral of curve given sample points/derivatives • Instead of using sum of linear segments, use numerical method to compute sum of curved segments Gaussian Quadrature • Commonly used to integrate function between –1 and +1 • Function to be integrated is evaluated at fixed points within [-1, 1] and multiplied by a precalculated weight f (u) w f (u ) • More sample points leads to better accuracy 1 i 1 i i Adaptive Gaussian Integration • Gaussian quadrature uses sampling to preseve accuracy – How many samples are necessary for given curve? • Adaptive gaussian integration monitors errors to subsample when necessary • Start trying few samples and add more as necessary • Recursive like spline subdivision Adaptive Gaussian Integration • Build a table that maps parameter values to arc length values • To solve arc length at u, find ui and ui+1 that bound u • Use gaussian quadrature to compute intermediate arc length between that at ui and ui+1 Finding u given s • Must compute u s.t. length (u1, u) = s • Solve: s – length(u1, u) = 0 – Find the zeros (roots) of the function • Newton-Raphson does this for us: f ( pn 1 ) pn pn 1 f ( pn 1 ) • f = s – length(u1, pn-1) f’= dp/du evaluated at pn-1 Newton-Raphson • Be aware that Newton-Raphson could set pn to a value not defined by curve • f’(pn-1) could be 0 (cannot divide by 0) Speed Control • Given arc-length parameterized curve • Let s(t) define amount the curve has traveled given t – For simplicity, normalize total distance to 1 – Monotonic (can’t go backwards) and continuous • To ease in/out, make s(t) = ease (t) that looks like: s(t) t Speed Control • Easing in/out: sin t 1 2 s(t ) ease(t ) 2 • -pi/2 shifts curve rightward • +1 shifts curve upward • Divide by 2 scales from 0 to 1 Speed Control • Transcendental functions are expensive – Table lookups are one possibility\ – Roll your own • User specifies acceleration period, deceleration period, and max velocity vel(t) v0 t1 t2 t v0 t1 t2 t Speed Control • Distance traveled is area under curve 1 1 1.0 v0 t1 v0 (t 2 t1 ) v0 (1.0 t 2 ) 2 2 • User selects two of three unknowns and distance traveled constraint determines third • Integrate velocity function to find s(t) d v0 d v0 t2 2 t1 0.0 t t1 t1 v0 (t t1 ) 2 t1 t t 2 SLERPing • Quaternions are points on the unit sphere in four dimensions – Unit sphere in three dimensions plus a fourth dimension representing the rotation about the normal at a point on the sphere • Interpolating quats – Linearly interpolate each of four components • Doesn’t quite work right SLERPing • Linear interpolation doesn’t produce constant velocity interpolation of quats • Instead, interpolate along the arc on sphere between two quats SLERPing • Which way do we go? – Long way or short way around sphere • q = [s,v] = [-s,-v] = -q • Compute angle between q1 and q2 – Four dimensional dot product • cos(Q q1qq2 = s1*s2 + v1 q v2 – If positive, this is shortest, – Else, interpolate between q1 and -q2 SLERPing • SLERP: slerp (q , q , u) ((sin(( 1 u) )) /(sin ) q (sin( u )) /(sin ) q • Unit quaternion is not guaranteed 1 2 1 • What about continuity of interpolation? 2 Continuity of SLERP • Interpolate between points – [p0, …, pn-1, pn, pn+1, …] • Bezier interpolation would compute intermediate points for each pn – To define tangent at pn – Define bn to be point before pn – Define an to be point after pn Continuity of SLERP • an = (pn – pn+1 + pn * ½) + (½ * pn+1) pn pn-1 pn+ pn – pn+1 an pn+1 • pn + pn – an = bn Continuity of SLERP • To compute midway (average) points between quats, SLERP halfway • Instead of adding vectors, concatenate rotations P1 = slerp(qn, qn, 1/3) an bn+1 P2 = slerp(an, bn+1, 1/3) P3 = slerp (bn+1, qn+1, 1/3) P12 = slerp (p1, p2, 1/3) qn qn+1 P23 = slerp (p2, p3, 1/3) P = slerp (p12, p23, 1/3)