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 › strange astronomical phenomena
Page Index Toggle Pages: 1
strange astronomical phenomena (Read 1937 times)
strange astronomical phenomena
Dec 31st, 2009, 7:09am
 
Im trying to make a sketch to simulate the movement of a planet around the sun. I use as parameters the initial position, the initial speed, the gravity constant, an the angle of the initial speed.

Usually the trajectory is an ellipse, as it should, and the planet dont go away from the ellipse. I think that the sketch is ok, and the elipse is only the case of stable orbits. ¿Do you think the strange case of the parameters chosen below is due to any error in the code?

Code:
//parámeters
float g=20000;//gravity constant
float din=200;//Initial distance to the sun
float vin=5;//Initial speed
float ang=-PI/10;//angle respect perpendicular to the distance to the sun. downside is positive
//variables
Ball planet;
float X;
float Y;
float r2;

void setup(){
 size (700,700);
 background(0);
 smooth();
 planet =new Ball(width/2,height/2-din,1,vin*cos(ang),vin*sin(ang),10);
 frameRate(60);
}
void draw(){
 background(0);
 ellipse (width/2,height/2,30,30);
 planet.ecuation();
 planet.move();
 planet.paint();
}
class Ball {
 float radio;
 float x,y;
 int id;
 float vx,vy;
 Ball[] resto;
 Ball(float xin,float yin, int idin,float vxin, float vyin,float radin){
   x=xin;
   y=yin;
   id=idin;
   vx=vxin;
   vy=vyin;
   radio=radin;
 
 }
 void ecuation(){
   X=x-width/2;
   Y=y-height/2;
   r2=X*X+Y*Y;
   if (r2>0){
vx-=g*X/(sqrt(r2)*r2);
vy-=g*Y/(sqrt(r2)*r2);
   }
 }
 void move(){
   x+=vx;
   y+=vy;
 }
 void paint(){
   ellipse (x,y,radio,radio);
 }
}


This for example is stable:

Code:
float g=10000;//gravity constant
float din=300;//Initial distance to the sun
float vin=5;//Initial speed
float ang=0;//angle respect perpendicular to the distance to the sun. downside is positive


But try to increase the g value, it starts to be insestable, and I think it shouldn't and in some cases of stronger gravity it expel the earth away!
Re: strange astronomical phenomena
Reply #1 - Dec 31st, 2009, 7:17am
 
where did you get these values from? i tried out different values and got some results that stay in place or rotates slowly arround the sun.

Code:
//parámeters
float g=8100;//gravity constant
float din=200;//Initial distance to the sun
float vin=4;//Initial speed
float ang=-PI/10;//angle respect perpendicular to the distance to the sun. downside is positive
//variables
Ball planet;
float X;
float Y;
float r2;

void setup(){
size (700,700);
background(0);
smooth();
planet =new Ball(width/2,height/2-din,1,vin*cos(ang),vin*sin(ang),10);
frameRate(60);
}
void draw(){
noStroke();
fill(0,3);
rect(0,0,width,height);
fill(255);
ellipse (width/2,height/2,30,30);
planet.ecuation();
planet.move();
planet.paint();
}
class Ball {
float radio;
float x,y;
int id;
float vx,vy;
Ball[] resto;
Ball(float xin,float yin, int idin,float vxin, float vyin,float radin){
x=xin;
y=yin;
id=idin;
vx=vxin;
vy=vyin;
radio=radin;

}
void ecuation(){
X=x-width/2;
Y=y-height/2;
r2=X*X+Y*Y;
if (r2>0){
vx-=g*X/(sqrt(r2)*r2);
vy-=g*Y/(sqrt(r2)*r2);
}
}
void move(){
x+=vx;
y+=vy;
}
void paint(){
ellipse (x,y,radio,radio);
}
}
Re: strange astronomical phenomena
Reply #2 - Dec 31st, 2009, 7:27am
 
The parameters values are not taken from anywhere, I´ve been changing them till I found an stable orbit, and then start to change them again to see what happened.

I simply applied Newton formula

Of course there are stable parameters and inestable ones, but I think there are nonsense results. For example that of increase the gravity and a stable orbit transform in an insestable one, or that the ellipse axes rotate around.
Re: strange astronomical phenomena
Reply #3 - Dec 31st, 2009, 7:58am
 
hmm so what was the actual question?
Re: strange astronomical phenomena
Reply #4 - Dec 31st, 2009, 8:16am
 
The question are that according to my limited phisics knowledge, the trajectory of an object submited to gravity atraccion to other, should be an ellipse or an hyperbola.

My sketch is suposed to simulate this movement, and I think is ok, but the movement of my planet are not what it should be. There has to be an error in my code or an explanation for theese cases.
Re: strange astronomical phenomena
Reply #5 - Jan 1st, 2010, 3:46am
 
Now I see what is the problem. I dont know how I didnt see before. The question is that te movement the planet do in the sketch is a poligonal one, each frame is a line, so is diferent from the real movement of a planet. Depending on the parameters, the diference can be big.
Re: strange astronomical phenomena
Reply #6 - Jan 2nd, 2010, 6:09am
 
just found this sketch : http://www.openprocessing.org/visuals/?visualID=5152
Re: strange astronomical phenomena
Reply #7 - Jan 3rd, 2010, 1:14pm
 
I also did something similar:

Much simpler, but everything seemed to work as I expected:

http://www.openprocessing.org/visuals/?visualID=6407
Re: strange astronomical phenomena
Reply #8 - Jan 4th, 2010, 4:24pm
 
To have a circular orbit, you need the distance and speed to form a special relations, plus the initial velocity has to be perpendicular to the radial line of the planet leading to the sun to begin with. If you have radius R multiply velocity squared V^2 equal to MG, then you're guaranteed to have a circular orbit.
R*V^2=MG
Here M is the mass of the sun and G is gravitational constant 6.67*10^-11.

I don't know where your numbers are from, possibly from your imagination of a different solar system but still the above condition has to be met to produce circular orbits, which is what you see for our solar system's planets.

I didn't try your program yet but if you have an ellipse that changes it orientation of major axis, there's a problem. It shouldn't, according to physics. Once set, the planets should not be changing their orbits.

I suggest you use the right constants say for planet and sun't mass and distance. You may scale the distance within your display.
Re: strange astronomical phenomena
Reply #9 - Jan 4th, 2010, 7:29pm
 
Here's my change from your original code:

1)

 for (int i=0; i<10;i++)
 {
   planet.move();
   planet.ecuation();
 }
 planet.paint();

2)
   vx-=X/sqrt(r2)*g/r2/60;
   vy-=Y/sqrt(r2)*g/r2/60;

3)
   x+=vx/60;
   y+=vy/60;

This way the planet is no longer changing its orbits noticably.
My constants. I changed a bit.

float g=200000;//gravity constant
float din=200;//Initial distance to the sun
float vin=20;//Initial speed
float ang=-PI/10;//angle respect perpendicular to the distance to the sun. downside is positive

The main problem was the accuracy of your calculation. I reduced the intervals and that tends to help quite a bit.
Page Index Toggle Pages: 1