Volume of the intersection of two cylinders
I have two infinite cylinders of unit radius in $\mathbb{R}^3$, whose axes are skew lines. Say that the axis of one is centered on the $x$-axis, and the axis of the other is determined by the two points $a$ and $b$. Is there a formula for the volume of their intersection, as a function of $a$ and $b$?
Solution 1:
Let
- $r = 1$ be the common radii of the two cylinders.
- $2d$ be the nearest distance between the two axis of the cylinders.
- $\alpha = 2\beta$ be the angle between the two axis of the cylinders.
Choose the coordinate system so that the axis of the cylinders pass through $(0, \pm d, 0)$ with tangent vectors $( \pm\sin\beta, 0, \cos\beta)$ respectively. It is not hard to see the two cylinders are give by.
$$\mathcal{C}_{\pm} = \left\{ (x,y,z) \in \mathbb{R}^3 : ( x\cos\beta \mp z\sin\beta )^2 + (y \mp d)^2 \le r^2 \right\}$$
If we intersect $\mathcal{C}_{\pm}$ with a plane of constant $z$, the intersections will be two axis aligned ellipses with semi major axis $\frac{r}{\cos\beta}$ in the $x$-direction and semi minor axis $r$ in the $y$-direction. Introduce new coordinates $$(u,v,w) = (x\cos\beta, y, z\sin\beta) \quad\iff\quad (x,y,z) = \left(\frac{u}{\cos\beta}, v, \frac{w}{\sin\beta}\right) $$ The intersections of $\mathcal{C}_{\pm}$ with a plane of constant $w$ become two circles of radii $r$. $$(u \mp w)^2 + (v \mp d)^2 \le r^2$$ and these two circles intersect when and only when $d^2 + w^2 \le r^2$.
When they intersect, let $\theta = \cos^{-1}\left(\frac{\sqrt{d^2 + w^2}}{r}\right)$. In the diagram below, the intersection is the one bounded by the two circular arc in red. Its area is equal to
$$\begin{align} & \verb/Area/(\text{sector } ABD) + \verb/Area/(\text{sector } CDB) - \verb/Area/(\text{rhombus } ABCD)\\ = & 2\verb/Area/(\text{sector } ABD) - 4\verb/Area/(\text{triangle } OAB)\\ = & 2\left(\frac12 r^2(2\theta)\right) - 4\left(\frac12 (r\sin\theta)(r\cos\theta)\right)\\ = & r^2(2\theta - \sin(2\theta)) \end{align} $$
$\hspace1.25in$
Let $\displaystyle\;\theta_0 = \cos^{-1}\left(\frac{d}{r}\right)\;$, the volume we want becomes
$$\begin{align}\verb/Volume/ &= \overbrace{\frac{1}{\cos\beta\sin\beta}}^{\color{blue}{\text{Jacobian}}} \int_{-\sqrt{r^2 - d^2}}^{\sqrt{r^2 - d^2}} r^2 (2\theta - \sin(2\theta)) d w\\ &= \frac{-4r^3}{\sin\alpha} \int_{0}^{\theta_0} (2\theta - \sin(2\theta)) d\sqrt{\cos^2\theta - \cos^2\theta_0}\\ \color{blue}{\text{ integrate by part } \rightarrow} &= \frac{16 r^3}{\sin\alpha}\int_0^{\theta_0} \sin^2\theta \sqrt{\cos^2\theta - \cos^2\theta_0} d\theta\\ \color{blue}{ m = \sin^2\theta_0 \rightarrow} &= \frac{16 r^3}{\sin\alpha}\int_0^\sqrt{m} \frac{\sin^2\theta}{\cos\theta}\sqrt{m - \sin\theta^2} d\sin\theta\\ \color{blue}{ \sin\theta = \sqrt{m} t \rightarrow} &= \frac{16 r^3 m^2}{\sin\alpha}\int_0^1 t^2\sqrt{\frac{1-t^2}{1-mt^2}} d t\\ &= \frac{16 r^3 m^2}{\sin\alpha}\int_0^1 \frac{t^2 - t^4}{\sqrt{(1-t^2)(1-mt^2)}} dt \end{align} $$
Let $Q(t) = (1-t^2)(1-mt^2)$, it is easy to check
$$\frac{d}{dt}\left(t \sqrt{Q(t)}\right) = \frac{1}{\sqrt{Q(t)}}\left(3m t^4 - 2(m+1) t^2 + 1\right)$$ We can use this to transform the last integral as
$$\begin{align}\verb/Volume/ &= \frac{16 r^3 m}{3\sin\alpha}\int_0^1 \frac{3m t^2 - 2(m+1) t^2 + 1}{\sqrt{Q(t)}} dt\\ &= \frac{16 r^3}{3\sin\alpha}\int_0^1 \frac{(2-m)(1-mt^2) - 2(1-m)}{\sqrt{Q(t)}} dt \end{align} $$ Compare this with the definition of the complete elliptic integrals of the $1^{st}$ and $2^{nd}$ kind.
$$\begin{align} K(m) &= \int_0^{\pi/2} \frac{d\theta}{\sqrt{1-m\sin^2\theta}} = \int_0^1 \frac{dt}{\sqrt{(1-mt^2)(1-t^2)}}\\ E(m) &= \int_0^{\pi/2} \sqrt{1-m\sin^2\theta} d\theta = \int_0^1 \sqrt{\frac{1-mt^2}{1-t^2}} dt \end{align} $$ We get
$$\verb/Volume/ = \frac{16 r^3}{3\sin\alpha}\left((2-m)E(m) - 2(1-m)K(m)\right)$$
As a sanity check, when $d \to 0$, $m \to 1^{-}$, we have
$$(1-m)K(m) \to 0\quad\text{ and }\quad (2-m)E(m) \to E(1) = 1$$ This leads to a familiar result for the volume of intersection when the axis intersect.
$$\verb/Volume/_{d = 0} = \frac{16r^3}{3\sin\alpha}$$