Curves with a secret point
A solar cooker is a shiny dish that gathers sunlight onto a pot. Families in sunny regions from India to Bolivia use them to cook without firewood. The dish is not just any bowl: its cross-section is a parabola, and every ray of sunlight that enters parallel to its axis is reflected through a single point, the focus. Satellite dishes and radio telescopes work the same way, in reverse for car headlights.
In some hospitals, kidney stones are shattered without surgery by a lithotripter: a shock wave is produced at one focus of a reflector shaped like part of an ellipsoid, and every reflected wave arrives together at the other focus — where the stone has been placed. And when Johannes Kepler studied the orbit of Mars, he found it was an ellipse with the Sun at one focus. In 2017 astronomers tracked the object ʻOumuamua passing the Sun on a hyperbola: it came from interstellar space and is leaving for good.
Parabolas, ellipses and hyperbolas are the conic sections: the curves you get by slicing a cone. In this lesson we meet three descriptions of them — slices of a cone, sets of points defined by distances, and second-degree equations — and prove that they agree.
Slicing a cone
Take a double cone: two ice-cream cones joined at their tips, extending forever. Slice it with a flat plane.
- A plane perpendicular to the axis gives a circle.
- Tilt the plane a little: the slice is a closed oval, an ellipse.
- Tilt it until it is parallel to a line on the cone (a generator): the curve no longer closes up. It is a parabola.
- Tilt it further, so that it cuts both halves of the cone: you get the two branches of a hyperbola.
- A plane through the tip gives a point, a single line or a pair of crossing lines: the degenerate conics.
Slices are hard to compute with, so the ancient Greek geometers also described the curves by distances. You can draw an ellipse with two pins and a loop of string: put the pins at two points, keep the string taut with a pencil, and move round. The total length from the pencil to the two pins never changes. Gardeners lay out oval flower beds this way.
Definitions
Definition— ellipse
Given two points , (the foci) and a length greater than the distance , the ellipse is the set of points with
Definition— parabola
Given a point (the focus) and a line (the directrix) not through , the parabola is the set of points equidistant from and from .
Definition— hyperbola
Given two foci , and a length with , the hyperbola is the set of points with
Definition— eccentricity
For a point , a line not through , and a number , the set of points with is an ellipse if , a parabola if and a hyperbola if (we prove this below). The number is the eccentricity. A circle is the limiting case ; it has no directrix.
Placing the foci symmetrically on the -axis gives the standard equations. In each row, , , are positive (for the parabola, ):
| Curve | Foci | Equation | Relation | Eccentricity |
|---|---|---|---|---|
| Ellipse | ||||
| Hyperbola | ||||
| Parabola | ; directrix | — |
For the ellipse, is the semi-major axis and the semi-minor axis. The hyperbola has asymptotes : its branches get closer and closer to these lines without meeting them. The ellipse with (so ) is the circle .
Worked examples
Example— The equation of a parabola from its focus and directrix
Take the focus and the directrix . A point is at distance from and from the line. Setting them equal and squaring: , so , or . In general, focus and directrix give .
Example— Finding the foci of an ellipse
. Divide by : , so , and . The foci are , the eccentricity is , and every point of the ellipse has distances to the foci adding up to . Check at the top point : both distances are .
Example— Completing the square
What is ? Group and complete the squares (see quadratics):
so the equation is , that is,
an ellipse with centre , , and foci . If the constant had been instead of , we would have reached , a single point; with a larger constant, no points at all.
Example— A hyperbola in disguise
The graph of , that is , is a hyperbola whose asymptotes are the coordinate axes. Rotating it by (substitute , ) turns into , which is in standard form with and . The term was hiding the standard form.
Example— Non-examples
- factorises as : a pair of crossing lines, not a hyperbola.
- is a single point, and has no real points at all.
- A parabola is not half of a hyperbola and has no asymptotes: on the slope grows without bound, so no straight line stays close to it (the gap tends to infinity).
Why the descriptions agree
Theorem— Theorem (the parabola)
A point is equidistant from the focus and the directrix if and only if .
Proof
Both distances, and , are non-negative, so they are equal exactly when their squares are: , which simplifies to .
∎
Theorem— Theorem (the ellipse)
Let and . A point satisfies if and only if , where and . Moreover, on the ellipse
Proof
Write and .
Equation distances. On the ellipse, . Substituting,
Since on the ellipse and , the number is positive, so . Replacing by gives , and .
Distances equation. Suppose . Subtracting the squares, . Since , we get . Together with this gives . Squaring, , which rearranges to . Dividing by gives .
∎
The same algebra, with , shows that is the hyperbola : on its right branch and .
Theorem— Corollary (focus and directrix of an ellipse)
If , put . Every point of the ellipse satisfies .
Proof
, and is the distance from to the vertical line , because .
∎
Theorem— Theorem (eccentricity decides the type)
Let be the origin, let be the line with , and let . The set of points with is an ellipse if , a parabola if , and a hyperbola if .
Proof
Squaring gives
If , the term vanishes and : a parabola (opening to the right). If , complete the square in , with : the equation becomes with . If , both squares have positive coefficients and : an ellipse. If , the coefficients have opposite signs and ; multiplying by gives the standard form of a hyperbola.
∎
Theorem— Theorem (Dandelin spheres: slices of a cone are ellipses)
If a plane cuts every generator of one half of a cone (and misses the tip), the curve of intersection is an ellipse.
Proof
Inscribe two spheres in the cone, one on each side of the plane, each touching the cone along a circle ( and ) and touching the plane at a single point ( and ). Let be a point of the curve. The generator through meets at and at . Two tangent segments drawn from a point to a sphere have equal length, so (both tangent to the first sphere) and . Hence
and — the distance between the two circles measured along a generator — is the same for every generator. So the sum of distances to and is constant: the curve is an ellipse, and the points where the spheres touch the plane are its foci.
∎
Germinal Pierre Dandelin found this argument in 1822. Similar arguments (with one sphere, or with spheres in both halves of the cone) handle the parabola and the hyperbola.
The reflective properties
Light reflects from a curved mirror as it would from the tangent line at the point where it hits: the reflected ray is the mirror image, in the tangent line, of the ray that would have continued straight on.
Theorem— Reflective property of the parabola
A ray travelling parallel to the axis of a parabola is reflected through the focus.
Proof
Let the ray come straight down and hit the parabola at . Let be the foot of the perpendicular from to the directrix, so the ray, continued straight on, would travel from towards . By definition . Let be the perpendicular bisector of ; it passes through , because is equidistant from and .
We claim is the tangent at . Take any other point of . Then (as is on the perpendicular bisector), and is longer than the distance from to the directrix, because is not perpendicular to the directrix (only is). So is greater than the distance from to the directrix, and is not on the parabola. Thus meets the parabola only at and is not parallel to the axis (it is perpendicular to , which is not vertical unless is the vertex, where is the horizontal tangent): it is the tangent line.
Reflection in fixes and swaps and (that is what "perpendicular bisector of " means). So the mirror image of the ray from towards is the ray from towards : the reflected ray passes through the focus.
∎
Theorem— Reflective property of the ellipse
A ray from one focus of an ellipse is reflected through the other focus.
Proof
Let the ray from hit the ellipse at , and let be the tangent at . Because the ellipse is an oval curve (convex), every point of lies outside it, so . Thus is the point of with the smallest total distance to and .
Now use Heron's trick: reflect in to get . For every on , , so , which is smallest when lies on the straight segment . So is on that segment, and the angles that and make with are vertically opposite, hence equal. By the symmetry of the reflection, the angle between and equals the angle between and . So and make equal angles with the tangent — which is exactly the law of reflection.
∎
Note
The hyperbola has a matching property: a ray aimed at one focus is reflected, from the outside of the near branch, towards the other focus. Large telescopes of the Cassegrain design combine a parabolic main mirror with a hyperbolic secondary mirror for this reason.
Second-degree equations
Every conic in the plane has an equation of the form
with , , not all zero. Conversely, which sets does such an equation describe?
Theorem— Classification of conics
The set of real solutions of is one of: an ellipse (possibly a circle), a parabola, a hyperbola, or a degenerate case — a single point, one line, two parallel lines, two crossing lines, or the empty set. When the curve is non-degenerate, it is
- an ellipse if ,
- a parabola if ,
- a hyperbola if .
Proof sketch. (1) Rotating the axes through an angle with (or if ) removes the term; a computation shows that does not change under rotation. (2) Without the term the discriminant is , and completing the square in and (or in just one of them, if or is zero) gives a standard form or one of the degenerate cases. The heart of the matter is the next pair of facts, which do not need any rotation.
Theorem— Lemma (definite and indefinite)
- If and , then for every .
- If , then takes both positive and negative values.
Proof
- Complete the square: . Both terms are non-negative, and they are both zero only if and then .
- If , the value at is , and the value at is , which has the opposite sign. If , then , and on the line the value takes every real number.
∎
So when the quadratic part grows in every direction, and the curve is bounded: an ellipse, a point or nothing. When the quadratic part is zero along two directions — the asymptotes of a hyperbola, or the two lines of a degenerate case. The borderline case gives a parabola (or, degenerately, two parallel lines, one line or nothing). For the eccentricity family above, , , , so : negative for , zero for , positive for , just as it should be.
Conics in Lean
Mathlib has no special theory of conic sections, so everything here is done in coordinates, with real numbers. First the parabola as a locus — the distance to the focus (0, p) equals the distance |y + p| to the directrix:
/-- **The parabola as a locus.** A point `(x, y)` is as far from the focus `(0, p)` as from
the directrix, the line `y = −p`, exactly when `x² = 4py`. The distance to the focus is
`√(x² + (y − p)²)` and the distance to the line is `|y + p|`. Squaring both (they are
non-negative), `x² + (y − p)² = (y + p)²`, which simplifies to `x² = 4py`. -/
theorem parabola_focus_directrix (p x y : ℝ) :
√(x ^ 2 + (y - p) ^ 2) = |y + p| ↔ x ^ 2 = 4 * p * y := by
rw [← Real.sqrt_sq_eq_abs, Real.sqrt_inj (by positivity) (by positivity)]
constructor <;> intro h <;> nlinarith [h]Next the ellipse: the focal radius formula, and then both directions of "equation if and only if the distances add up to ", following the lesson's proof:
/-- **The focal radius of an ellipse.** Let `0 ≤ c < a` and `b² = a² − c²`. On the ellipse
`x²/a² + y²/b² = 1`, the distance from `(x, y)` to the focus `(c, 0)` is `a − (c/a) x`.
Proof: substitute `y² = b² (1 − x²/a²)` into `(x − c)² + y²` and simplify to `(a − cx/a)²`;
since `|x| ≤ a` and `c < a`, the number `a − cx/a` is positive, so it is the square root. -/
theorem ellipse_focal_radius (a b c x y : ℝ) (ha : 0 < a) (hc : 0 ≤ c) (hca : c < a)
(hb : b ^ 2 = a ^ 2 - c ^ 2) (h : x ^ 2 / a ^ 2 + y ^ 2 / b ^ 2 = 1) :
√((x - c) ^ 2 + y ^ 2) = a - c / a * x := by
have hb2 : 0 < b ^ 2 := by nlinarith
have hb0 : b ≠ 0 := by rintro rfl; simp at hb2
have hy : y ^ 2 = b ^ 2 - b ^ 2 * x ^ 2 / a ^ 2 := by
have h1 : y ^ 2 / b ^ 2 = 1 - x ^ 2 / a ^ 2 := by linarith
have h2 : y ^ 2 = b ^ 2 * (1 - x ^ 2 / a ^ 2) := by
rw [← h1]; field_simp
rw [h2]; ring
have hx : x ^ 2 ≤ a ^ 2 := by
have : y ^ 2 / b ^ 2 ≥ 0 := by positivity
have h2 : x ^ 2 / a ^ 2 ≤ 1 := by linarith
rwa [div_le_one (by positivity)] at h2
have hxa : |x| ≤ a := abs_le_of_sq_le_sq hx ha.le
have hpos : 0 ≤ a - c / a * x := by
have h1 : c / a * x ≤ c / a * a := by
apply mul_le_mul_of_nonneg_left (le_trans (le_abs_self x) hxa) (by positivity)
have h2 : c / a * a = c := by field_simp
linarith
rw [Real.sqrt_eq_iff_mul_self_eq (by positivity) hpos]
rw [hy, hb]
field_simp
ring/-- **The ellipse: equation versus foci.** With `0 ≤ c < a` and `b² = a² − c²`, a point lies on
`x²/a² + y²/b² = 1` exactly when the sum of its distances to the foci `(c, 0)` and `(−c, 0)` is
`2a`. Forwards: add the two focal radii `a − cx/a` and `a + cx/a`. Backwards: if `d₁ + d₂ = 2a`,
then `d₂² − d₁² = 4cx` gives `d₂ − d₁ = 2cx/a`, so `d₁ = a − cx/a`; squaring this and
simplifying gives the equation. -/
theorem ellipse_iff_focal_sum (a b c x y : ℝ) (ha : 0 < a) (hc : 0 ≤ c) (hca : c < a)
(hb : b ^ 2 = a ^ 2 - c ^ 2) :
x ^ 2 / a ^ 2 + y ^ 2 / b ^ 2 = 1 ↔
√((x - c) ^ 2 + y ^ 2) + √((x + c) ^ 2 + y ^ 2) = 2 * a := by
constructor
· intro h
have h1 := ellipse_focal_radius a b c x y ha hc hca hb h
-- The other focus: reflect the picture in the y-axis (`x ↦ −x`).
have h2 := ellipse_focal_radius a b c (-x) y ha hc hca hb (by rw [neg_sq]; exact h)
rw [show (-x - c) ^ 2 = (x + c) ^ 2 by ring] at h2
rw [h1, h2]
ring
· intro h
set d₁ := √((x - c) ^ 2 + y ^ 2) with hd₁
set d₂ := √((x + c) ^ 2 + y ^ 2) with hd₂
have hsq₁ : d₁ ^ 2 = (x - c) ^ 2 + y ^ 2 := Real.sq_sqrt (by positivity)
have hsq₂ : d₂ ^ 2 = (x + c) ^ 2 + y ^ 2 := Real.sq_sqrt (by positivity)
-- `d₂² − d₁² = 4cx` and `d₁ + d₂ = 2a` give `d₂ − d₁ = 2cx/a`.
have hdiff : (d₂ - d₁) * (2 * a) = 4 * c * x := by
rw [← h]; nlinarith [hsq₁, hsq₂]
have hd₁' : d₁ = a - c * x / a := by
field_simp
nlinarith [hdiff, h]
have key : (a - c * x / a) ^ 2 = (x - c) ^ 2 + y ^ 2 := by rw [← hd₁', hsq₁]
have hb2 : b ^ 2 ≠ 0 := by nlinarith
rw [hb] at hb2 ⊢
field_simp at key ⊢
nlinarith [key]Parametrisations: traces the ellipse, and a branch of the hyperbola, using the identity from Mathlib:
/-- The point `(a cos t, b sin t)` lies on the ellipse `x²/a² + y²/b² = 1` (for `a, b ≠ 0`):
the equation becomes `cos² t + sin² t = 1`. As `t` runs from `0` to `2π` the point goes once
round the ellipse; for `a = b` it is a circle. -/
theorem ellipse_param (a b t : ℝ) (ha : a ≠ 0) (hb : b ≠ 0) :
(a * cos t) ^ 2 / a ^ 2 + (b * sin t) ^ 2 / b ^ 2 = 1 := by
rw [mul_pow, mul_pow, mul_div_cancel_left₀ _ (pow_ne_zero 2 ha),
mul_div_cancel_left₀ _ (pow_ne_zero 2 hb), cos_sq_add_sin_sq]/-- `cosh² t − sinh² t = 1`, the hyperbolic analogue of `cos² t + sin² t = 1`. Applies
Mathlib's `Real.cosh_sq_sub_sinh_sq`. (Here `cosh t = (eᵗ + e⁻ᵗ)/2`, `sinh t = (eᵗ − e⁻ᵗ)/2`.) -/
theorem cosh_sq_sub_sinh_sq (t : ℝ) : cosh t ^ 2 - sinh t ^ 2 = 1 := Real.cosh_sq_sub_sinh_sq t/-- The point `(a cosh t, b sinh t)` lies on the hyperbola `x²/a² − y²/b² = 1`; as `t` runs
over all real numbers it traces the right-hand branch (`cosh t ≥ 1`). This is why `cosh` and
`sinh` are called *hyperbolic* functions. -/
theorem hyperbola_param (a b t : ℝ) (ha : a ≠ 0) (hb : b ≠ 0) :
(a * cosh t) ^ 2 / a ^ 2 - (b * sinh t) ^ 2 / b ^ 2 = 1 := by
rw [mul_pow, mul_pow, mul_div_cancel_left₀ _ (pow_ne_zero 2 ha),
mul_div_cancel_left₀ _ (pow_ne_zero 2 hb), cosh_sq_sub_sinh_sq]The reflective property of the parabola, in vector form. We define the dot product and the law of reflection, and prove that the reflected vertical ray points exactly at the focus. This is a different proof from the geometric one above — a calculation rather than an argument with the perpendicular bisector:
/-- The dot product of two vectors in the plane, `(u₁, u₂) · (v₁, v₂) = u₁ v₁ + u₂ v₂`. -/
def dotp (u v : ℝ × ℝ) : ℝ := u.1 * v.1 + u.2 * v.2/-- The **law of reflection** for a direction `v` hitting a mirror whose normal vector is `n`:
the component of `v` along `n` is reversed and the rest is kept,
`reflect v n = v − (2 (v · n)/(n · n)) n`. -/
noncomputable def reflect (v n : ℝ × ℝ) : ℝ × ℝ := v - (2 * dotp v n / dotp n n) • n/-- **The reflective property of the parabola** `y = x²/(4p)`. At the point
`P = (x₀, x₀²/(4p))` the tangent has direction `(2p, x₀)`, so `n = (x₀, −2p)` is a normal
vector. A ray coming straight down, with direction `(0, −1)`, is reflected to the direction
`reflect (0, −1) n`. The theorem says that this reflected direction, multiplied by the positive
number `x₀²/(4p) + p` (the distance `PF`), is exactly the vector from `P` to the focus
`F = (0, p)`: every vertical ray is reflected through the focus. -/
theorem parabola_reflection (p x₀ : ℝ) (hp : p ≠ 0) :
(x₀ ^ 2 / (4 * p) + p) • reflect (0, -1) (x₀, -2 * p) = (0, p) - (x₀, x₀ ^ 2 / (4 * p)) := by
have hN : x₀ ^ 2 + 4 * p ^ 2 ≠ 0 := by positivity
have hN' : x₀ * x₀ + -(2 * p) * -(2 * p) ≠ 0 := by nlinarith [sq_nonneg x₀, sq_pos_of_ne_zero hp]
simp only [reflect, dotp, Prod.smul_mk, Prod.mk_sub_mk, smul_eq_mul, Prod.ext_iff]
constructor
· field_simp
ring
· field_simp
ringFinally, second-degree equations: completing the square for a circle, and the two halves of the lemma behind the classification:
/-- **Completing the square for a circle.**
`x² + y² + Dx + Ey + F = (x + D/2)² + (y + E/2)² − r²` with `r² = (D² + E²)/4 − F`. So the
equation `x² + y² + Dx + Ey + F = 0` describes a circle with centre `(−D/2, −E/2)` if `r² > 0`,
the single point `(−D/2, −E/2)` if `r² = 0`, and no points at all if `r² < 0`. -/
theorem circle_complete_square (D E F x y : ℝ) :
x ^ 2 + y ^ 2 + D * x + E * y + F =
(x + D / 2) ^ 2 + (y + E / 2) ^ 2 - ((D ^ 2 + E ^ 2) / 4 - F) := by
ring/-- **Ellipse type.** If `A > 0` and `B² − 4AC < 0`, then `Ax² + Bxy + Cy² > 0` at every point
other than the origin. Completing the square,
`4A (Ax² + Bxy + Cy²) = (2Ax + By)² + (4AC − B²) y²`, a sum of two non-negative terms that are
both zero only when `y = 0` and then `x = 0`. So the level curves `Ax² + Bxy + Cy² = k` are
bounded: ellipses, a single point, or nothing. -/
theorem definite_of_discriminant_neg (A B C x y : ℝ) (hA : 0 < A) (hdisc : B ^ 2 - 4 * A * C < 0)
(hxy : (x, y) ≠ (0, 0)) : 0 < A * x ^ 2 + B * x * y + C * y ^ 2 := by
have key : 4 * A * (A * x ^ 2 + B * x * y + C * y ^ 2) =
(2 * A * x + B * y) ^ 2 + (4 * A * C - B ^ 2) * y ^ 2 := by ring
by_cases hy : y = 0
· have hx : x ≠ 0 := by
intro hx; exact hxy (by rw [hx, hy])
subst hy
have : 0 < x ^ 2 := by positivity
nlinarith
· have hy2 : 0 < y ^ 2 := by positivity
have : 0 < (4 * A * C - B ^ 2) * y ^ 2 := mul_pos (by linarith) hy2
nlinarith [sq_nonneg (2 * A * x + B * y)]/-- **Hyperbola type.** If `B² − 4AC > 0`, then `Ax² + Bxy + Cy²` takes both positive and
negative values. If `A ≠ 0`, compare the points `(1, 0)` (value `A`) and `(−B, 2A)` (value
`A (4AC − B²)`, of the opposite sign). If `A = 0`, then `B ≠ 0`, and along the line `y = 1` the
value `Bx + C` takes every real value. So the level curves are unbounded, like hyperbolas. -/
theorem indefinite_of_discriminant_pos (A B C : ℝ) (hdisc : 0 < B ^ 2 - 4 * A * C) :
(∃ x y : ℝ, 0 < A * x ^ 2 + B * x * y + C * y ^ 2) ∧
(∃ x y : ℝ, A * x ^ 2 + B * x * y + C * y ^ 2 < 0) := by
by_cases hA : A = 0
· subst hA
have hB : B ≠ 0 := by
intro hB; subst hB; norm_num at hdisc
refine ⟨⟨(1 - C) / B, 1, ?_⟩, ⟨(-1 - C) / B, 1, ?_⟩⟩
· have h1 : B * ((1 - C) / B) = 1 - C := by field_simp
simp only [zero_mul, zero_add, mul_one, one_pow]
rw [h1]; linarith
· have h1 : B * ((-1 - C) / B) = -1 - C := by field_simp
simp only [zero_mul, zero_add, mul_one, one_pow]
rw [h1]; linarith
· have hval : A * (-B) ^ 2 + B * (-B) * (2 * A) + C * (2 * A) ^ 2 =
A * (4 * A * C - B ^ 2) := by ring
rcases lt_or_gt_of_ne hA with hneg | hpos
· refine ⟨⟨-B, 2 * A, ?_⟩, ⟨1, 0, by nlinarith⟩⟩
rw [hval]; nlinarith
· refine ⟨⟨1, 0, by nlinarith⟩, ⟨-B, 2 * A, ?_⟩⟩
rw [hval]; nlinarithWhat is not formalised: the Dandelin-sphere proof (three-dimensional geometry of spheres and cones), the reflective property of the ellipse, and the full classification theorem with rotation of axes.
Tracing rays and sorting equations
"""Ray tracing in a parabolic dish and an elliptical room.
Parabola y = x^2 / (4p): rays come straight down, hit the curve, and are
reflected by the law of reflection (reverse the component along the normal).
We find where each reflected ray crosses the axis x = 0; the theorem says it
is always the focus (0, p). Ellipse x^2/a^2 + y^2/b^2 = 1: rays leave one
focus in many directions; after one reflection we measure how far each ray
passes from the other focus, and check that the distances to the foci add up
to 2a at every point hit. Floating-point evidence for finitely many rays.
"""
import math
def reflect(v, n):
"""Reflect the direction v in a mirror with normal vector n."""
k = 2 * (v[0] * n[0] + v[1] * n[1]) / (n[0] ** 2 + n[1] ** 2)
return (v[0] - k * n[0], v[1] - k * n[1])
def parabola_axis_crossing(p, x0):
"""Where the vertical ray at x = x0 crosses x = 0 after reflection."""
point = (x0, x0 * x0 / (4 * p))
normal = (x0, -2 * p) # perpendicular to the tangent direction (2p, x0)
d = reflect((0.0, -1.0), normal)
t = -point[0] / d[0] # requires x0 != 0
return point[1] + t * d[1]
def ellipse_hit(a, b, start, direction):
"""First point where the ray start + t*direction (t > 0) meets the ellipse."""
(x, y), (u, v) = start, direction
qa = (u / a) ** 2 + (v / b) ** 2
qb = 2 * (x * u / a ** 2 + y * v / b ** 2)
qc = (x / a) ** 2 + (y / b) ** 2 - 1
t = (-qb + math.sqrt(qb * qb - 4 * qa * qc)) / (2 * qa)
return (x + t * u, y + t * v)
def distance_to_line(point, start, direction):
"""Distance from a point to the line through start with this direction."""
dx, dy = point[0] - start[0], point[1] - start[1]
return abs(dx * direction[1] - dy * direction[0]) / math.hypot(*direction)
def main():
p = 1.0
print(f"Parabola y = x^2/4, focus (0, {p:g}): reflected vertical rays cross")
worst = 0.0
for x0 in (-4, -3, -2, -1, 0.5, 1, 2, 3, 4):
y = parabola_axis_crossing(p, x0)
worst = max(worst, abs(y - p))
print(f" ray at x = {x0:4g} crosses the axis at y = {y:.15f}")
print(f" largest miss: {worst:.1e}")
a, b = 5.0, 3.0
c = math.sqrt(a * a - b * b)
f1, f2 = (-c, 0.0), (c, 0.0)
miss = sum_err = 0.0
for k in range(12):
angle = 2 * math.pi * (k + 0.5) / 12
hit = ellipse_hit(a, b, f1, (math.cos(angle), math.sin(angle)))
normal = (hit[0] / a ** 2, hit[1] / b ** 2)
out = reflect((hit[0] - f1[0], hit[1] - f1[1]), normal)
miss = max(miss, distance_to_line(f2, hit, out))
sum_err = max(sum_err, abs(math.dist(hit, f1) + math.dist(hit, f2) - 2 * a))
print("Ellipse x^2/25 + y^2/9 = 1, foci (-4, 0) and (4, 0), 12 rays from")
print(f"(-4, 0): largest distance of a reflected ray from (4, 0): {miss:.1e}")
print(f" largest error in PF1 + PF2 = 2a = 10 at the points hit: "
f"{sum_err:.1e}")
print()
print("Epistemic status: numerical evidence. Each ray is traced in floating")
print("point, so 'through the focus' means within about 1e-15; only 21 rays")
print("were traced. The reflective properties are theorems proved in the")
print("lesson (and, for the parabola, checked in Lean).")
if __name__ == "__main__":
main()Every reflected ray passes through the focus, to within rounding error. That is numerical evidence for rays; the theorems cover them all.
Next, a classifier for second-degree equations. It uses the discriminant together with a determinant that detects the degenerate cases, all in exact integer arithmetic:
"""Classify second-degree equations Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0.
Uses three integer invariants: the discriminant B^2 - 4AC of the quadratic
part, the determinant of the 3 x 3 symmetric matrix of the equation (zero
exactly for degenerate cases such as pairs of lines), and, for degenerate
parabolic cases, a 2 x 2 invariant that separates parallel lines, a double
line and the empty set. Everything is exact integer arithmetic. We classify
some famous examples and then every equation with coefficients from -2 to 2.
"""
import itertools
from collections import Counter
def det3(m):
"""Determinant of a 3 x 3 matrix given as a list of rows."""
(a, b, c), (d, e, f), (g, h, i) = m
return a * (e * i - f * h) - b * (d * i - f * g) + c * (d * h - e * g)
def classify(A, B, C, D, E, F):
"""Name the set of real solutions of Ax^2+Bxy+Cy^2+Dx+Ey+F = 0.
Works with twice the symmetric matrix, so every entry is an integer.
"""
if A == B == C == 0:
raise ValueError("not a second-degree equation")
disc = B * B - 4 * A * C
delta = det3([[2 * A, B, D], [B, 2 * C, E], [D, E, 2 * F]])
if delta != 0:
if disc < 0:
if (A + C) * delta > 0:
return "empty"
return "circle" if A == C and B == 0 else "ellipse"
return "parabola" if disc == 0 else "hyperbola"
if disc < 0:
return "point"
if disc > 0:
return "two crossing lines"
k = (4 * A * F - D * D) + (4 * C * F - E * E)
if k < 0:
return "two parallel lines"
return "one line" if k == 0 else "empty"
EXAMPLES = [
("x^2 + y^2 - 2x + 4y + 1 = 0", (1, 0, 1, -2, 4, 1)),
("3x^2 + 2xy + 3y^2 - 8 = 0", (3, 2, 3, 0, 0, -8)),
("x^2 - 4y = 0", (1, 0, 0, 0, -4, 0)),
("xy - 1 = 0", (0, 1, 0, 0, 0, -1)),
("x^2 + y^2 + 1 = 0", (1, 0, 1, 0, 0, 1)),
("x^2 + y^2 = 0", (1, 0, 1, 0, 0, 0)),
("x^2 - y^2 = 0", (1, 0, -1, 0, 0, 0)),
("x^2 - 1 = 0", (1, 0, 0, 0, 0, -1)),
("x^2 - 2xy + y^2 = 0", (1, -2, 1, 0, 0, 0)),
("x^2 + 1 = 0", (1, 0, 0, 0, 0, 1)),
]
def main():
print("Named examples:")
for text, coeffs in EXAMPLES:
print(f" {text:<30} {classify(*coeffs)}")
counts = Counter()
for coeffs in itertools.product(range(-2, 3), repeat=6):
if coeffs[:3] != (0, 0, 0):
counts[classify(*coeffs)] += 1
total = sum(counts.values())
print(f"All {total} equations with coefficients in -2..2:")
for name, n in counts.most_common():
print(f" {name:<20} {n:6d} ({100 * n / total:4.1f}%)")
print("Parabolas need B^2 = 4AC exactly, a borderline case, so they are")
print("rare; a random small change turns one into an ellipse or hyperbola.")
print()
print("Epistemic status: exact integer computation of the standard")
print("classification by invariants. The classification itself (that")
print("these invariants decide the type) is a theorem explained in the")
print("lesson; this program applies it, it does not prove it.")
if __name__ == "__main__":
main()The named examples include all the degenerate cases from the classification theorem. Among all equations with small integer coefficients, parabolas are rare: they need exactly, a single equation among the coefficients, while ellipses and hyperbolas are defined by inequalities. The program applies the classification exactly, but it does not prove that the classification is right — that is the job of the theorem.
Explore: one family of curves
In polar coordinates, with a focus at the origin, every conic has the equation . Move the eccentricity from (a circle) through values below (ellipses that stretch out), to exactly (a parabola), and beyond (hyperbolas, whose second branch appears as becomes negative). This one formula is also how astronomers describe orbits.
Eccentricity decides the shape
Each angle θ gives a distance r from the origin.
- r = ℓ/(1 + e cos θ)
- (0.242, 0.242) · r = 0.342
Now the two-focus description. Change and and watch the foci move: when they meet at the centre and the ellipse is a circle.
An ellipse and its foci
A point moves along the curve as t changes: x and y are both functions of t.
- (a cos t, b sin t)
- (3.536, 2.121)
And a hyperbola with its asymptotes . Both branches hug the asymptotes far from the centre.
A hyperbola and its asymptotes
A point moves along the curve as t changes: x and y are both functions of t.
- right branch
- left branch
- y = (b/a) x
- y = −(b/a) x
- (5.006, −3.184)
- (−5.006, −3.184)
- (−2.813, −1.875)
- (−2.813, 1.875)
Exercises
1. Conic sections
Warm-upHumanThe parabola has its focus at . What is ?
2. Conic sections
Warm-upHumanFor every point on the ellipse , what is , the sum of the distances to the two foci?
3. Conic sections
CoreHumanThe ellipse has foci at . Find .
4. Conic sections
CoreHumanThe hyperbola has foci at . Find .
5. Conic sections
CoreHumanThe equation describes a non-degenerate conic. Which one?
6. Conic sections
CoreHumanThe equation describes a circle. What is its radius?
7. Conic sections
StretchHumanWhich of these equations describe something other than an ellipse, parabola or hyperbola? (Choose all that apply.)
8. Conic sections
StretchHumanIn the proof of the reflective property of the parabola, is the foot of the perpendicular from to the directrix, and the tangent at is the perpendicular bisector of . Why does this show that the reflected ray passes through ?
9. Conic sections
StretchFormalWhich Lean statement correctly says that is equidistant from the focus and the directrix exactly when ?
10. Conic sections
StretchComputationalWrite ellipse_foci(a, b) returning the two foci of the ellipse (with ) as a sorted list of two (x, y) tuples of floats. Careful: the major axis is horizontal only when !
Common misconceptions
Misconception
"A parabola is half of a hyperbola", or "a parabola eventually becomes straight". A parabola has one piece and no asymptotes: its slope grows without bound, and the gap between and any line tends to infinity. A hyperbola has two branches, each approaching two straight asymptotes.
Misconception
"Every second-degree equation describes a curve." Some describe a single point (), a pair of lines (), one line (), or nothing at all (). Apart from the empty set, these degenerate cases are also plane sections: of a cone through its tip, or (for parallel lines) of a cylinder.
Misconception
"The foci lie on the ellipse." The foci are inside the ellipse, on the major axis, at distance from the centre. For a hyperbola they are inside the two branches, at distance .
Misconception
" for every conic." For an ellipse , but for a hyperbola . The foci of a hyperbola are further from the centre than its vertices.
Misconception
"Eccentricity measures size." It measures shape: all circles have and all parabolas , whatever their size. Scaling a conic does not change .
Many ways of seeing
Geometry— One curve in the projective plane
Add to the plane a "line at infinity", one point for each family of parallel lines; this is the projective plane (see projective geometry). There, ellipses, parabolas and hyperbolas become a single kind of curve, differing only in how they meet the line at infinity: an ellipse misses it, a parabola touches it at one point (the direction of its axis), and a hyperbola crosses it at two points (the directions of its asymptotes). This is why a projection — a shadow cast from a point light — can turn one conic into another: the shadow of a circular lampshade on a wall can be a hyperbola. Pascal's theorem (1640) states that the three intersection points of opposite sides of any hexagon inscribed in a conic lie on a line, and it holds for all conics at once.
Physics— Orbits
Kepler's first law (1609) says that planets move on ellipses with the Sun at one focus. Newton showed in the Principia (1687) that an inverse-square force of attraction produces exactly conic orbits: in polar coordinates centred at the Sun, the orbit is . Planets and periodic comets have ; an object with exactly the escape energy would follow a parabola; faster ones, such as interstellar visitors and spacecraft on fly-bys, follow hyperbolas. The eccentricity is determined by the energy and angular momentum. See classical mechanics.
Number theory— Rational and integer points on conics
Which points of a conic have rational coordinates? On the circle , every line through with rational slope meets the circle again at the rational point , and every rational point arises this way. Clearing denominators gives all Pythagorean triples, such as from . Integer points are subtler: the hyperbola (a Pell equation) has infinitely many, , studied by Brahmagupta in the 7th century and solved in general by the chakravala method, described by Jayadeva and by Bhāskara II (11th–12th centuries). See number theory.
Algebra— Quadratic forms and symmetric matrices
The quadratic part is . Its determinant is , so the discriminant is the determinant in disguise. Rotating the axes to remove the term is diagonalising this symmetric matrix: its eigenvalues are the coefficients in the rotated equation, and an ellipse, parabola or hyperbola corresponds to eigenvalues of equal sign, a zero eigenvalue, or opposite signs. In three variables the same algebra classifies quadric surfaces: ellipsoids, paraboloids and hyperboloids. See linear algebra.
Wonder Trails
Optional, and never graded: a question that leads somewhere further.
Wonder Trail · Optional · never gradedWhy do planets move on ellipses?Planets move around the Sun on ellipses, with the Sun at one focus. Why ellipses — and not circles, egg shapes or spirals?Follow the trailHistory and global context
- Discovery. According to later Greek sources, Menaechmus (4th century BCE) discovered the conic sections while trying to double the cube (to construct a length with ): the intersection of two parabolas, or of a parabola and a hyperbola, solves the problem.
- Apollonius of Perga (around 200 BCE) wrote the Conics in eight books, showing that all three curves arise from a single double cone and giving them their names ellipse, parabola and hyperbola. Diocles proved the focal property of the parabola in On Burning Mirrors, and Pappus of Alexandria (4th century CE) stated the focus–directrix property.
- The Islamic world. Ibn Sahl (around 984, Baghdad) designed lenses and burning mirrors with conic profiles and stated the law of refraction; Ibn al-Haytham studied parabolic mirrors. ʿUmar al-Khayyām (around 1070) solved every type of cubic equation geometrically by intersecting conics.
- India. Brahmagupta (7th century) and Bhāskara II (12th century) solved equations such as , whose solutions are the integer points on hyperbolas.
- Europe. Kepler introduced the word focus (Latin for "hearth") in 1604 and discovered elliptical orbits; René Descartes and Pierre de Fermat described conics by second-degree equations in the 1630s; Girard Desargues and Blaise Pascal began their projective study; Newton derived conic orbits from the law of gravitation (1687); Dandelin found his spheres in 1822.
Further reading
- Keith Kendig, Conics (2005) — a beautifully illustrated tour from Apollonius to projective and complex conics.
- David Hilbert and Stephan Cohn-Vossen, Geometry and the Imagination (1932; English translation 1952) — chapter 1 includes the Dandelin spheres.
- Tom M. Apostol, Calculus, Volume 1 (1967) — conic sections, their polar equations and their use in Kepler's laws.
- H. S. M. Coxeter, Introduction to Geometry (1961) — conics in Euclidean and projective geometry.