Trying to create a inverse quare algorithm for expanding sphere

90 Views Asked by At

So, in a piece of software I am writing (this isn't homework), I want to have a sphere expand relative to time.

I want it to expand quickly from start with the expansion slowing over time.

I.e, the rate of expansion being inversely proportion to time.

I have the centre point of the sphere and a vector to a point on the sphere (radius) and obviously time.

My first try

$p_1 =$ position on the sphere

$p_2 =$ new position of the point on the sphere

$c_1 =$ center of the sphere

$t =$ time

$v_1 =$ vector from $c_1$ to $p_1$

$v_1 = p_1 - c_1$

$p_2 = p_1 + \frac{v_1}{t^2} $

This gives me the exact opposite of what I want. It starts big and shrinks very quickly to start off and then slows.

What should I have done instead?

3

There are 3 best solutions below

4
On BEST ANSWER

I think you are confusing a function and its derivative. You say,

I want it to expand quickly to start with with the expansion slowing over time. i.e, an inverse square.

So if $r(t)$ is the radius of the sphere, this sentence means you want $r'(t) = \frac{1}{t^2}$.

But the way you programmed it is if $r(t)=\frac{1}{t^2}+\text{initial radius}$.

So, if you really do want the radius to grow like the inverse square, you can solve $r'(t) = \frac{1}{t^2}$ to get $r(t) = C - \frac{1}{t}$.

To match your initial radius $r_0$ and your eventual radius $r_{\infty}$, you would have to introduce another parameter. Perhaps $r'(t) = \frac{k}{t^2}$ will work. The initial value problem $$ r'(t) = \frac{k}{t^2}\qquad r(1) = r_0 \qquad \lim_{t\to\infty} r(t) = r_\infty $$ has solution $$ r(t) = r_\infty - \frac{r_\infty-r_0}{t} $$

Now this may not be the best thing for you. If so, you might want to think about other functions that start with quick growth and level off. For instance, one model of heat transfer works with the equation $r'(t) = k(r_\infty - r(t))$. So the closer $r(t)$ is to $r_\infty$, the less $r(t)$ changes. The solution to that would be $$ r(t) = r_\infty - (-r_\infty - r_0)e^{-kt} $$ for any positive $k$. The larger the $k$, the larger $r'(0)$ will be, that is, the larger the expansion at the start.

2
On

You should define what you mean by "inverse square". This is by no means a standard concept.

In you formula it means that the radius of the sphere is divided by the square of time, which indeed cannot mean anything else than that the sphere shrinks.

You need a function that increases with time, but ever more slowly in the sense that its derivative is decreasing.

There are many such functions to choose from, each with their own properties. For instance, the following function will let your sphere expand forever without ever doubling in size:

(2t+1)/(t+1)

The function log t will let your sphere expand indefinitely, but very slowly.

0
On

I gather that you want the speed at which your sphere's radius expands to be proportional to $1/t^2$.

The speed at which the radius expands is the derivative of the radius as a function of time. So if you already knew the radius and wanted to know its speed of expansion, you would differentiate that function.

But I think you want to solve the problem in the opposite direction. You have the speed and you want the actual radius. To do this, you integrate the speed.

The integral of $1/t^2$ is $$\int \frac{1}{t^2}\; dt = -\frac{1}{t} + C$$ where the $C$ can be any constant value that works for you. Whatever value you pick, that is the limit of how far this sphere will grow. That is, a growth rate proportional to $1/t^2$ will reach only some certain finite distance from the center of the sphere, no matter how long you wait.

I have a hunch that what you actually wanted was for the growth to be proportional to $1/r^2$, that is, inverse square of the radius. That is,

$$ \frac{dr}{dt} = k \frac{1}{r^2} .$$

The solution to this is $\frac13 r^3 = kt + C,$ or $r = \sqrt[3]{3kt + 3C}$. You may want to just set $C = 0$; since the constant $k$ is arbitrary, we can just replace $\sqrt[3]{3k}$ by some other constant $r_1$ of your choosing, and then the formula for radius is

$$ r = r_1 \sqrt[3]{t} $$

and the formula for a point on the sphere at time $t$ is

$$ p_2 = c_1 + v_1 \sqrt[3]{t}. $$