Need help with Cylinder calculations for a game.

25 Views Asked by At

I am working on a game where the organisms will be represented by cylinders, and despite my attempts, I'm unable to determine the proper geometric calculations.

$v = (\pi)r^2h$

Easy enough! Problem is, that I have to calculate $r$ and $h$, given $v$ and a ratio of $h$-to-$r$.

Here's the context: the organism's volume is equal to their health $* x$, where $x$ is a constant. Let's say health $= H$, then: $v = H * x$, so:

$H * x = (\pi)r^2h$

Also, each organism will have a "height-to-radius" (call it $q$) property, i.e. $h = r * q$.

Plugging that in, I get: $H * x = (\pi) r^2 (r * q)$

Now, given $H$, $x$, and $q$, I need two algorithms - one solving for $r$ and one for $h$.

I'm sure this is utterly trivial for many of you, but I'm a bit rusty myself. Thanks in advance!

I hope I gave you enough info, please let me know if I need to clarify anything.

1

There are 1 best solutions below

1
On BEST ANSWER

As you note, you have $Hx = \pi r^3 q$. So we have $$r = \left(\frac{Hx}{\pi q }\right)^{\frac{1}{3}}$$

We can then find $h$ by multiplying this by $q$. So $h = rq$, after solving for $r$.