[Math] Cartesian equation cylinder along a line

3dgeometry

What is the cartesian equation for a cylinder along a line in a 3d space?

Imagine two points in a 3d space, (Xc,Yc,Zc) and (Xp,Yp,Zp).

The equation for the line connecting these points is:

(x-Xc)/(Xp-Xc)=(y-Yc)/(Yp-Yc)=(z-Zc)/(Zp-Zc)

This line is the centerline for a cylinder with radius R.

On the math-forum I found this:

If the line goes through the point (X0,Y0,Z0) and in the direction of
the unit vector u = (u1,u2,u2), it is not difficult to show that for
an arbitrary point (X,Y,Z), the point on the line closest to (X,Y,Z)
is
(X0,Y0,Z0) + ((X-X0)u1+(Y-Y0)u2+(Z-Z0)u3) (u1,u2,u3)
So, calculate the square of the distance from (X,Y,Z) to this point
and set the result equal to R^2.

But I'm missing something here.

To give you a further context: the cylinder union a sphere will be calculated, and that curve union a plane will (hopefully) result in an easy parametrisation of two points.

Edit:Explanation of the further context

Imagine a ball with a tropic circle (offset against equator). This circle defines a plane (red one on sketch). This ball rotates along an axis, different from the north-south axis, given by the z' axis on sketch (d).

I hold a grinder in the red plane, which is always pointing at a point on the z-axis.

I know the position of the center of the grinder relative to the sphere at each moment, and would like to calculate the trajectory the grinder makes into the sphere.

(not enough posts to set sketch inline with text)
Link to sketch

Figure (d) gives a clear overview of the 3d problem. The grey area represents a sphere, the red area a plane in this sphere and "Pin" is the cylinder with the equation that Nominal Animal has given.

On figure (b) you see the two points D and C, that define the centerline for the cylinder. Point D is given at time t*, as is point C. Point D moves on the outer red circle in figure (d), point C moves in a circle along the rotation axis of the sphere, this is shown by the red dotted line on (b).

So now I know the equation of the cylinder, and I calculate the cross section with this cylinder Pin and the sphere. (equation in answer + sqrt(x^2+y^2+z^2)=1).

Then I also know the blue plane in figure (a), which stands perpendicular on the velocity, given by ux+vy+wz=0 (plane goes through the origin of the sphere). This is the third equation.

All this to calculate the trajectory of the grinder.

Best Answer

The points on the infinite right circular cylinder are at distance $r$ from the axis of the cylinder. The distance between point $\vec{p}$ and line through $\vec{p}_1$ and $\vec{p}_2$ is $$d = \frac{\left \lvert (\vec{p} - \vec{p}_1) \times (\vec{p} - \vec{p}_2) \right \rvert}{\left \lvert \vec{p}_1 - \vec{p}_2 \right \rvert}$$ so we can square that to get our equation describing an infinite right circular cylinder of radius $r$ whose axis passes through points $\vec{p}_1$ and $\vec{p}_2$: $$r^2 = \frac{\left \lvert (\vec{p} - \vec{p}_1) \times (\vec{p} - \vec{p}_2) \right \rvert^2}{\left \lvert \vec{p}_1 - \vec{p}_2 \right \rvert^2}$$ That can be written using Cartesian coordinates as $$r^2 = \frac{ \left ( (y-y_1)(z-z_2) - (z-z_1)(y-y_2) \right )^2 }{(x_2-x_1)^2 + (y_2-y_1)^2 + (z_2-z_1)^2 } + \frac{ \left ( (z-z_1)(x-x_2) - (x-x_1)(z-z_2) \right )^2 }{(x_2-x_1)^2 + (y_2-y_1)^2 + (z_2-z_1)^2 } + \frac{ \left ( (x-x_1)(y-y_2) - (y-y_1)(x-x_2) \right )^2 }{(x_2-x_1)^2 + (y_2-y_1)^2 + (z_2-z_1)^2 }$$ which we can convert to standard form by multiplying by the right-hand-side denominator, and moving all to the same side: $$\left ( (y-y_1)(z-z_2) - (z-z_1)(y-y_2) \right )^2 + \left ( (z-z_1)(x-x_2) - (x-x_1)(z-z_2) \right )^2 + \left ( (x-x_1)(y-y_2) - (y-y_1)(x-x_2) \right )^2 - r^2 \left ( (x_2-x_1)^2 + (y_2-y_1)^2 + (z_2-z_1)^2 \right ) = 0$$

I have at my Wikipedia talk page the equations to locate the intersection between a line passing through origin and an arbitrary right circular cylinder; without caps, with flat end caps, or with spherical end caps. The key point is that when the ray (or line we are testing intersection for) passes through origin (so we use an unit vector $\hat{n}$, $\lvert\hat{n}\rvert=1$, to describe the line or ray), the equations become rather straightforward.


If the underlying problem is related to grinding spheres using a grinding wheel -- a cutting plane, essentially -- then a simplified coordinate system where origin is the sphere origin, and $\hat{z}$ is along the rotation axis, makes for easy calculations. Consider this illustration:

Grinding sphere]

The contact point scribes a circle around the axis of rotation. We can describe this circle using a single scalar, $d$, which is the signed distance from the origin to the plane of that circle, along the axis of rotation. If the circle is not on the surface of the sphere, but perhaps inside it, then we need a second scalar, $r$, to describe the radius of the circle (around the axis of the rotation).

If the radius of the sphere is $R$, then on the surface of the sphere $r = \sqrt{R^2-d^2}$, of course.

If we include the cutting or abrasion done by the wheel, then two pairs of scalars are needed: $(d_1,r_1)$ and $(d_2,r_2)$. If we assume the grinding wheel is planar, and stays at a fixed location with a perfect cut for at least one rotation of the sphere, the removed section of the sphere leaves a flat facet. Mathematically, $$r(d) = r_1 + \left ( d - d_1 \right ) \frac{r_2 - r_1}{d_2 - d_1}$$ where $d_1 \le d \le d_2$. Remember, $d$ is the distance along the axis of rotation, and $r$ the circle radius (around a point on the axis of rotation, at distance $d$ from the center of the sphere); that is why the dependence above is linear too.

If the axis of the grinding wheel always intersects the rotation axis, and you call up $z$ and right $x$ in the above diagram, then $(d,r) = (z,x)$, and the primary problem (surface of revolution caused by grinding, or shape of the "sphere" after several grinds) reduces to planar (2D) vector calculus.

If we also have the axis of rotation $\hat{n}$ in some fixed sphere coordinate system, it is easy to calculate the "ribbons" each grind cuts into the sphere, either parametrically (using say $0 \le u \le \pi$ along the circular ribbon, and $0 \le v \le 1$ across the ribbon -- useful for visualization) or algebraically.