I am looking for a mathematical function that produces something similar to a bell curve ( think). I am very much out of my depth here. I think the Gaussian function might be what I need, but I don't know how to apply it correctly for my purposes.
I will be using the function to animate over a series of objects:

I want to simulate the appearance of acceleration and deceleration of this animation by offsetting each object closer to the previous one, until the midway point, after which the offset increases back to the original value:

Once implemented, I want the function to accept my start and end points on the x-axis, and the number of objects that need to be accommodated. It should then return a series of values that will be the x origin for each object.
For example:
Start: 0 End: 100 Objects: 20
Flat distribution: 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95
Required results: 0, 10, 19, 27, 34, 40, 44, 45, 46, 47, 48, 49, 50, 51, 55, 60, 66, 73, 81, 90
Some control over the profile of the curve would also be nice - for example, my estimated values above are quite a 'flat' bell (items 7-14 have the same offset).
Consider the following cubic polynomial:
f(x,a) = 4ax^3 - 6ax^2 + 2ax + x
evaluated over the domain x in [0:1] with a held constant and chosen from the interval `[0:1]'.
This will generate plot that starts at zero and ends at one. If a==0, you get a straight line. If a==1, you get a deep curve. For a somewhere in between, you get something in between.
Once you've picked a good value for a, you simply evaluate at however many points you want between 0 and 1. Then you scale the values to fit the range that you want.
This screenshot of a spreadsheet gives two examples. Columns A and F hold the value a, columns B and G hold values of x (if you wanted to use the exact values from your flat distribution, you could change every usage of x to be x/100). Columns C and H hold the outcome of f(x,a). Columns D and I hold f(x,a)*100.

Here is a Java implementation for generating a normal deviate:
/** generation of a Gaussian deviates (variants) by the ratio of uniform method */
final public static double generateNormalDeviate( final double mean, final double std_deviation ){
double u, v, x, y, q;
do {
u = random.nextDouble();
v = 1.7156 * ( random.nextDouble() - 0.5 );
x = u - 0.449871;
y = (v < 0 ? v * -1 : v) + 0.386595;
q = x*x + y * (0.19600 * y - 0.25472 * x);
} while( q > 0.27597 &&
(q > 0.27846 || v*v > -4d * Math.log(u) * u*u));
return mean + std_deviation * v / u;
}
See Numeric Recipes by Press for more information and a C version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With