Graphing Quadratic Equations
To sketch a parabola you do not need dozens of points. Five well-chosen features, the direction of opening, the vertex, the axis of symmetry, the -intercept and the -intercepts, pin the curve down. This lesson turns them into a step-by-step method and then uses it to design the jump of a platformer character.
Five steps
For :
- Direction: opens up, opens down.
- Vertex: , . The axis of symmetry is the line .
- -intercept: .
- Mirror point: the -intercept reflected across the axis, .
- -intercepts: solve (by factoring or with the quadratic formula). There may be two, one or none.
Plot these points and draw a smooth U through them.
A worked example
Graph .
The -intercepts are symmetric about the axis too: −1 and 5 are both 3 units from . That is a quick check on your arithmetic.
import numpy as np
import matplotlib.pyplot as plt
a, b, c = 1, -4, -5
h = -b / (2 * a)
k = a * h**2 + b * h + c
roots = np.roots([a, b, c])
x = np.linspace(-2, 6, 200)
plt.figure(figsize=(6, 4))
plt.plot(x, a * x**2 + b * x + c, label="y = x² − 4x − 5")
plt.axvline(h, linestyle="--", color="gray", label=f"axis x = {h:g}")
plt.plot([h], [k], "o", color="tab:red", label=f"vertex ({h:g}, {k:g})")
plt.plot([0, 2 * h], [c, c], "s", color="tab:green", label="y-intercept and mirror")
plt.plot(roots, [0, 0], "^", color="tab:purple", label="x-intercepts")
plt.axhline(0, color="black", linewidth=0.8)
plt.grid(True, alpha=0.3); plt.legend(fontsize=8)
plt.show()
print("vertex:", (h, k), " roots:", sorted(float(r) for r in roots))vertex: (2.0, -9.0) roots: [-1.0, 5.0]
Range and extreme values
Because the vertex is the turning point, it gives the smallest or largest -value:
| Vertex is | Range of | |
|---|---|---|
| minimum | ||
| maximum |
For the range is . On a limited interval of , the extreme values occur either at the vertex (if it is inside the interval) or at the interval's ends. That is how you answer "what is the highest point of this arc?" or "what is the least cost?" without calculus.
In software: a platformer jump
Under constant gravity , a character who jumps with upward speed has height
a downward parabola in . Its vertex is at (the apex) with height . Game designers usually think the other way round: "the jump should be 3 tiles high and reach the top in 0.4 s". Setting the vertex to gives two equations, and , whose solution is
With tiles and s: and , so .
H, T = 3.0, 0.4 # design: 3 tiles high, apex after 0.4 s
g = 2 * H / T**2
v0 = 2 * H / T
print(f"gravity {g:g} tiles/s², jump speed {v0:g} tiles/s")
def height(t):
return v0 * t - 0.5 * g * t * t
for t in [0.0, 0.2, 0.4, 0.6, 0.8]:
print(f"t = {t:.1f} s y = {height(t):.2f}")
speed_x = 5.0 # tiles per second while running
print("jump length:", speed_x * 2 * T, "tiles")
# height as a function of horizontal distance: substitute t = x / speed_x
for x in [0, 1, 2, 3, 4]:
print(f"x = {x} y = {height(x / speed_x):.2f}")gravity 37.5 tiles/s², jump speed 15 tiles/s
t = 0.0 s y = 0.00
t = 0.2 s y = 2.25
t = 0.4 s y = 3.00
t = 0.6 s y = 2.25
t = 0.8 s y = 0.00
jump length: 4.0 tiles
x = 0 y = 0.00
x = 1 y = 2.25
x = 2 y = 3.00
x = 3 y = 2.25
x = 4 y = 0.00
The table shows the symmetry: the character is at 2.25 tiles both 0.2 s before and 0.2 s after the apex, and lands at s. Running at 5 tiles/s, the arc over the ground is , a parabola in with its vertex at and landing point . Level designers use exactly this curve to check that gaps can be jumped and ceilings are high enough. Many games then use a larger on the way down for a snappier fall, which joins two different parabolas at the apex. Real engines step the motion frame by frame; see Physics Integration in Game Loops and Integrators.
Exercises
Exercise 1: Sketch a downward parabola
Find the direction, vertex, -intercept and -intercepts of .
Answer
Opens down; vertex ; -intercept ; -intercepts and .
Solution
Check: −2 and 4 are both 3 units from the axis .
Exercise 2: No x-intercepts
Graph . Why does it have no -intercepts?
Answer
Vertex , -intercept , mirror . It opens upward and its lowest point is at , so it never reaches the -axis.
Solution
Exercise 3: Highest and lowest on an interval
For with , find the smallest and the largest value of .
Answer
Smallest 1 (at ), largest 10 (at ).
Solution
The vertex is inside the interval, so the minimum is . The maximum is at one of the ends: , . So the maximum is 10.
ys = {x: (x - 3)**2 + 1 for x in [0, 3, 4]}
print(ys, min(ys.values()), max(ys.values())){0: 10, 3: 1, 4: 2} 1 10
Exercise 4: Design a short hop
A character's short hop should be 2 tiles high and reach its apex after 0.25 s. Compute and , and check that the height at s is 2.
Answer
, ; .
Solution
H, T = 2, 0.25
g, v0 = 2 * H / T**2, 2 * H / T
print(g, v0, v0 * T - 0.5 * g * T**2)64.0 16.0 2.0
Exercise 5: Clear the block?
With the arc from the lesson ( in tiles from the take-off point), can the character clear a block 2 tiles high that spans from to ?
Answer
Yes: over the block the arc is never lower than 2.25 tiles.
Solution
The arc opens downward with its vertex at , inside the block's span, so its lowest points over are at the ends:
Test yourself
The -intercept of a parabola is and its axis of symmetry is . Which other point must be on the curve?
What is the range of ?
- all real numbers
A jump should reach height at time . Which gravity value does that require?