I want to know if a 3D spherocylinder/capsule, that looks like this:
Can be approximated by a known equation. I want a shape with volume.
Edit: In my program I already have a cylinder with two hemispheres on the ends to represent the capsule, I wonder if there is a better idea.
$\endgroup$ 23 Answers
$\begingroup$Assume the upper/lower caps are hemispheres centered at $(0,0,\pm a)$ with radius $r$ and the middle portion is a circular cylinder, the equation of the capsule is
$$x^2 + y^2 + \frac14\left(|z-a|+|z+a| - 2a\right)^2 = r^2$$
I will encourage you to prove this yourself, it is sort of fun.
$\endgroup$ $\begingroup$The top half sphere can be represented by the equation $$x^2 + y^2 + (z-h)^2 = a^2$$
where $z\geq h$.
The bottom can be represented as $x^2+y^2+z^2=a^2$ where $z\leq 0$
The cylinder in between can be $$x^2+y^2=a^2$$ where $0\leq z\leq h$
Put these three together and you get an equation $F(x,y,z)=a^2$ where $F$ is a continuous function (defined using three equations).
$\endgroup$ $\begingroup$If $l$ is the 'length' of the cylindrical section of the capsule and $r$ is the 'radius' of the two half spheres then the volume of the capsule would be given by $$\pi r^{2} \left( \frac{4}{3}r+l \right)$$
$\endgroup$