cs 551/651 advanced graphics arc length. assignment 1 due week from thursday building a cubic...
TRANSCRIPT
CS 551/651Advanced 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 TuesdayPresenters 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, u2)
• 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
2
1
22
1
/)2,1(
)(u
u
u
u
dududPdudu
dPsuulength
uPx
2
1
22
2
23
23
23/
)(
u
u
ducbuaus
cbuaududP
dcubuauuP
Cubic curve example:
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
• More sample points leadsto better accuracy
i
ii ufwuf )()(1
1
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 = s – length(u1, pn-1) f’= dp/du evaluated at pn-1
)(
)(
1
11
n
nnn pf
pfpp
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:
t
s(t)
Speed Control
• Easing in/out: 2
12
sin)()(
tteasets
• -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
t
vel(t)
t1 t2
v0
Speed Control
• Distance traveled is area under curve
• User selects two of three unknowns and distance traveled constraint determines third
• Integrate velocity function to find s(t)
tt1 t2
v0
)0.1(2
1)(
2
10.1 2012010 tvttvtv
21101
0
11
2
0
)(2
0.02
tttttvt
vd
ttt
tvd
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(q1q2 = s1*s2 + v1 v2
– If positive, this is shortest,– Else, interpolate between q1 and -q2
SLERPing
• SLERP:
• Unit quaternion is not guaranteed
• What about continuity of interpolation?
2121 )/(sin))(sin()/(sin)))1((sin((),,( ququuqqslerp
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 – an = bn
pn-1
pn
pn+1
an
pn+ pn – pn+1
Continuity of SLERP
• To compute midway (average) points between quats, SLERP halfway
• Instead of adding vectors, concatenate rotations
an bn+1
qn+1qn
P1 = slerp(qn, qn, 1/3)
P2 = slerp(an, bn+1, 1/3)
P3 = slerp (bn+1, qn+1, 1/3)
P12 = slerp (p1, p2, 1/3)
P23 = slerp (p2, p3, 1/3)
P = slerp (p12, p23, 1/3)