# Calculating an axis aligned bounding box for a transformed sphere

I'm trying to understand the math behind this answer :

https://stackoverflow.com/questions/4368961/calculating-an-aabb-for-a-transformed-sphere/4369956#4369956

I've implemented it and it seems to work, but I don't know why ..

Can somebody point me to a definition of the dual of a conic and why it allows us to find the planes tangent to the tranformation ?

Thanks.

## migrated from mathoverflow.netSep 5 '13 at 17:36

This question came from our site for professional mathematicians.

The first trick is that if points are represented by homogeneous coordinates $\vec{p} = \begin{bmatrix}x & y & z & 1\end{bmatrix}^\mathrm{T}$, a plane can be represented by a row vector $\vec{q}^\mathrm{T} = \begin{bmatrix}a & b & c & d\end{bmatrix}$ such that

$$\vec{q} \cdot \vec{p} = a\,x + b\,y + c\,z + d = 0$$

is the plane equation. For a point $\vec{p}$ on the surface, the particular plane $\vec{q}^\mathrm{T} = \vec{p}^\mathrm{T}\,\mathbf{S}$ touches the surface at $\vec{p}$ since $\vec{q} \cdot \vec{p} = \vec{p}^\mathrm{T}\,\mathbf{S}\,\vec{p} = 0$.

In fact, this point is the only point of intersection, so $\vec{q}$ must be the tangent plane at that point. To see why, look at any point $\vec{p}' = \vec{p} + r\,\hat{r}$ that lies on the plane and the surface.

\begin{align*} \vec{p}'^\mathrm{T} \, \mathbf{S} \, \vec{p}' & = (\vec{p} + r\,\hat{r})^\mathrm{T} \, \mathbf{S} \, \vec{p}' \\ {} & = \vec{q}\cdot\vec{p}' + r\,\hat{r}^\mathrm{T} \, \mathbf{S} \, \vec{p}' \\ {} & = r \, (\vec{p}'^\mathrm{T} \, \mathbf{S} \, \hat{r})^\mathrm{T} \\ {} & = r \, \left((\vec{p} + r\,\hat{r}\right)^\mathrm{T} \, \mathbf{S} \, \hat{r})^\mathrm{T} \\ {} & = r^2 \, (\hat{r}^\mathrm{T} \, \mathbf{S} \, \hat{r})^\mathrm{T} \\ {} & = r^2 \, (\hat{r}^\mathrm{T} \, \mathbf{S} \, \hat{r}) \\ {} & = 0 \end{align*}

If $\hat{r}^\mathrm{T} \, \mathbf{S} \, \hat{r} = 0$, then the whole line $\vec{p} + t\,\hat{r}$ lies on the surface, but that can't be true since the surface is curved. Therefore $r = 0$ and $\vec{p}' = \vec{p}$.

That's all we need to prove the formula for the so-called dual,

\begin{align*} \vec{q}^\mathrm{T} \, \mathbf{S}^{-1} \, \vec{q} & = \vec{p}^\mathrm{T} \, \mathbf{S} \, \mathbf{S}^{-1} \, \mathbf{S} \, \vec{p} \\ {} & = \vec{p}^\mathrm{T} \, \mathbf{S} \, \vec{p} \\ {} & = 0. \end{align*}

By the way, I know these as quadric surfaces or quadratic forms. To me a conic section lies in the plane. Also, I wrote a blog post here that covers this topic and gives a simplified form for the bounding boxes that should be faster to calculate.