CS 551/651 Advanced Graphics Technical Background

advertisement
CS 551/651
Advanced Graphics
Technical Background
FLTK
• Hopefully you downloaded and
compiled successfully
– Questions
• Assignment 1 – Warmup
– Interactive B-Spline Editor
– Due two weeks from today
Topics you should know
• Object, world, camera coord spaces
• Lookat point, up vector, angle of view,
near/far clipping planes, view frustum
• Homogeneous coords
• Transformation matrices
• Rendering pipeline
Affine Transformations
• A transformation that preserves
– Angles
– Lengths
– Parallel lines
• Ex
–
–
–
–
–
Translation
Rotation
Scaling
Reflection
Shear
Round-off Errors
• Consider rotating a polygonal model
about y-axis
x
• Moon = Roty(5) Moon
• Moon = Roty(5) Roty(5) Moon
• Moon = Roty(n) Moon
z
Orthonormalization
• All rows of transformation matrix must:
– Have unit length
– Be orthogonal to one another
• Row1 dot Row2 = 0
– One technique to orthonormalize
• Normalize row 1 (excluding last column)
• Row1 x Row2 = Row3 (normalize)
• Row3 x Row1 = Row2 (normalize)
– Errors were shifted in matrix
Rotations
• Give me four rotation representations
and their shortcomings…
•
•
•
•
3x3 matrix
Euler Angles
Axis-angle
Quaternion
- Interpolation
- Gimbal Lock
- Compiling Rot Seqs
Representing 3 Rotational
DOFs
• 3x3 Matrix (9 DOFs)
– Rows of matrix define orthogonal axes
• Euler Angles (3 DOFs)
– Rot x + Rot y + Rot z
• Axis-angle (4 DOFs)
– Axis of rotation + Rotation amount
• Quaternion (4 DOFs)
– 4 dimensional complex numbers
Rotation Matrix
•
•
•
•
9 DOFs must reduce to 3
Rows must be unit length (-3 DOFs)
Rows must be orthogonal (-3 DOFs)
Drifting matrices is very bad
– Numerical errors results when trying to gradually
rotate matrix by adding derivatives
– Resulting matrix may scale / shear
– Gram-Schmidt algorithm will re-orthogonalize your
matrix
• Difficult to interpolate between matrices
Euler Angles
• (qx, qy, qz) = RzRyRx
– Rotate qx degrees about x-axis
– Rotate qy degrees about y-axis
– Rotate qz degrees about z-axis
• Axis order is not defined
– (y, z, x), (x, z, y), (z, y, x)…
are all legal
– Pick one
Euler Angles
• Rotations not uniquely defined
– ex: (z, x, y) = (90, 45, 45) = (45, 0, -45)
takes positive x-axis to (1, 1, 1)
– cartesian coordinates are independent of
one another, but Euler angles are not
• Gimbal Lock
– Term derived from mechanical problem
that arises in gimbal mechanism that
supports a compass or a gyro
Gimbal Lock
Gimbal Lock
• Occurs when two axes
are aligned
• Second and third
rotations have effect of
transforming earlier
rotations
– ex: Rot x, Rot y, Rot z
• If Rot y = 90 degrees, Rot
z == -Rot x
Interpolation
• Interpolation between two Euler angles
is not unique
• ex: (x, y, z) rotation
– (0, 0, 0) to (180, 0, 0) vs. (0, 0, 0) to (0,
180, 180)
– Interpolation about different axes are not
independent
Interpolation
Chapter 3
Interpolation
• First let’s talk about functions
– Read Appendix B.4
– Explicit equation: y = f(x)
• Dependent on choice of coordinate axes
• Not defined if more than one f(x) for x, sqrt(9)
– Implicit equation: f(x, y) = 0
• Quick to see if (x,y) is on curve
• Difficult to generate series of f(x) for x:0g10
– Parametric: x = f(t), y = f(t)
Equations
• Polynomial: only containing variables
raised to a power
• Linear, quadratic, cubic: polynomial
equation with highest power of 1, 2, 3
• Transcendental: equations containing
trig functions, logs, exponentials
Continuity
• Zeroth-order (C0): the value of the
function f(x0) is arbitrarily close to the
value of f(x0+e)
• First-order (C1): first derivative is
continous
• Second-order (C2): second derivative is
continuous
Piecewise Curve Segments
• One curve constructed by connecting many
smaller segments end-to-end
• Piecewise linear: a sequence of straight line
segments
• Continuity describes the joint
Specifying Curves
• Control Points
– A set of points that influence the
curve’s shape
• Knots
– Control points that lie on the curve
• Interpolating Splines
– Curves that pass through the control
points (knots)
• Approximating Splines
– Control points merely influence shape
Linear Interpolation
P(u )  (1  u )  P0  u  P1
or
P1
P(u )  ( P1  P0)  u  P0
For generic blending functions:
P(u)
P(u )  F0 (u )  P0  F1 (u)  P1
P0
Matrix forms:
 F (u )
P(u )   0 P0 P1  FBT
 F1 (u ) 
  1 1   P 0
P(u )  u 1
 U T MB



 1 0  P1
Interpolation Functions
• Hermite
• Bezier
• B-spline
– Global vs. local control
Animating with Interpolation
• Most variables are controlled with
parametric equations
– x-position, y-position, z-position
– x-, y-, z- rotation axis, rotation angle
– Size, color, texture…
• Most parametric equations are
constructed from key frames
Motion Along a Curve
• Equal increments in interpolation
parameter result in unequal jumps in
function space
Dt
Dt
f(t)
t
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
• Computes the arc length of a cubic curve
• Adaptive gaussian integration monitors errors
to subsample
• 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
Gaussian Quadrature
• Compute u s.t. length (u1, u) = s
• Solve: s – length(u1, u) = 0
• 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 (divide by 0)
Download