# Shortest Distance of a Point in $R^3$ to a Cone

I'm having a problem how to figure out the shortest distance of a point $\vec{p} = [x_p, y_p, z_p]$ to the surface of a cone given by:

• Start vertex $\vec{a} = [x_a, y_a, z_a]$. This is the center of the bottom circle in $\Bbb{R}^3$.
• End vertex $\vec{b} = [x_b, y_b, z_b]$. This is the center if the top circle in $\Bbb{R}^3$.
• The main axis of the cone is then defined as $\vec{b} - \vec{a}$.
• Base radius $r_a$, top radius $r_b$.
• Height $h$ is defined as $|\vec{b} - \vec{a}|$.

i tried to solve the case for a symmetric cone first but im not coming that far

• What do you mean by "start vertex" and "end vertex"? And is it correct they are the same point as p? – DavidButlerUofA Jul 9 '14 at 8:44
• Hi David, i edited the question so i hope its more clear now. you may define a cone with $r_a = 2, r_b = 1$ and $\vec{a} = \vec{0}, \vec{b} = [0, 1, 0]$ so you get a conical frustum at the origin pointing top. if you set $r_b=0$ you get a typical cone with its apex at [0, 1, 0] – reads Jul 9 '14 at 11:59
• Is the axis of the cone at right angles to the two circles? Also, when you say "$[px, py, pz]$" do you mean p TIMES x, y, z or do you mean more like "$[p_x, p_y, p_z]$"? – DavidButlerUofA Jul 9 '14 at 12:02
• I mean $p_x, p_y, p_z$. For a first step i assume that they are perpendicular yes. As soon as i have a solution for that problem, i want to try and find one for the case that they are not. – reads Jul 9 '14 at 14:36

## 3d --> 2d

You can use the rotational symmetry of the cone to reduce the problem to $\Bbb{R}^2$: take the plane which contains $p$, $a$, and $b$, i.e., the plane through the point and the axis of the cone.

Now, the point on the cone closest to $p$ lies on this plane, do all you need to do is to find the distance from a given point to the given isosceles trapezoid (which is the intersection of the cone with the plane).

## Distance from a polygon

The distance to a polygon (a trapezoid in your case) is the smallest of the distances from its sides.

The computation of the distance between a point $\vec{p}$ and a segment (a side of the polygon) with ends $\vec{a}$ and $\vec{b}$ depends on the position of the projection of $\vec{p}$ on the segment relative to its ends ($(\cdot,\cdot)$ is the scalar product of two vectors, $||\vec{x}||=\sqrt{(\vec{x},\vec{x})}$ is the length of a vector):

If $(\vec{p}-\vec{b},\vec{b}-\vec{a})\ge 0$, then the projection lies outside of the segment beyond $\vec{b}$ and the distance is $||\vec{p}-\vec{b}||$.

If $(\vec{p}-\vec{a},\vec{a}-\vec{b})\ge 0$, then the projection lies outside of the segment beyond $\vec{a}$ and the distance is $||\vec{p}-\vec{a}||$.

Otherwise the projection lies inside the segment and the distance is $$||(\vec{p}-\vec{a}) - \frac{\vec{b}-\vec{a}}{||\vec{b}-\vec{a}||^2}(\vec{b}-\vec{a},\vec{p}-\vec{a})||$$

• thats as far as i got when i thought about it. but im really stuck at the point when i try to write it down. I get the plane vectors $\vec{v_1} = \vec{p} - \vec{a}$ and $\vec{v_2} = \vec{b} - \vec{a}$ but im still stuck in $R^3$ – reads Jul 9 '14 at 15:43

2d -> 3d

In the "3d -> 2d" post, the shortest distance is in the plane through $\vec{p}$ and the axis of the cone. The intersection of this plane and the cone is a trapezium and you need to find the 3D coordinates of each of its vertices. In the picture I have labelled these vertices as $\vec{c}$, $\vec{d}$, $\vec{e}$, $\vec{f}$.

These four points are all a perpendicular distance from the axis. If we can find a direction vector perpendicular to the axis in this plane, then we can make a unit vector in this direction and so find the coordinates of the vertices.

The vector $\vec{x}$ in the diagram is perpendicular to the axis. You can find it by projecting $\vec{p}$ onto the axis and subtracting the result. This was done in the "3d -> 2d" post already:

So: $$\vec{x} = (\vec{p} - \vec{a}) - \frac{(\vec{p}-\vec{a},\vec{b}-\vec{a})}{(\vec{b}-\vec{a},\vec{b} - \vec{a})}(\vec{b} - \vec{a})$$ Dividing this vector by its length gives a unit vector, which I will call $\vec{u}$. That is, $$\vec{u} = \frac{1}{||\vec{x}||}\vec{x}$$

Now we have the following: $$\vec{c} = \vec{a} + r_a \vec{u}\\ \vec{d} = \vec{b} + r_b \vec{u}\\ \vec{e} = \vec{b} - r_b \vec{u}\\ \vec{d} = \vec{a} - r_a \vec{u}$$

From the "3d -> 2d" post, you need to find the shortest distance from $\vec{p}$ to each of the edges of the trapezium, and the minimum of all of these is the shortest distance from $\vec{p}$ to the cone.

• that was of great help, but shouldnt $\vec{x}$ be $\vec{x} =( \vec{p} - \vec{a}) - (\vec{b} - \vec{a}) \cdot \frac{(\vec{p} - \vec{a}, \vec{b} - \vec{a})}{(\vec{b} - \vec{a}, \vec{b} - \vec{a})}$ – reads Jul 10 '14 at 10:02
• Also im still not quite sure what i should make of the cases from sds answer. Why should the shortest distance always be to one of the points $\vec{c}, \vec{d}, \vec{e}$ or $\vec{f}$? It may be on the vector $\vec{c} - \vec{d}$? – reads Jul 10 '14 at 10:09
• It doesn't have to be at one of the corners. Suppose the shortest distance to the infinite line $\vec{c}\vec{d}$ is at the point $\vec{y}$. Then the angle between $\vec{d} - \vec{c}$ and $\vec{p} - \vec{y}$ will be a right angle so $(\vec{d} - \vec{c},\vec{p} - \vec{y}) = 0$. However, the only way this could happen is if the angles using $\vec{c}$ and $\vec{d}$ for $\vec{y}$ were such that one was obtuse and the other acute. This would require the scalar products to be opposite signs. If they are, then the shortest distance is to a point between. If not, then it is to one of the corners. – DavidButlerUofA Jul 10 '14 at 10:55