How to calculate the intersect of a point-vector and a cone in 3D space.

125 Views Asked by At

I have a 3D modeling problem where I am trying to modify a mesh to make it 3d printable without supports. I have been able to identify "unsupported" vertices in the mesh. What I want to do is move the vertex along its normal vector until it intersects a cone. This cone will originate from a neighboring vertex in the mesh, will open upwards, and will always have the axis be the vertical (z-axis). The relative locations of the vertices and the slope of the cone can vary.

I need to calculate the coordinates of the intersecting point given the coordinates of the original point, a vector from the original point, the coordinates of the tip of the cone, and the angle of the cone.

I'm at a complete loss for how to do this. Probably something I learned 25 years ago in college and forgot because I haven't used it since.

vector intersecting a cone

1

There are 1 best solutions below

6
On BEST ANSWER

Let $\vec{c} = (x_c, y_c, z_c)$ be the apex of the cone; "spread" $k = \tan(\theta)$ where cone aperture or apex angle is $2\theta$ (so $0 \lt \theta \lt 90^\circ$); $\vec{v} = (x_v, y_v, z_v)$ be the initial location of the vertex, and $\vec{n} = (x_n, y_n, z_n)$ be the direction along which you wish to move the vertex.

Point $(x, y, z)$ is on the surface of the cone if and only if $z \ge z_c$ and $$(x - x_c)^2 + (y - y_c)^2 = k^2 (z - z_c)^2 \tag{1}\label{BtV1}$$

Moving the vertex along the chosen direction by distance $d$ (in units of the direction vector length, i.e. $d = 1$ moving by one direction vector) gives the vertex coordinates $$\left\lbrace \begin{aligned} x &= x_v + d x_n \\ y &= y_v + d y_n \\ z &= z_v + d z_n \\ \end{aligned} \right. \tag{2} \label{BtV2}$$

Substituting $\eqref{BtV2}$ into $\eqref{BtV1}$ gives us a single equation in one unknown, $d$: $$(x_v + d x_n - x_c)^2 + (y_v + d y_n - y_c)^2 = k^2 (z_v + d z_n - z_c)^2 \tag{3a}\label{BtV3a}$$ which has a pair of solutions. To keep the solution short, let's use $x_\Delta = x_v - x_c$, $y_\Delta = y_v - y_c$, and $z_\Delta = z_v - z_c$: $$\begin{aligned} d & = \frac{x_n x_\Delta + y_n y_\Delta - k^2 z_n z_\Delta}{k^2 z_n^2 - x_n^2 - y_n^2} \\ ~ & \pm \frac{\sqrt{ k^2 \biggl( \bigl( x_\Delta z_n - x_n z_\Delta \bigr)^2 + \bigl( y_\Delta z_n - y_n z_\Delta \bigr)^2 \biggr) - \bigl( x_\Delta y_n - x_n y_\Delta \bigr)^2 }}{k^2 z_n^2 - x_n^2 - y_n^2} \\ \end{aligned} \tag{3b}\label{BtV3b}$$ Calculate both $d_{+}$ and $d_{-}$, and pick the smaller nonnegative one for which $z_v + d z_n \ge z_c$. Then, the point where the vertex meets the surface of the cone is given by $\eqref{BtV2}$.


Note that you can use the inequality form of $\eqref{BtV1}$ to check if the vertex is already within the cone, assuming $z_v \ge z_c$: $$(x_v - x_c)^2 + (y_v - y_c)^2 \le k^2 (z_v - z_c)^2 \quad \iff \quad x_\Delta^2 + y_\Delta^2 \le k^2 z_\Delta^2$$