[Math] Point inside right circular cone

geometry

I have already posted this on SO here with code however I'm really thinking that my line of thought (mathematical that is) is incorrect and that's why my code isn't working as intended so I decided to ask here since this is a mathematical problem.

I have a right circular cone with its tip ($\vec{tip} = (x_{tip},y_{tip},z_{tip})$) being the first point of the set of points and the center of the base being a point lying at the same $x$, $y$ coordinates but with $z$ equal to $0$ ($\vec{base} = (x_{tip},y_{tip},0)$). I have also a given angle between the cone's axis (tip to base) and the slant.

For every point in the set I have to check if it's inside the cone or not. For simplicity reasons I mark a point as valid if it is either really inside or at least lying on the cone's surface. A point is invalid if it lies outside.

In order to that I check two things:

  • Is the point above the cone? – due to the range of values I have and the way I define my cone's base (at $z = 0$) a point cannot go below the cone's base (however it can lie on it in which case it is a valid one). This check is pretty simple. The height of the cone is already given by its tip (the first point from the set) so I just have to do a one-dimensional test comparing $z$ values. If the point is above the given height of the cone it is clearly outside.

$$
checkHeightOkay(z) :
\begin{cases}
yes & z_{point}\leq z_{tip} \\
no & else
\end{cases}
$$

  • Is the point on the inside of/lying on the circumference of the slice of the cone at the given height or not? – this test is a two-dimensional one. After making sure that the point is not above the cone (that is it's $z$ coordinate is okay) I calculate the slice of the cone at the height of the point (not that in my case the cone goes along the $z$ and not the $x$ axis as in the image below):

enter image description here

with the following formula for the radius:

$$\frac{r_{slice}}{z_{point}} = \frac{R_{cone}}{h_{cone}} \Rightarrow r_{slice} = \frac{R_{cone} \cdot z_{point}}{h_{cone}}$$

For measuring if the point's x and y coordinates are part of this slice I use Euclidean distance:

$$dist(\vec{axis_{cone}}, \vec{point}) = \sqrt[]{(x_{tip} – x_{point})^2 + (y_{tip} – y_{point})^2}$$

And as a last step I check if $dist$ is $\le$ (inside) or $> r_{slice}$ (outside).

It seems however that this doesn't work since some points that are supposed to be valid are marked as invalid and vice versa (for more details and code you can check the link at the beginning of this post).

The algorithm is pretty straight forwards and I have really no idea what I'm doing wrong here.

Best Answer

One mistake, that I can spot, is that the relation:

$$\frac{r_{slice}}{z_{point}} = \frac{R_{cone}}{h_{cone}}$$

should be changed to

$$\frac{r_{slice}}{z_{tip}-z_{point}} = \frac{R_{cone}}{h_{cone}}.$$

I think the rest is fine.