8.2 - Parametric Equations¶
Key frame animations require an animator to specify “key” properties
of an object or a camera at “key” frames. Then the computer is required
to calculate intermediate values for the specific properties between the key frames.
Parametric equations are the ideal method for these calculations. A
parametric equation is a function of a single variable, which we typically call
t
. Think of t
as representing time. To be as generic as possible we
assume that t
varies between 0.0 and 1.0. You can always scale the results
to match any particular time interval.
Let’s start off with a simple example that calculates points along a straight
line between two points, p1
and p2
. All intermediate points
between p1
and p2
can be calculated using a fractional
combination of the two points. The equation looks like this:
p = (1-t)*p1 + t*p2; // where t varies from 0.0 to 1.0
Notice the following:
- When
t = 0.0
, the equation becomesp = p1
. - When
t = 1.0
, the equation becomesp = p2
. - When
t = 0.25
, the equation becomesp = 0.75*p1 + 0.25*p2
. The pointp
is 75% ofp1
’s value and 25% ofp2
’s value. t + (1-t)
is always equal to 1.0. This means we are always getting 100% of the two points. For any value of t, you are taking t% ofp2
and the leftover percentage ofp1
.- For a straight line in 3D space, we are calculating 3 values but only
varying a single parameter
t
:- px = (1-t)*p1x + t*p2x
- py = (1-t)*p1y + t*p2y
- pz = (1-t)*p1z + t*p2z
Animating Anything¶
You can vary any type of value using a parametric equation. For example, let’s vary the scale of a model from 3.0 to 5.0. The equation would be:
p = (1-t)*3.0 + t*5.0; // where t varies from 0.0 to 1.0
Or, let’s vary a normal vector from a vector aligned with the x axis,
<1,0,0>
, to a vector aligned with the y axis, <0,1,0>
. The
equations would be:
nx = (1-t)*1.0 + t*0.0; // where t varies from 0.0 to 1.0
ny = (1-t)*0.0 + t*1.0; // where t varies from 0.0 to 1.0
nz = (1-t)*0.0 + t*0.0; // where t varies from 0.0 to 1.0
Rotations Using Parametric Equations¶
Calculating intermediate points around a circular path that is centered about an arbitrary 3D point and about an arbitrary rotation vector is best done with a matrix transformation. Since all rotation is about the origin, you need to do the following three steps:
- Translate the center point to the global origin.
- Use a rotation transform to rotate about the axis of rotation.
- Translate the center point back to its original position.
To vary the angle of rotation use a parametric equation. For example, to vary an angle between 10 and 55 degrees, the parametric equation would be:
angle = (1-t)*10.0 + t*55.0; // where t varies from 0.0 to 1.0
WebGL Example Program¶
Study the code in path.js
below. Notice that the parametric
parameter t
is calculated as a percentage between 0.0 and 1.0
of the total number of frames in the animation. The calculation is
on line 66. Experiment with the program and the code.
Animate an object along a path between two points.
current frame 0 : 0 120
animation: start frame: end frame:
You might experiment with values for t
that are less than 0.0 or greater
than 1.0. In path.js
, remove the cascading if statement
that makes
sure the value for t
is between 0.0 and 1.0. The positions calculated along
the path are still along a straight line, but outside the initial starting and ending
locations. (You will have to click and drag the scene to rotate the view to see the
model.)
Glossary¶
- parametric equation
- Calculate an intermediate value based on a starting and ending value. Any particular intermediate value is defined by a single parameter t, which varies between 0.0 and 1.0.
Self Assessment¶
-
Q-178: The parametric parameter,
- "time"
- Correct. The answer is in quotes because the t value is normalized to a range from 0.0 to 1.0.
- distance
- Incorrect. You could think of t as a percentage of distance, but it is more related to time.
- speed
- Incorrect. Speed is the distance traveled over a set unit of time.
- acceleration
- Incorrect. Acceleration is the change in speed.
t
, is best thought of in terms of what property?
-
Q-179: Given
- (0, 0, 0)
- Correct. You always get the starting point when t === 0.0.
- (10,0,0)
- Incorrect. You get the ending point when t === 1.0.
- (0.5, 0, 0);
- Incorrect. You would get the mid-point when t === 0.5.
- (0, 0, 0.5)
- Incorrect. This location is not on the path for any value of t.
p1
at (0,0,0)
and p2
at (10,0,0)
, what is the intermediate
point between them when t=0.0
?
-
Q-180: Given
- (10,0,0)
- Correct. You always get the ending point when t === 1.0.
- (0, 0, 0)
- Incorrect. You get the starting point when t === 0.0.
- (0.5, 0, 0);
- Incorrect. You would get the mid-point when t === 0.5.
- (0, 0, 0.5)
- Incorrect. This location is not on the path for any value of t.
p1
at (0,0,0)
and p2
at (10,0,0)
, what is the intermediate
point between them when t=1.0
?
-
Q-181: Given
- (2, 0, 0)
- Correct.
- (2, 2, 2)
- Incorrect. Make sure you use the correct component value for each point.
- (0.2, 0.4, 0.6)
- Incorrect.
- (0, 0, 2)
- Incorrect. Make sure you use the correct component value for each point.
p1
at (0,0,0)
and p2
at (10,0,0)
, what is the intermediate
point between them when t=0.2
?