Otóż jest to symulator orbitowania, zrobiłem już losową prędkość orbitalną, ale chciałem aby planety poruszały sie według 3 prawa keplera. Problem jest taki że ich prędkość powinna być oparta na masie ciała "ojczystego" (np dla księżyca byłaby to ziemia), a w moim programie opiera się o masie tego ciała orbitującego. Nie mam pojęcia jak to zmienić.
class Planet{
Planet[] planets;
float radius;
float angle;
float distance;
float ItIsSun;
float mass;
float velocity;
Planet(float r,float d,float o){
distance=d;
radius=r;
ItIsSun=o;
mass = ((radius*radius*radius*(4.0/3.0))*density);
angle=random(TWO_PI);
}
void spawnMoons(int total){
planets = new Planet[total];
for(int i =0;i< planets.length;i++){
float ra=radius*random(0.2,0.7);
float di=random(50,300);
float oi = 1.0;
planets[i] = new Planet(ra,di,oi);
}
}
void orbit(){
if(distance!=0){
velocity=((sqrt((mass*G)/distance)/distance)*220)*ItIsSun; //ItIsSun :: only sun has value 0
angle+=velocity*0.001;
}
if(planets != null){
for(int i =0;i<planets.length;i++){
planets[i].orbit();
}
}
}
void show(){
pushMatrix();
rotate(angle);
translate(distance,0);
fill(135);
ellipse(0,0,radius,radius);
if(planets != null){
for(int i =0;i< planets.length;i++){
planets[i].show();
}
}
popMatrix();
}
}