Equation of an Oblique Cylinder in 3d Plane and checking if a point lies within it or not

250 Views Asked by At

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?

2

There are 2 best solutions below

6
On

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 $

0
On

Let's define the right circular cylinder using its base $\vec{b}$, unit axis vector $\hat{a}$, height $h$, and radius $r$.

(If the cylinder is standing at origin, with its axis towards the positive $z$ axis, then $\vec{b} = (0, 0, 0)$ and $\hat{a} = (0, 0, 1)$. Note that the axis vector being an unit vector means it is of unit length, $\left\lVert\hat{a}\right\rVert = 1$.)

If we extend this cylinder to infinity, we can define its surface as the points that are at distance $r$ from the axis. This is a simple case of point-line distance in 3D. Point $\vec{p}$ is on the surface of the right circular infinite cylinder, if and only if $$\left\lVert \hat{a} \times (\vec{p} - \vec{b}) \right\rVert = r \tag{1}\label{EQ1}$$ Similarly, point $\vec{p}$ is within the right circular infinite cylinder, if and only if $$\left\lVert \hat{a} \times (\vec{p} - \vec{b}) \right\rVert \le r \tag{2}\label{EQ2}$$

We can measure the distance from the point $\vec{b}$ along the axis using a simple dot product. Essentially, we extend the point $\vec{b}$ into a plane perpendicular to the axis of the cylinder, and measure the (signed) distance $d$ between point $\vec{p}$ and that plane, via $$d = \hat{a} \cdot (\vec{p} - \vec{b})$$ Since we defined $\vec{b}$ as the base, and the cylinder height $h$ is along the axis vector, the second equation we need for point $\vec{p}$ to be on the surface of the cylinder or within the cylinder is $$0 \le \hat{a} \cdot (\vec{p} - \vec{b}) \le h\tag{3}\label{EQ3}$$ Note that since this essentially "cuts" the infinitely long cylinder into the $h$-tall section starting at the base, this rule is the same regardless of whether you consider points on the surface of the cylinder, or points within the cylinder.

In pseudo-code, we could write the within-the-cylinder test as

Function  WithinCylinder(x,y,z, xA,yA,zA, xB,yB,zB, r, h)

    # L = p - B, the point p relative to the base B
    xL = x - xB
    yL = y - yB
    zL = z - zB

    # d = distance from B along cylinder axis
    d = xA*xL + yA*yL + zA*zL
    If (d < 0) Or (d > h) Then
        # Point is not within the h-tall section
        Return FALSE
    End If

    # s = distance squared from the cylinder axis
    s = (yA*zL - zA*yL)**2 + (zA*xL - xA*zL)**2 + (xA*yL - yA*xL)**2
    If (s <= r*r) Then
        Return TRUE
    Else
        Return FALSE
    End If

End Function

where (expression)**2 == (expression)*(expression), indicating squaring (raising to the second power).

Do note that the above function requires that $\hat{a}$ has unit length, i.e. that xA*xA+yA*yA+zA*zA==1.

If you want to define $\hat{a}$ using Euler or Tait-Bryan angles, such that with zero rotation the axis is parallel to the positive $z$ axis, use the rightmost column of the desired rotation matrix for the axis unit vector $\hat{a}$. (Each column or row vector of a true rotation matrix will have unit length.)