Finding radius of capsule defined by total volume and height of inner cylinder

596 Views Asked by At

I have a capsule shape that is comprised of a cylinder and two half-sphere end caps, and I want to dynamically resize it. As I stretch the capsule by increasing/decreasing the height of the cylinder, the total volume should remain constant by adjusting the radius. This means, I need to define the radius in terms of height and volume.

My starting equation looks like this:

Total volume = Sphere volume + Cylinder volume

$$W_v = \frac{4}{3}\pi r^3 + h \pi r^2$$

Given this equation, I don't know how to solve for radius (r).

Am I approaching this from the right direction? It seems that, when it comes to weird circle problems, or pi in general, it often comes down to integrating/derivating(??) a solution. I know basic Calc, but I can't see how to use it here. Also, since this is for a computer game and needs to run in realtime, I'm really hoping the solution isn't too ... problematic. ;) I know I can fudge an okay representation, but if the real solution is elegant, I'd rather have that. Plus after circling poor attempts to factor and simplify for a while, I'm genuinely curious to know what the answer is now.

2

There are 2 best solutions below

7
On BEST ANSWER

Non-Complex Solution

The math involved for solving for $r$ goes a bit beyond basic calculus, I can spare you the long explanations and tell you that $V = \frac{4}{3}\pi r^3+h\pi r^2$ is solved for $r$ as:

$$\frac{1}{4} \left(-\frac{\sqrt[3]{4 \sqrt{3} \sqrt{12 V^2-\pi h^3 V}+\pi h^3-24 V}}{\sqrt[3]{\pi }}-\frac{\sqrt[3]{\pi } h^2}{\sqrt[3]{4 \sqrt{3} \sqrt{12 V^2-\pi h^3 V}+\pi h^3-24 V}}-h\right)$$

That's the only solution not involving complex numbers.


Complex Soltution

The solution(s) involving complex numbers are:

$$r = \frac{\left(1 \mp i \sqrt{3}\right) \sqrt[3]{4 \sqrt{3} \sqrt{12 V^2-\pi h^3 V}+\pi h^3-24 V}}{8 \sqrt[3]{\pi }}+\frac{\sqrt[3]{\pi } \left(1 \pm i \sqrt{3}\right) h^2}{8 \sqrt[3]{4 \sqrt{3} \sqrt{12 V^2-\pi h^3 V}+\pi h^3-24 V}}-\frac{h}{4}$$

Note that this is two separate solutions due to the flipping of the signs. Also notice the formatting of the "minus-plus sign" and the "plus-minus sign". This means that when $\mp$ is negative, $\pm$ is positive. When $\mp$ is positive, $\pm$ is negative.


Graphical Representation of the Functions

I thought it'd be best to represent the data graphically.

The three functions are labeled in these representations as:

  • $f(h,V) = \frac{1}{4} \left(-\frac{\sqrt[3]{4 \sqrt{3} \sqrt{12 V^2-\pi h^3 V}+\pi h^3-24 V}}{\sqrt[3]{\pi }}-\frac{\sqrt[3]{\pi } h^2}{\sqrt[3]{4 \sqrt{3} \sqrt{12 V^2-\pi h^3 V}+\pi h^3-24 V}}-h\right)$
  • $f\text{complex1}(h,V) = \frac{\left(1-i \sqrt{3}\right) \sqrt[3]{4 \sqrt{3} \sqrt{12 V^2-\pi h^3 V}+\pi h^3-24 V}}{8 \sqrt[3]{\pi }}+\frac{\left(1+i \sqrt{3}\right) \sqrt[3]{\pi } h^2}{8 \sqrt[3]{4 \sqrt{3} \sqrt{12 V^2-\pi h^3 V}+\pi h^3-24 V}}-\frac{h}{4}$
  • $f\text{complex2}(h,V) = \frac{\left(1+i \sqrt{3}\right) \sqrt[3]{4 \sqrt{3} \sqrt{12 V^2-\pi h^3 V}+\pi h^3-24 V}}{8 \sqrt[3]{\pi }}+\frac{\left(1-i \sqrt{3}\right) \sqrt[3]{\pi } h^2}{8 \sqrt[3]{4 \sqrt{3} \sqrt{12 V^2-\pi h^3 V}+\pi h^3-24 V}}-\frac{h}{4}$

All three functions, transposed onto a single $3D$ graph looks like so:

All 3 functions on graph

To further represent the data, we can visualize the functions transforming when we put them into the form $f\left(x \cdot h, \; y \cdot V\right)$:

data gif

Note that in this gif, $h$ and $V$ are both running from $-10$ to $10$.

1
On

Based on what I understood, you are asking what adjustments must be made to the the radii of the half spheres and the cylinder in order to maintain the volume while changing the height of the cylinder. In effect, you want: $$\pi (\alpha +h) (r-\epsilon )^2+\frac{4}{3} \pi (r-\epsilon )^3=V_T\tag{1}$$ Where $r$ is the radius of the cylinder and the sphere, $\epsilon$ is the change in the radius while changing height $h$ by adding $\alpha$. So we want to solve for $\epsilon$ here, which gives us one real answer as: $$\epsilon \to \frac{-9 \pi ^{4/3} \sqrt[3]{-\pi \alpha ^3-\pi h^3-3 \pi \alpha h^2-3 \pi \alpha ^2 h+4 \sqrt{3} \sqrt{V_T \left(-\left(\pi (\alpha +h)^3-12 V_T\right)\right)}+24 V_T}-\frac{9 \pi ^2 (\alpha +h)^2}{\sqrt[3]{-\pi \alpha ^3-\pi h^3-3 \pi \alpha h^2-3 \pi \alpha ^2 h+4 \sqrt{3} \sqrt{V_T \left(-\left(\pi (\alpha +h)^3-12 V_T\right)\right)}+24 V_T}}+9 \pi ^{5/3} (\alpha +h+4 r)}{36 \pi ^{5/3}}\tag{2}$$


To check, suppose originally, we have $$h\to 1\,\,r\to 3\,\,\epsilon \to 0\,\,\alpha \to 0$$ Which gives a total volume from $(1)$ of $$V_T=45\pi$$ Now we want to change the height by $2$, thus $\alpha=2$, now we need to solve $(2)$ using: $$\{\alpha \to 2,h\to 1,r\to 3,V\to 45 \pi\}$$ And we get: $$\epsilon \to \frac{-9 \pi ^{4/3} \sqrt[3]{108 \pi \sqrt{95}+1053 \pi }+135 \pi ^{5/3}-\frac{81 \pi ^2}{\sqrt[3]{108 \pi \sqrt{95}+1053 \pi }}}{36 \pi ^{5/3}}$$ And now substitute everything into $(1)$, we get back $V_T=45\pi$