I am doing a research project and trying to figure out a problem to find whether a point in 3d space ( x,y,z) lies within an imaginary cylinder or not.
Going by the basic principles of coordinate geometry if f(a) - a < 0,0 ,>0 the point a will lie within/on/above the shape(line,circle,etc) a is a 2d point (x,y)
I am trying to use the same analogy to 3d shapes starting with a cylinder.
g(b) - b < 0,0,>0 will determine whether point b lies within the cylinder on the periphery of the cylinder or out of the cylinder.b is a 3d point(x,y,z)
Now after finding numerous posts on the web I am not able to get one simple equation of a cylinder that could satisfy my problem,
I have a few sets of points which I want to feed to my code which will determine whether those points will lie/away/inside the cylinder.
all I can get is the equation of a right circular cylinders x^2 + y ^2 = 18 |z| < 3
but not able to get the equation of a cylinder which is 3d space and makes, α,β and γ angle with the x,y, z-axis, ideally, I am looking for the equation of cylinder c(α,β,γ) in x,y,z plane.
Can anyone please assist?
If $\mathbf{a}$ is the unit vector along the axis of the cylinder in $3D$ space, and $\mathbf{r_0} $ is a point on this axis, and $R$ is its radius, then the algebraic equation of the cylinder is
$ ( \mathbf{r} - \mathbf{r_0} )^T ( \mathbf{ I - { a a} ^T}) ( \mathbf{r} - \mathbf{r_0} ) = R^2 $
where $\mathbf{r} = [x, y, z]^T $ is the position vector of any point on the cylinder.
This formula can be derived as follows. Given $\mathbf{r}$, the vector $\mathbf{r} - \mathbf{r_0}$ has a component along the axis $\mathbf{a}$ given by
$ \mathbf{v} = ((\mathbf{r} - \mathbf{r_0}) \cdot \mathbf{a}) \mathbf{a} = ((\mathbf{r} - \mathbf{r_0})^T \mathbf{a}) \mathbf{a} = \mathbf{a a}^T (\mathbf{r} - \mathbf{r_0})$
Hence, the component of $\mathbf{r} - \mathbf{r_0}$ perpendicular to the axis is given by
$\begin{equation} \begin{split} \mathbf{v}_\perp &= (\mathbf{r} - \mathbf{r_0}) - \mathbf{v} \\ &= (\mathbf{r} - \mathbf{r_0}) - \mathbf{a a}^T (\mathbf{r} - \mathbf{r_0}) \\ &= (\mathbf{I - {aa}^T} ) (\mathbf{r} - \mathbf{r_0}) \end{split} \end{equation} $
Now the length of $\mathbf{v}_\perp$ must be the radius $R$, therefore,
$ \mathbf{v}_\perp^T \mathbf{v}_\perp = (\mathbf{r} - \mathbf{r_0})^T (\mathbf{I - {a a}^T })^T (\mathbf{I - {a a}^T} ) (\mathbf{r} - \mathbf{r_0}) = R^2 $
Now, note that
$(\mathbf{I - {a a}^T })^T (\mathbf{I - {a a}^T} ) = (\mathbf{I - {a a}^T }) (\mathbf{I - {a a}^T} ) = (\mathbf{I - {a a}^T })$
Therefore, our cylinder equation becomes
$ (\mathbf{r} - \mathbf{r_0})^T (\mathbf{I - {a a}^T} ) (\mathbf{r} - \mathbf{r_0}) = R^2$
Now it is easy to see that a point $\mathbf{P}$ is on the cylinder if its coordinates satisfy the above equation, i.e.
$ (\mathbf{P} - \mathbf{r_0})^T (\mathbf{I - {a a}^T} ) (\mathbf{P} - \mathbf{r_0}) = R^2$
and it is inside the cylinder if
$ ( \mathbf{P} - \mathbf{r_0} )^T ( \mathbf{ I - { a a} ^T}) ( \mathbf{P} - \mathbf{r_0} ) \lt R^2 $
and it is outside the cylinder if
$ ( \mathbf{P} - \mathbf{r_0} )^T ( \mathbf{ I - { a a} ^T}) ( \mathbf{P} - \mathbf{r_0} ) \gt R^2 $