# Flows Along Conic Sections

Here’s a cute bit of math I figured out recently. It probably doesn’t have much practical application, at least not for graphics programmers, but I thought it was fun and wanted to share it.

First of all, everyone knows about rotations: they make things go in circles! More formally, given
a plane to rotate in and a center point, rotations of any angle will preserve circles in the same
plane and with the same center. By “preserve circles”, I mean that the rotation will send every
point on the circle to somewhere on the same circle. The individual points move, but the *set*
of points comprising the circle is invariant under rotation.

Moreover, rotations with a fixed plane and center form a one-parameter family of transformations:
they can be parameterized by a single degree of freedom, the angle. By varying the angle, you move
the points around on each circle. Another way of saying this is that the family of rotations defines
a *flow* along circles: if you take derivatives with respect to the rotation angle, you can get a
vector field that shows how each point is pushed around by the rotation—like a velocity field in a
fluid simulation. The family of concentric circles preserved by the rotation show up as the
integral curves of this vector field.

So far, so good. Now for the fun part: it happens that **all conic sections**, not just circles,
have a similar family of linear or affine transformations that preserve them and induce a flow
along them.

Here’s a shadertoy to demonstrate. It cycles through circles, ellipses, parabolas, and hyperbolas, and in each case animates through transformations that preserve that conic. The background coordinate grid shows what the transformation is doing to the space, and dots trace individual points to show how they flow along the conic.

So, what are these transformations? Let’s look at each type of conic in turn.

**Circles**. As we’ve seen, circles are preserved by rotations, which can be parameterized by
their angle $\theta$ and have a matrix of the form:
$$
\begin{bmatrix}
\cos\theta & -\sin\theta \\ \sin\theta & \cos\theta
\end{bmatrix}
$$

**Ellipses**. Ellipses are just scaled circles, and the transformations that preserve them can be
derived by: scaling the ellipse to a circle, rotating, then unscaling back to the ellipse. If the
ellipse is axis-aligned and has aspect ratio $\alpha$, then the ellipse-preserving transformations
have the form:
$$
\begin{bmatrix}
\cos\theta & -\alpha\sin\theta \\ \frac{1}{\alpha}\sin\theta & \cos\theta
\end{bmatrix}
$$
Geometrically, this produces a rotation combined with some shear and nonuniform scaling that varies
with angle. Naturally, it reduces to the circle case when $\alpha = 1$.

**Parabolas**. This one is different! It turns out there’s no continuous family of *linear*
transformations that map a parabola to itself. However, there does exist a family of *affine*
transformations that does so. For the parabolas $y = x^2 + k$, it looks like this:
$$
\begin{bmatrix} x \\ y \end{bmatrix} \mapsto
\begin{bmatrix}
1 & 0 \\ v & 1
\end{bmatrix}
\begin{bmatrix} x \\ y \end{bmatrix} +
\begin{bmatrix} \frac{1}{2}v \\ \frac{1}{4}v^2 \end{bmatrix}
$$
This consists of a shear along the $y$-axis, which sort of “rolls” the parabola, pushing some points
up and others down so that a different point becomes the vertex. Then the translation puts the
vertex back where it was to begin with. The family of transformations is parameterized by the shear
fraction, $v$.

Note that unlike the previous cases, this family isn’t periodic. It’s unbounded; $v$ can range over all the real numbers. As $v$ gets farther from zero, the shear will get more and more extreme, and the original coordinate system more and more distorted—but the parabola stays just where it is, and its points just keep flowing along it.

**Hyperbolas**. We’re back to linear transformations again for these ones. Hyperbolas are preserved
by squeeze mappings, which are nonuniform scalings
that have reciprocal scale factors along two axes: if they scale one axis by a factor $a$, they
scale the other by $1/a$. The axes here must be aligned with the asymptotes of the hyperbola.

It turns out that a convenient way to parameterize these is in terms of the
hyperbolic angle (somewhat of a misnomer, as it
isn’t an *angle* in the usual sense at all). The hyperbolas $y^2 - x^2 = k$ are preserved by
transformations of the form:
$$
\begin{bmatrix}
\cosh u & \sinh u \\ \sinh u & \cosh u
\end{bmatrix}
$$
This kind of transformation is also known as a “hyperbolic rotation” or a
Lorentz transformation; it’s central in
special relativity (although there usually parameterized differently). Like the parabolic case,
the family is unbounded; $u$, the hyperbolic angle, can range over all real numbers but induces a
consistent flow along the hyperbolas no matter how positive or negative it gets.

Incidentally, these families of transformations we’ve been discussing are examples of continuous symmetry groups—Lie groups. The flow vector field is the generator of the Lie algebra for that Lie group.

And, as an application of Noether’s theorem, each family also has a corresponding conserved quantity—a particular function of the coordinates that’s conserved (does not change) when a transformation is applied. Consequently, these quantities are also constant along the corresponding conic sections. They can therefore serve to identify a specific conic section amongst all the ones preserved by the same family of transformations.

- Circles’ conserved quantity is $x^2 + y^2$, the radius of the circle.
- Ellipses (in the axis-aligned case) have conserved quantity $(x/\alpha)^2 + y^2$, an aspect-ratio-corrected radius.
- Parabolas (in the standard orientation and aspect ratio we considered) have conserved quantity $y - x^2$, the height of the parabola above the origin.
- Hyperbolas (in the standard orientation and aspect ratio we considered): the conserved quantity is $y^2 - x^2$, which is the plus or minus the hyperbola’s distance of closest approach to the origin.