Download presentation
Presentation is loading. Please wait.
Published byBuck Morris Modified over 9 years ago
1
Paths, Smoothing, Least Squares Fit CS 551/651 Spring 2002
2
Following a Path How do we compute an object’s first- person view as it follows a path? –Situate a local coordinate system about the object and orient the system Positive z-axis points frontward –Frontward is first derivative, P’(s) Positive y-axis points upward –Upward is cross product of z-axis and P’’(s) Positive x-axis points left –Cross product of z- and y-axes
3
Newton-Raphson No guarantees that it will find the roots of an equation Or that it will be efficient Caught Here
4
Cross Product Right Hand Rule See: http://www.phy.syr.edu/courses/video/RightHandRule/index2.html http://www.phy.syr.edu/courses/video/RightHandRule/index2.html Orient your right hand such that your palm is at the beginning of A and your fingers point in the direction of A Twist your hand about the A-axis such that B extends perpendicularly from your palm As you curl your fingers to make a fist, your thumb will point in the direction of the cross product
5
Frenet Frame The local coordinate system If curve has no curvature, technique fails –Use Frenet Frame from before straight section starts (and interpolate rotation about z-axis if necessary) Use dot product of y-axis before and after straight section to determine interpolation amount
6
Frenet Frame Discontinuity in the curvature causes jump in local coordinate system Can be jumpy if curve is not very smooth Doesn’t reflect desirable camera effects like banking into a corner A curve that moves downward in 3-space will cause Frenet frame to orient upside-down
7
Alternative Orientation Methods Define a natural notion of ‘UP’, y-axis –The opposite direction of gravity Define a focal point, z-axis –z-axis = focal_point – cur_pos –x-axis = z-axis x UP –y-axis = z-axis x x-axis Passing close to focal point causes extreme changes How do you automatically update focal point?
8
Lookahead If cur_pos = p(s), the focal point = p(s+ s) –Note, should be arc length parameterization to prevent wandering camera What about the end of curve (where s+ s is undefined)? –Extrapolate curve in the direction of its tangent
9
Smoothing Data Frequently we use a series of points to represent paths We turn points into piecewise Bezier curve But may be overkill Alternatives
10
Smoothing Data Average a point with its neighbors –But this causes flattening of curves Fit cubic curve to subsets of points –Curve is inherently smooth –Sample curve at midpoint for new point
11
Cubic Curves P(u) = au 3 + bu 2 + cu + d For a point, P i, build curve from its four neighbors –P i-2, P i-1, P i+1, P i+2 –Evaluate the cubic at its midpoint (u = ½) –Average cubic midpoint and P i
12
Evaluating the Cubic P i-2 = P(0) = d P i-1 = P(1/4) = a 1/64 + b 1/16 + c1/4 + d P i+1 = P(3/4) = a 27/64 + b 9/16 + c¾ + d P i+2 = P(1) = a + b + c + d 4 equations and 4 unknowns… solve
13
Evaluating Cubic What about endpoints? P i+1 and P i+2 don’t exist –P’ 0 = P 3 + 3 (P 1 – P 2 ) Second in from beginning or end? –Build a quadratic (parabola) –P(u) = au 2 + bu + c –Solve for a, b, and c using P 0, P 2, P 3 –P 1 is averaged with P(1/3)
14
Overconstrained Cubics Earlier, we solved for cubic coefficients using Gaussian Elimination / Linear Programming We solved for x such that Ax = b A was square and invertable
15
Overconstrained Cubics What if we had 10 points and we wished to fit a line, quadratic, or cubic to them? Ax = b Matrix dimensions: –[10 x 4] * [4 x 1] = [10 x 1] –Cannot trivially invert A
16
Least Squares Fit Select a cubic curve (the x-vector in our example) that minimizes the standard deviation of the distances between the points and the cubic curve:
17
Least Squares Fit E is the error function: f(u) is a function of (a, b, c, d) and u –It is the parametric cubic curve We want to minimize E Wherever E is minimized:
18
Least Squares Fit Compute the partial derivative of E w.r.t. a, b, c, and d Set each partial derivative equal to 0 We now have four equations and four unknowns Solve… This method is slow and there are better least squares solution methods
19
Linear Least Squares We just talked about linear least squares –The cubic equation is nonlinear because x is raised to powers greater than 1 ax 3 + bx 2 + cx + d –But fitting a cubic to a set of data is linear curve fitting Parameters (a, b, c, d) enter into the formula as simple multipliers of terms that are added together
20
An example Fit a line to data: –The vertical deviation of the i th piece of data (x i, y i ) is: d i = y i – y = y i – (mx i + b) Where m and b are the unknown parameters –By minimizing square of deviations d 2 i = (y i – y) 2 = (y i – (mx i + b)) 2
21
An example Minimize sum of d i and set partials to 0 m= b=
22
Computer Tools Write your own function Mathematica –Fit [data, {1, x}, x] Excel –Linest (y-array, x-array, count, statistics) See http://www.orst.edu/instruct/ch490/lessons/lesson9.htm for more info http://www.orst.edu/instruct/ch490/lessons/lesson9.htm
23
Robustness of Least Squares Effective, complete, and appropriate for many problems in science/engineering Estimates of unknowns are optimal Efficient use of data Not good for extrapolation past endpoints Sensitive to presence of outliers –Model validation is useful
24
Convolution Kernels Another smoothing technique Imagine data define stepwise function Create the kernel –Centered around zero –Symmetric –Has finite support –Area under curve equals 1 Box Gaussian Tent
25
Convolution Kernels Compute new (averaged) points by convolving kernel with data Slide kernel over all points Watch for overlap at beginning and end New value for P1 is:
26
Determining a Path on Surface Consider a polygonal terrain map Assume you have the (x,y,z) coordinates of two endpoints What are the values of intermediate points on the line?
27
Path Determination Construct a plane that passes through the two points and is (roughly) perpendicular to the ground plane –How do we compute the perpendicular? –How doe we compute the plane? Intersect plane with the terrain polys –How?
28
Path Determination If the terrain is modeled as a parametric surface: f(u, v) = z Linearly interpolate between (u 1, v 1 ) and (u 2, v 2 ) and solve for f(u interp, v interp )
29
Path Determination What if ground is constructed from many triangles and we wish to only walk along the edges? –Start from the first point –And then what? Consider all coincident edges Project each edge to straight line on path. How? Dot product (remember to normalize)
30
Path Determination Edge with smallest angle is selected Keep applying until destination is reached Guaranteed to reach destination?
31
Downhill Paths To go downhill –Cross product of surface normal and ‘up’ gives you a surface tangent vector (perpendicular to down) –Cross product of surface tangent and normal vector defines downhill vector
32
Reminder Read papers and write questions for Tuesday Assignment due Thursday at 9:00 a.m. Warping and morphing are next
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.