Other Equations and Their Shapes
Lines and parabolas are only the start. Equations with and together draw circles, ellipses and hyperbolas, and a few other simple equations give shapes you will meet constantly: the V of absolute value, the half-parabola of a square root, the S of a cube. This lesson teaches you to recognise each shape from its equation and shows where programmers use them.
Circle
A circle is the set of points at distance from a centre . The distance formula squared gives its equation:
is the circle with centre and radius 3. With the centre at the origin it is simply .
If the equation arrives expanded, complete the square in and in :
Ellipse
Stretch a circle by different amounts horizontally and vertically and you get an ellipse. Centred at the origin:
is 8 wide (from to 4) and 6 tall (from to 3). When it is a circle. Planetary orbits are ellipses, and so is a circle seen at an angle, which is why a round plate looks elliptical in a perspective drawing.
Hyperbola
Change the plus to a minus and the curve splits into two branches that open away from each other:
has vertices and approaches the lines without touching them. The curve (or ) is also a hyperbola, rotated by 45°; it is the graph of inverse variation, "double one quantity, halve the other".
import numpy as np
import matplotlib.pyplot as plt
t = np.linspace(0, 2 * np.pi, 300)
s = np.linspace(-2, 2, 200)
fig, axes = plt.subplots(1, 3, figsize=(10, 3.4))
axes[0].plot(2 + 3 * np.cos(t), -1 + 3 * np.sin(t))
axes[0].plot(2, -1, "k+"); axes[0].set_title("(x − 2)² + (y + 1)² = 9")
axes[1].plot(4 * np.cos(t), 3 * np.sin(t))
axes[1].set_title("x²/16 + y²/9 = 1")
for sign in (1, -1): # two branches: x = ±2·cosh(s)
axes[2].plot(sign * 2 * np.cosh(s), 3 * np.sinh(s), color="tab:blue")
xs = np.linspace(-6, 6, 2)
axes[2].plot(xs, 1.5 * xs, "--", color="gray"); axes[2].plot(xs, -1.5 * xs, "--", color="gray")
axes[2].set_ylim(-8, 8); axes[2].set_title("x²/4 − y²/9 = 1")
for ax in axes:
ax.axhline(0, color="black", linewidth=0.6); ax.axvline(0, color="black", linewidth=0.6)
ax.set_aspect("equal", adjustable="datalim"); ax.grid(True, alpha=0.3)
plt.tight_layout()
plt.show()
print("circle, ellipse and hyperbola (with its asymptotes)")circle, ellipse and hyperbola (with its asymptotes)
The figure draws the curves with parametric formulas (, for the ellipse), which avoids solving for and handling the of a square root. Parametric curves are covered in Pre-Calculus and in Parametric Curves.
Recognising the shape
For an equation (no term), the squared terms decide the shape:
| Squared terms | Shape | Example |
|---|---|---|
| only one of or | parabola | , |
| and , same sign, | circle | |
| and , same sign, | ellipse | |
| and , opposite signs | hyperbola |
Together these four curves are the conic sections: each is the outline you get by slicing a cone with a plane (Conic Sections). A few other basic shapes complete the catalogue:
| Equation | Shape |
|---|---|
| a V with its corner at the origin | |
| the upper half of a sideways parabola, starting at | |
| an S-shaped curve through the origin, low on the left and high on the right | |
| a hyperbola in quadrants I and III |
def classify(A, C):
"""Shape of A·x² + C·y² + D·x + E·y + F = 0 (no xy term, non-degenerate)."""
if A == 0 or C == 0:
return "parabola"
if A * C < 0:
return "hyperbola"
return "circle" if A == C else "ellipse"
examples = {"x² + y² = 25": (1, 1), "4x² + 9y² = 36": (4, 9),
"x² − 4y² = 4": (1, -4), "y = x² − 3": (1, 0), "x² + y² − 4x + 2y − 4 = 0": (1, 1)}
for eq, (A, C) in examples.items():
print(f"{eq:28} -> {classify(A, C)}")x² + y² = 25 -> circle
4x² + 9y² = 36 -> ellipse
x² − 4y² = 4 -> hyperbola
y = x² − 3 -> parabola
x² + y² − 4x + 2y − 4 = 0 -> circle
("Non-degenerate" excludes special cases such as , a single point, or , which has no points at all.)
In software
- Circle tests. "Is the enemy inside the explosion radius?" is . Games compare the squared distance with to skip the square root (Circles and Spheres).
- Ellipse tests. An oval button, an elliptical vision cone or a stretched hit area uses after shifting to the ellipse's centre.
- Hyperbolas. On-screen size is proportional to , a hyperbola, which is why a perspective camera divides by depth. GPS and sound-source location also use hyperbolas: a fixed difference of distances to two receivers puts the source on a hyperbola.
def in_ellipse(x, y, a, b, cx=0, cy=0):
return ((x - cx) / a) ** 2 + ((y - cy) / b) ** 2 <= 1
def in_circle(x, y, cx, cy, r):
return (x - cx) ** 2 + (y - cy) ** 2 <= r * r # no square root needed
print(in_ellipse(2, 1.5, 4, 3), in_ellipse(3.5, 2, 4, 3))
print(in_circle(4, 1, 2, -1, 3), in_circle(5, 1, 2, -1, 3))True False
True False
gives , inside the ellipse; gives about 1.21, outside. For the circle, is at squared distance , while is at .
Exercises
Exercise 1: Read a circle
Give the centre and radius of . Does the circle pass through the origin?
Answer
Centre , radius 5; yes, it passes through the origin.
Solution
Exercise 2: Complete the squares
Find the centre and radius of .
Answer
Centre , radius 2.
Solution
from sympy import symbols, expand
x, y = symbols("x y")
print(expand((x - 1)**2 + (y + 3)**2 - 4))x**2 - 2*x + y**2 + 6*y + 6
Exercise 3: An ellipse
Identify and give its intercepts.
Answer
An ellipse, , with intercepts and .
Solution
Both squared terms are positive with different coefficients, so it is an ellipse. Divide by 36:
Exercise 4: A hyperbola
Identify . Give its vertices and asymptotes.
Answer
A hyperbola, , with vertices and asymptotes .
Solution
Exercise 5: Explosion radius
An explosion at has radius 5. Which of the enemies at , and are hit? Answer by comparing squared distances in code.
Answer
and are hit; is not.
Solution
cx, cy, r = 10, 6, 5
for ex, ey in [(13, 10), (14, 9), (6, 2)]:
d2 = (ex - cx) ** 2 + (ey - cy) ** 2
print((ex, ey), d2, "hit" if d2 <= r * r else "miss")(13, 10) 25 hit
(14, 9) 25 hit
(6, 2) 32 miss
Test yourself
What shape is ?
- Ellipse
- Circle with radius 2
- Hyperbola
- Parabola
Which equation describes a hyperbola?
Why do games test instead of comparing the distance with ?
- It is more accurate for large circles
- It avoids computing a square root and gives the same answer
- Distances can be negative
- It works only for ellipses