CS 551/651 Advanced Graphics Technical Background.

33
CS 551/651 Advanced Graphics Technical Background

Transcript of CS 551/651 Advanced Graphics Technical Background.

Page 1: CS 551/651 Advanced Graphics Technical Background.

CS 551/651Advanced Graphics

Technical Background

Page 2: 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

Page 3: CS 551/651 Advanced Graphics Technical Background.

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

Page 4: CS 551/651 Advanced Graphics Technical Background.

Affine Transformations

• A transformation that preserves– Angles– Lengths– Parallel lines

• Ex– Translation– Rotation– Scaling– Reflection– Shear

Page 5: CS 551/651 Advanced Graphics Technical Background.

Round-off Errors

• Consider rotating a polygonal model about y-axis

x

z

• Moon = Roty(5) Moon

• Moon = Roty(5) Roty(5) Moon

• Moon = Roty(n) Moon

Page 6: CS 551/651 Advanced Graphics Technical Background.

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

Page 7: CS 551/651 Advanced Graphics Technical Background.

Rotations

• Give me four rotation representations

• 3x3 matrix

• Euler Angles

• Axis-angle

• Quaternion

- Interpolation

- Gimbal Lock

- Compiling Rot Seqs

and their shortcomings…

Page 8: CS 551/651 Advanced Graphics Technical Background.

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

Page 9: CS 551/651 Advanced Graphics Technical Background.

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

Page 10: CS 551/651 Advanced Graphics Technical Background.

Euler Angles

• (x, y, z) = RzRyRx

– Rotate x degrees about x-axis– Rotate y degrees about y-axis– Rotate z degrees about z-axis

• Axis order is not defined– (y, z, x), (x, z, y), (z, y, x)…

are all legal– Pick one

Page 11: CS 551/651 Advanced Graphics Technical Background.

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

Page 12: CS 551/651 Advanced Graphics Technical Background.

Gimbal Lock

Page 13: CS 551/651 Advanced Graphics Technical Background.

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

Page 14: CS 551/651 Advanced Graphics Technical Background.

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

Page 15: CS 551/651 Advanced Graphics Technical Background.

Interpolation

Page 16: CS 551/651 Advanced Graphics Technical Background.

Chapter 3Interpolation

• 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:010

– Parametric: x = f(t), y = f(t)

Page 17: CS 551/651 Advanced Graphics Technical Background.

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

Page 18: CS 551/651 Advanced Graphics Technical Background.

Continuity

• Zeroth-order (C0): the value of the function f(x0) is arbitrarily close to the value of f(x0+)

• First-order (C1): first derivative is continous

• Second-order (C2): second derivative is continuous

Page 19: CS 551/651 Advanced Graphics Technical Background.

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

Page 20: CS 551/651 Advanced Graphics Technical Background.

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

Page 21: CS 551/651 Advanced Graphics Technical Background.

Linear Interpolationor10)1()( PuPuuP

1)(0)()( 10 PuFPuFuP

0)01()( PuPPuP

TFBPPuF

uFuP

10

)(

)()(

1

0

For generic blending functions:

Matrix forms:

P0

P(u)

P1

MBUP

PuuP T

1

0

01

111)(

Page 22: CS 551/651 Advanced Graphics Technical Background.

Interpolation Functions

• Hermite

• Bezier

• B-spline– Global vs. local control

Page 23: CS 551/651 Advanced Graphics Technical Background.

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

Page 24: CS 551/651 Advanced Graphics Technical Background.

Motion Along a Curve

• Equal increments in interpolation parameter result in unequal jumps in function space

t

f(t)t t

Page 25: CS 551/651 Advanced Graphics Technical Background.

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

Page 26: CS 551/651 Advanced Graphics Technical Background.

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))

Page 27: CS 551/651 Advanced Graphics Technical Background.

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:

Page 28: CS 551/651 Advanced Graphics Technical Background.

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?

Page 29: CS 551/651 Advanced Graphics Technical Background.

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

Page 30: CS 551/651 Advanced Graphics Technical Background.

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

Page 31: CS 551/651 Advanced Graphics Technical Background.

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

Page 32: CS 551/651 Advanced Graphics Technical Background.

Gaussian Quadrature

• Compute u s.t. length (u1, u) = s

• Solve: s – length(u1, u) = 0

• 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

Page 33: CS 551/651 Advanced Graphics Technical Background.

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)