FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Programs
(Moderators: fry, REAS)
   basic particle physics
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: basic particle physics  (Read 1377 times)
st33d

WWW Email
basic particle physics
« on: Jan 12th, 2005, 4:19pm »

I've been wrestling with this for hours now and I really need some breakfast. So I turn to the forum.
 
I'm trying to learn how to do basic orbiting particles (planetary style). Most of the formulae out there doesn't seem to address making an applet so I've come out with a very confused idea of how to do it.
 
I've guessed that I have a gravitational force acting on the particle and a centripetal force. One pulls it to the center and one throws it around the center. But my particles converge on "earth" and the shoot off. Very pretty but I still don't understand how to get a nice realistic particle orbit.
 
Would someone mind setting me straight?
 
Code:

float G = 6.7 * pow(10, -11);
particle [] p = new particle [1000];
void setup(){
for(int i = 0; i<1000; i++){
p[i] = new particle(random(400)-200,random(400)-200,10);
}
size (400,400);
stroke(255);
}
void loop(){
background (0);
translate(200,200);
for(int i = 0; i<1000; i++){
p[i].gmove();
p[i].cmove();
point(p[i].x,p[i].y);
}
point (0,0);
}
class particle{
//m=mass,gva=gravity acceleration, gv=gravity velocity
//ga=angle to earth, cv=centripetal velocity
float x,y,m,ga,gv,cv;
particle (float x, float y, float m){
this.x = x;
this.y = y;
this.m = m;
gv = 1.0;
cv = 1.0;
}
//centrepetal motion
void cmove(){
float angle = atan2(y,x)+(PI/2);
cv += sq(cv)/rad(x,y);
x += cos(angle)*(cv);
y += sin(angle)*(cv);
}
//gravity motion
void gmove(){
ga = atan2(-y,-x);
float gva = (G * m) / sq(rad(x,y));
gv +=gva;
x += cos(ga)*gv;
y += sin(ga)*gv;
}
}
float rad (float x, float y){
return sqrt(sq(200-x)+sq(200-y));
}
 

I could murder a pint.
Mythmon


Re: basic particle physics
« Reply #1 on: Jan 13th, 2005, 8:00pm »

try and provide a initial momentum to the particle, perpindicular to the direction the the gravity is coming from
 
st33d

WWW Email
Re: basic particle physics
« Reply #2 on: Jan 19th, 2005, 4:02pm »

Yeah, basically I confused force equations with velocity equations. Got a nice improvement by trying to balance the centrifugal and gravitational force.
 
http://www.st33d.net/processing/gold.html
 
Kinda looks like cigarette smoke after the particles begin to get bunched up.
 
My centrifugal acceleration seems to be slowly counteracting the gravity still. It would be nice if I could figure out the balance.
 

I could murder a pint.
eskimoblood

222550793222550793 WWW
Re: basic particle physics
« Reply #3 on: Jan 20th, 2005, 9:19am »

Hi build these applet http://eskimoblood.de/applet.php?i=16 with a gravity formula from here http://www.jmckell.com/generalgravity.html
 
st33d

WWW Email
Re: basic particle physics
« Reply #4 on: Jan 26th, 2005, 12:56pm »

Magic. I can understand this. Thanks.
 
Figured out how to balance the centrifugal and gravity (just use the same value - duh). Looked boring though, it's some how more interesting when the particles get catapulted. Will try introducing proper gravity now.
 

I could murder a pint.
Fish-face

308232952308232952thedemonsheep WWW Email
Re: basic particle physics
« Reply #5 on: Feb 11th, 2005, 12:26am »

Yeah, centrifugal force doesn't really exist - it's just the momentum of the particles tends to make them go in a straight line - a straight line will take them away from the point.
 

--

The C@ S@ on the M@
=Fish-Face=
~#Chris#~
Pages: 1 

« Previous topic | Next topic »