[Math] Equation for points within a finite cylinder of arbitrary axial line.

geometryrotations

If I have a finite length cylinder with axis along the line defined by points $P_1(x_1, y_1, z_1)$ and $P_2(x_2, y_2, z_2)$ in Cartesian space, how can I find a point $P(x, y, z)$ in Cartesian coordinates from the variables:

  • $dl$: a distance from $P_1$ along the axis towards $P_2$
  • $r$: a distance perpendicular to the axis line $P_1P_2$ (radius of the cylinder)
  • $\theta$: the rotation angle around the axis line.

I have tried approaches similar to:
http://mathforum.org/library/drmath/view/51734.html and
the cylinder wiki page for arbitrary cylinders, but to no end.
http://planning.cs.uiuc.edu/node102.html for a rotation matrix approach, but I haven't been able to write down a generalized statement to handle all cases.

Best Answer

We can find the distance $d$ from point $\vec{p}$ to the infinite right circular cylinder whose axis passes through points $\vec{p}_1$ and $\vec{p}_2$ using point-line distance (to the axis): $$d = \frac{ \left\lVert \left ( \vec{p}_2 - \vec{p}_1 \right ) \times \left ( \vec{p}_1 - \vec{p} \right ) \right\rVert}{\left\lVert \vec{p}_2 - \vec{p}_1 \right\rVert}$$
We can use $t$ to denote the position along the axis (so that the line between that point and point $\vec{p}$ is perpendicular to the axis), with $t=0$ at $\vec{p}_1$, and $t=1$ at $\vec{p}_2$: $$t = \frac{ \left( \vec{p} - \vec{p}_1 \right) \cdot \left( \vec{p}_2 - \vec{p}_1 \right) }{\left\lVert \vec{p}_2 - \vec{p}_1 \right\rVert^2}$$
Point $\vec{p}$ is within the right circular cylinder, if and only if $$\begin{cases} t \ge 0 \\ t \le 1 \\ d \le r \end{cases}$$
Because the right circular cylinder is axially symmetric, there is no "zero $\theta$ angle" we can refer to. We must establish one ourselves.

Let's say we have an unit vector $\hat{c}$ ($\left\lVert\hat{c}\right\rVert^2 = \hat{c}\cdot\hat{c} = 1$) that establishes that zero angle for us. The vector must be perpendicular to the axis, i.e. $$\hat{c} \cdot \left ( \vec{p}_2 - \vec{p}_1 \right ) = 0$$ If you have some generic zero angle vector $\vec{v}$ which is not parallel to the axis, you can calculate $\hat{c}$ in two steps, using $$\vec{v}' = \vec{v} - \vec{v} \cdot \left( \vec{p}_2 - \vec{p}_1 \right) \frac{\vec{p}_2 - \vec{p}_1}{\left\lVert \vec{p}_2 - \vec{p}_1 \right\rVert^2}$$ Note that $\vec{v}'$ is the original vector $\vec{v}$ with the axis-parallel-part subtracted from it; thus, it is perpendicular to the axis. We only need to normalize it to unit length to get $\hat{c}$: $$\hat{c} = \frac{\vec{v}'}{\left\lVert\vec{v}'\right\rVert}$$


If we already know $d$ and $t$, we can easily construct an unit vector $\hat{q}$, from the axis towards point $\vec{p}$: $$\hat{q} = \frac{\vec{p} + t \left ( \vec{p}_1 + \vec{p}_2 \right ) - \vec{p}_1}{\left\lVert \vec{p} + t \left ( \vec{p}_1 + \vec{p}_2 \right ) - \vec{p}_1 \right\rVert}$$ This unit vector is perpendicular to the axis (because that's how $t$ was defined), so the angle $\theta$ can now be easily calculated: $$\begin{cases} \cos\theta = \hat{q} \cdot \hat{c} \\ \sin\theta = \left\lVert \hat{q} \times \hat{c} \right\rVert \end{cases}$$


When $\vec{p}_1$, $\vec{p}_2$, $\hat{c}$, $t$, $d$, $\sin\theta$, and $\cos\theta$ are known, we can calculate point $\vec{p}$.

First, we need a helper unit vector $\hat{u}$ which is perpendicular to both the axis ($\hat{u}\cdot\left(\vec{p}_2-\vec{p}_1\right)=0$) and the zero angle unit vector $\hat{c}$ ($\hat{u}\cdot\hat{c}=0$): $$\hat{u} = \frac{ \hat{c} \times \left ( \vec{p}_2 - \vec{p}_1 \right ) }{\left\lVert \hat{c} \times \left ( \vec{p}_2 - \vec{p}_1 \right ) \right\rVert }$$
Then, $$\vec{p} = (1 - t)\,\vec{p}_2 + t\,\vec{p}_1 + \hat{c}\,d \cos\theta + \hat{u}\,d \sin\theta$$


Years ago, I wrote some related equations to my Wikipedia talk page, but never found the effort to try and push it anywhere more approppriate to be worthwhile. You might find it interesting or useful, though.