Parametric Equations
A parametric curve describes a path by giving and separately as functions of a third variable, usually time . Instead of " as a function of ", you get "where the object is at time ". This lesson shows how to write and graph parametric equations, how to eliminate the parameter, and why game objects, animations and particle effects are naturally parametric.
and
A parametric curve is a pair of functions
The variable is the parameter. Each value of gives one point ; as increases, the point traces out the curve in a particular direction. That direction and speed are extra information a plain equation in and does not carry.
| Parametric equations | Curve |
|---|---|
| , | a line through with direction |
| , , | unit circle, counter-clockwise |
| , | ellipse |
| , | the parabola |
| , | cycloid (a point on a rolling wheel) |
Parametric equations can draw curves that fail the vertical line test, such as a full circle or a loop, which no single function can.
Eliminating the parameter
To find an ordinary equation for the curve, solve one equation for and substitute, or use an identity:
Different parametrisations can trace the same curve: , is the same unit circle, travelled twice as fast. , is the same circle clockwise.
Projectile motion
A ball launched at speed and angle under gravity (no air resistance) follows
The horizontal motion is uniform; the vertical motion is the falling-body formula. Eliminating gives a parabola, a conic section. The parametric form answers the questions a game needs directly: where is the ball at frame , when does it land, how high does it go?
import math
v, alpha, g = 20.0, math.radians(40), 9.81
vx, vy = v * math.cos(alpha), v * math.sin(alpha)
t_land = 2 * vy / g # y(t) = 0 again
t_top = vy / g
print(f"flight time {t_land:.3f} s, peak {vy**2 / (2 * g):.3f} m at t = {t_top:.3f} s, range {vx * t_land:.3f} m")
print(" t x y")
for k in range(6):
t = t_land * k / 5
print(f"{t:5.2f} {vx * t:7.2f} {vy * t - 0.5 * g * t**2:7.2f}")flight time 2.621 s, peak 8.424 m at t = 1.310 s, range 40.155 m
t x y
0.00 0.00 0.00
0.52 8.03 5.39
1.05 16.06 8.09
1.57 24.09 8.09
2.10 32.12 5.39
2.62 40.16 0.00
In software: paths for game objects
Games and animation code are full of parametric paths:
- Moving along a line. for goes from to . This is linear interpolation, the basis of lerp, and with an easing function applied to it becomes smooth UI animation.
- Orbits and patrols. A moon orbiting a planet at : , . Changing changes the speed, the sign of the direction.
- Figure-eights and Lissajous curves. , give looping patrol routes and screensaver patterns.
- Bézier curves. The curves in vector drawing programs and font outlines are parametric polynomials in (Bézier Curves).
import numpy as np
import matplotlib.pyplot as plt
t = np.linspace(0, 2 * np.pi, 500)
plt.figure(figsize=(6, 4))
plt.plot(3 * np.sin(t), 2 * np.sin(2 * t), label="patrol: x = 3 sin t, y = 2 sin 2t")
plt.plot(1.2 * np.cos(t) + 4.5, 1.2 * np.sin(t), label="orbit: circle around (4.5, 0)")
s = np.linspace(0, 4 * np.pi, 400)
plt.plot(0.5 * (s - np.sin(s)) - 3, 0.5 * (1 - np.cos(s)) - 3, label="cycloid (rolling wheel)")
for k in range(0, 500, 50): # sample positions = frames
plt.plot(3 * np.sin(t[k]), 2 * np.sin(2 * t[k]), "k.", ms=6)
plt.gca().set_aspect("equal")
plt.legend(fontsize=8, loc="upper left")
xs = 3 * np.sin(t[::50])
print("frame x positions:", [round(float(v), 2) for v in xs])frame x positions: [0.0, 1.77, 2.86, 2.85, 1.75, -0.02, -1.78, -2.86, -2.84, -1.74]
The black dots are equally spaced in , not in distance: the object moves faster where the dots are far apart. Game code that needs constant speed along a curve has to reparametrise by arc length, a topic for calculus (Parametric Curves, Calculus with Parametric Curves).
Exercises
Exercise 1: Eliminate
Eliminate the parameter from , .
Answer
, a parabola with vertex .
Solution
Exercise 2: Parametrise a segment
Write parametric equations for the segment from to , with from 0 to 1. Where is the point at ?
Answer
, ; at the point is .
Solution
Exercise 3: Identify the curve
What curve is , , and in which direction is it traced?
Answer
The circle , counter-clockwise.
Solution
Exercise 4: When does it land?
A ball leaves a 10 m high cliff with velocity , so , . When does it hit the ground and how far from the cliff? Check numerically.
Answer
, at .
Solution
import math
t = (6 + math.sqrt(36 + 4 * 4.9 * 10)) / (2 * 4.9)
print(round(t, 3), round(8 * t, 2), round(10 + 6 * t - 4.9 * t**2, 9))2.166 17.33 0.0
Test yourself
Which curve is , ?
- A line
- A circle of radius 4
- A parabola
- An ellipse with ,
What does give at ?
- Point
- Point
- The midpoint of and
- A point beyond
, traces the unit circle…
- clockwise
- counter-clockwise
- only half of it
- twice per