We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Curvaceous Attraction
Page Index Toggle Pages: 1
Curvaceous Attraction (Read 930 times)
Curvaceous Attraction
Feb 13th, 2006, 5:38pm
 
I'm looking to create a gravitation and replusion effect on a grid of particles. I take one particle and then itterate through the other particles effecting movement towards or away from that particle. (I'm basically trying to create a more predictable, more controllable version of the Kohonen neural net.)

I tried delta/n, where delta is the distance between the particles and n is some arbitrary value to interpolate the movement. All that did was scale the grid.

I tried sq(delta) and that gave me a bit of a curve but it didn't go far enough towards ignoring the edge of the grid.

Can anybody suggest some graph curves that might give me a reasonable pull around the particle calling the gravity function, but ignore the ones further away?
Re: Curvaceous Attraction
Reply #1 - Feb 14th, 2006, 11:56am
 
Well the proper physics formula is f=(G*Mass1*Mass2)/sq(dist)

Which you can simplify by saying that all your particles are the same weight, and that weight is such that the formula ends up being force = 1/sq(dist)

Depending on how fast you want the force to drop off, you can multiply dist by some factor. e.g. you coudl say 1 pixel is actually 2.3 "units" of distance or somesuch, which should increase the falloff.
Re: Curvaceous Attraction
Reply #2 - Feb 14th, 2006, 4:24pm
 
I applied a gravity formula to the net. Seems to work okay. Thanks for the tip - I used an old applet of mine which borrowed from a lingo applet somewhere...

http://www.robotacid.com/misc/nailGun

I've set it to kill the energy of the particles after letting go of one because I want a warped grid, not a cluster-****.

However, multiplying the square of the distance doesn't seem to effect the fall off, only the amount of energy in the system. I'm happy to use gravity, the idea of energy remaining in the particles is a nice idea, but I'd still like more control over that curve of influence.

I'm going to put a graph and gui together to trouble shoot this, but if anyone can offer any ideas I'd be happy to hear them.

Plus, does anyone know if the physics library would be appropriate for this?
Re: Curvaceous Attraction
Reply #3 - Feb 14th, 2006, 10:24pm
 
I meant if you multiply dist by a factor before squaring it, that should increase the falloff.

e.g. instead of

Code:

|\
| \
| \
| `.
| `-.
| . `'-,_
+-------------

You'll get
Code:

||
||
|\
| \
| .
| `',______
+------------


(apologies for dodgy ascii art..)
Re: Curvaceous Attraction
Reply #4 - Feb 15th, 2006, 5:08am
 
st33d, what do you plan on doing with your neural network? It sounds like an interesting project... I've just started learning about these things, but I'm having a hard time picturing a neat/useful/clever implementation.

OT: JohnG, your ASCII skillz are impressive. How long did those take you?
Re: Curvaceous Attraction
Reply #5 - Feb 15th, 2006, 4:50pm
 
Sorry John, observe the following code:
Code:

float mul = 1.0;
void setup(){
 size(400,400);
 background(255);
}
void draw(){
 stroke(0);
 beginShape(LINE_STRIP);
 for(int i = 0; i < 400; i++){
   vertex(i, sq(i) * mul);
 }
 endShape();
 stroke(255,0,0);
 beginShape(LINE_STRIP);
 for(int i = 0; i < 400; i++){
   vertex(i, sq(i * mul));
 }
 endShape();
}
void keyPressed(){
 switch(key){
   case '+':
   case '=':
   mul *= 1.5;
   break;
   case '-':
   case '_':
   mul /= 1.5;
   break;
 }
}

Although the change in the curve is achieved faster by multiplication before squaring - it's still exactly the same curve. Why is this It's because of multiplication, you're putting numbers in a different order but they still follow the same pattern.

I think what I'm aiming for is to increase the sphere of influence of the gravity. For that, I don't need to just scale distance by multiplying it or dividing it - I need to bend it. Curved space (like a Stanislav Lem novel). The equation is just floating out of my reach and I can't seem to put it together - something to do with a curve within that curve - hrmm....

This project is a continuation of this.

Ah hah

grav = (m1 * m2) / pow(distance, curvature);

It's the power to which distance is multiplied that affects the shape of the curve. A low power (1.1) gives a flatter, more linear curve, a high power (5+) gives you more of a funnel. Top dorrar!
Re: Curvaceous Attraction
Reply #6 - Feb 18th, 2006, 9:20pm
 
johng, your ascii art gets my "favorite post of the year" award (if i had one). that's hilarious.
Page Index Toggle Pages: 1