11

I know the perspective projection of a sphere on a plane is an ellipse. How would I find the parametric equation for this ellipse?

Say I have a camera at $(0, 0, z_2)$, a plane at $z=z_1$, and a sphere with radius $r$ centered at $(x_0, y_0, z_0)$. Specifically I want to find the equation of the ellipse created by the intersection of the plane with a cone with apex at the camera and tangent to the sphere.

I made a model in GeoGebra in case it helps: http://ggbtu.be/mCbZok04r

3 Answers3

7

WLOG I assume that $z_2=0$.

Let a ray be cast to the viewing plane in an arbitrary direction $\vec d=(x,y,z_1)$, so that a point along it is $t\vec d$. If we plug the coordinates to the sphere equation,

$$(t\vec d-\vec c)^2=r^2,$$

we get a second degree equation in $t$

$$\vec d^2t^2-2\vec d\cdot\vec c t+\vec c^2-r^2=0.$$

The ray passes through the apparent outline when the equation has a double root, i.e. when

$$(\vec d\cdot\vec c)^2-\vec d^2(\vec c^2-r^2)=0,$$ or $$(xx_0+yy_0+z_1z_0)^2-(x^2+y^2+z_1^2)(x_0^2+y_0^2+z_0^2-r^2)=0.$$

This is the implicit equation of the searched ellipse. You can reduce it to the canonical form by well-kown techniques of translation and rotation (also).

brainjam
  • 9,172
3

I’m going to assume that you’re familiar with homogeneous coordinates. The outline of a smooth surface under a central projection is the intersection with the image plane of rays from the viewpoint (camera center) that are tangent to the surface. For a quadric surface described by the symmetric matrix $\mathtt Q$, the resulting curve has a fairly simple representation in terms of dual conics/quadrics.

Let $\mathtt P$ be the $4\times 3$ projection (camera) matrix. A line $\mathbf l$ in the image back-projects to the plane $\mathtt P^T\mathbf l$. For this plane to be tangent to $\mathtt Q$, it must satisfy the dual quadric equation $$(\mathtt P^T\mathbf l)^T\mathtt Q^*(\mathtt P^T\mathbf l) = \mathbf l^T(\mathtt P\mathtt Q^*\mathtt P^T)\mathbf l = 0,$$ therefore the outline $\mathtt C$ of the image of $\mathtt Q$ is given by the dual formula $$\mathtt C^* = \mathtt P\mathtt Q^*\mathtt P^T.$$ For a nondegenerate quadric, we can take $\mathtt Q^*=\mathtt Q^{-1}$, so $\mathtt C$ can be computed as $\mathtt C = \left(\mathtt P\mathtt Q^{-1}\mathtt P^T\right)^{-1}$, though using cofactor matrices instead of inverses might be more convenient in practice. For a sphere, this curve will be an ellipse unless the sphere intersects the camera’s principal plane, in which case the outline will be a parabola or hyperbola instead.

You can then develop a parameterization of this curve by finding its center and principal axes using standard techniques such as those outlined here. Note that for an ellipse (and hyperbola), we already know its center: it’s the pole of the line at infinity, which is just the last row/column of $\mathtt C^*$. It’s also not necessary to compute the principal axes. Even though in the parameterization $\mathbf a\cos t+\mathbf b\sin t+\mathbf c$ (where $\mathbf c$ is the center), the vectors $\mathbf a$ and $\mathbf b$ usually correspond to the ellipse’s principal semiaxes, they can in fact be derived from any pair of conjugate radii. So, you can choose any convenient point $\mathbf p$ on the ellipse and set $\mathbf a=\mathbf p-\mathbf c$. A corresponding $\mathbf b$ can then be found by using the fact that the conjugate diameter is parallel to the tangent at $\mathbf p$, i.e., to the line $\mathtt C\mathbf p$.

When the surface is a sphere, there’s a relatively simple alternative to the above, namely, parameterize the outline generator $\mathbf\Gamma$ and project that. $\mathbf\Gamma$ is the locus of the tangent points of the rays that produce the outline. For a quadric, it’s the intersection of the surface with the polar plane $\mathtt Q\mathbf p$ of the viewpoint $\mathbf p$—a circle in this case. You can produce a parameterization of this circle of the form $R\mathbf u\cos t+R\mathbf v\sin t+\mathbf c$, where $\mathbf u$ and $\mathbf v$ are orthogonal unit vectors parallel to the polar plane, which you can then project by multiplying by $\mathtt P$. This parameterization isn’t as “nice” as the one developed above, though. After dehomogenization, the coordinates will have terms involving $\cos t$ and $\sin t$ in both the numerator and denominator.

amd
  • 55,082
  • @JoãoCartucho Sure. Construct a sphere at the origin and translate it to wherever it needs to be. Or write the matrix down directly from the sphere’s Cartesian equation: the coefficients of the squared terms and the constant term appear on the diagonal, the other entries in the last row and column are the coefficients of the $x$, $y$ and $z$ terms divided by two, and the rest of the matrix is zero (there shouldn’t be any cross terms). Incidentally, it’s often more convenient to work with $\operatorname{diag}(1,1,1,-r^2)$ for an origin centered-sphere than what’s in your cited source. – amd Dec 08 '21 at 21:01
0

Here is a geometric approach that gives you the axes of the ellipse. You can then derive a parametric equation from them.

Find the line that passes through the camera and the center of the sphere. This is the axis of the cone. Project that line onto the plane. The major axis of the ellipse will lie on the projected line. Let $L$ be the distance from the camera to the center of the sphere. The half aperture angle $\theta$ of the cone is then $\arcsin(r/L).$ Construct lines through the camera position at angle $\theta$ to the axis of the cone, passing through the projected line in the plane. The points where these lines intersect the plane are the ends of the major axis of the ellipse. The center of the ellipse is the midpoint of the major axis.

You now have the center of the ellipse and the length and orientation of its major axis. This tells you the orientation of the minor axis as well.

Find $\sin(\beta),$ where $\beta$ is the angle between the cone’s axis and the projection plane. Then the eccentricity of the ellipse is $$ e = \frac {\cos(\beta)}{\cos(\theta)}. $$ From the semi-major axis length and the eccentricity you can find the semi-minor axis and complete the parameterization of the ellipse.

David K
  • 108,155
  • if L is the distance from the camera to the center of the sphere, and r is the radius of the sphere, then the half aperture angle would be arctan(r/L), right? whereas the angle is arcsin(r/H) if H is the hypothenuse of the triangle (line from camera to sphere edge), is this not so? – jmarina Jan 19 '21 at 15:39
  • 1
    @jmarina The line from the camera tangent to the sphere makes a right angle with the radius at the point of tangency. So the line segment from the camera to the sphere's center, the line segment from the camera to the point of tangency, and the line segment from the center to the point of tangency indeed form a right triangle, as you have implied, but the hypotenuse of that right triangle is the line from the camera to the sphere's center. – David K Jan 19 '21 at 18:05
  • @jmarina Perhaps you were thinking of the usual way we create a circular cone, which is to choose a line through a point as an axis, and then construct a circular disk perpendicular to that line with center on the line. In that case it is true that the segment from the cone's vertex to the circumference of the circle is the hypotenuse of a right triangle whose right angle is at the center of the circle. A circle, of course, is not the same thing as a sphere. – David K Jan 19 '21 at 18:08