Solar system simulations and the Hohmann transfer orbit

import java.text.SimpleDateFormat;
import java.util.Date;
//========================================================================================
float eccentricity[] = {0,0.205,0.007,0.017,0.094,0.049,0.057,0.046,0.011};
float aphelion[] = {0.0,69.8,108.9,152.1,249.2,816.6,1514.5,3003.6,4545.7};
float inclination[] = {0.0,7.0,3.4,0.0,1.9,1.3,2.5,0.8,1.8};
float bodyRadius[] = {0.0,0.5,0.7,0.7,0.6,1.7,1.5,3,3};
float orbitPeriod[] = {0.0,126720.0,323568.0,525888.0,989280.0,6380640.0,15475680.0,44048160.0,86112000.0};
float epoch[]={0.0,13627665.75,13630579.0,13922899.58,14241140.2,18535221.46,25301781.93,20140822.57,74731252.68};

String alert = "Solar System Simulator by LGR";
String strCurrentTime = "";
String f1= "Press 'f'/'l'key To increase / decrease the speed of the revolution.";
String f2= "Press 'UP','DOWN','LEFT','RIGHT'key To adjust the camera angle.";
String f3= "Click on the mouse to turn off or turn on the Orbits.";
String f4= "Rotate the wheel of the mouse to zoom in or out.";
String camxy = "x/y of cam : ";
String introduce1 ="When simulating in real time, the speed of the simulations ";
String introduce2 ="was so slow that I tried to  accelerate the time of the simulations.";

float camx = 0, camy = 0, camz = 0, scale = 1.0;
long currentTime = 0,startTime;
int BColorR[] = {255,0,255,43,255,209,255,41,41};
int BColorG[] = {255,123,0,255,177,122,86,100,100};
int BColorB[] = {255,255,0,0,68,0,210,255,255};
int center = 0,timeRate = 0,fastForward = 0,zoom = 1; 
//========================================================================================
void setup() {
  size(832,624,P3D);
  stroke(255);
  camx=1.250;
  camy=-2.850;
}
//========================================================================================
void draw() {
  background(0, 0, 0); 
  timeChange();
  showLetter();
     
     translate(width/2, height/2, 0);
  
      scale(scale);
      rotateX(camx);
      rotateY(camy);
      rotateZ(camz);
  
  fill(255,255,255); 
  sphere(15);
   
   for(int planeti=1;planeti<9;planeti++) {
   
     pushMatrix();
    
     rotateY(radians(inclination[planeti]));
    
    if(zoom==1){ 
      Orbit(planeti);
    }
    Planet(planeti);
    popMatrix();
  }
}
//========================================================================================
void Planet(int j) {
        float timeDiff = currentTime - epoch[j];
        if(timeDiff<0) timeDiff-=orbitPeriod[j];        
        float i = ((2*PI)/orbitPeriod[j])*timeDiff;

        float a = aphelion[j];
        float e = eccentricity[j];
        float r = (a*(1-(e*e)))/(1-(e*cos(i)));
        float x = r*cos(i);
        float y = r*sin(i);
  
          pushMatrix();
          translate(x, y, 0);
          noStroke();          
          fill(BColorR[j],BColorG[j],BColorB[j]);
          sphere(bodyRadius[j]*4);
          stroke(255);
          popMatrix();
}
//========================================================================================
void Orbit(int k) {
    float circumference = 2*PI;
    float a = aphelion[k];
    float e = eccentricity[k];
    float prevx = -1;
    float prevy = -1;
    for(float theta=0.0;theta<circumference;theta+=0.01) {
      float r = (a*(1-(e*e)))/(1-(e*cos(theta)));
      float x = r*cos(theta);
      float y = r*sin(theta);
      if(prevx == -1 && prevy == -1) {
        prevx = x;
        prevy = y;
      } else {
        line(prevx,prevy,x,y);
        prevx = x;
        prevy = y;
      }
    }
}
//========================================================================================
void showLetter() {
  
  textSize(20);
  fill(255,255,255);
  text(strCurrentTime, width/2-100, 20);
  text(camxy,20,510); 
  text(camx,150,510); 
  text(camy,220,510); 
  text(alert,20,530); 
  text(f1,20,550); 
  text(f2,20,570); 
  text(f3,20,590); 
  text(f4,20,610); 
  
  textSize(15);
  fill(255,255,255);
  text(introduce1, width/2-200, 50);
  text(introduce2, width/2-200, 63);
} 
//========================================================================================
void timeChange() { 
  println("time : "+timeRate);
  if(timeRate==0) { 
    if(fastForward==0) { 
      Date d = new Date(); 
      long x = d.getTime()/1000; 
      currentTime = x/60;
      fastForward = 1;
      timeRate = 1;
    } 
  }
  
else if(timeRate>0) {
      currentTime+=pow(2,timeRate);
  } 
  long oriCurrentTime = currentTime * 60 * 1000;
  println(oriCurrentTime);
  SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
  Date d2 = new Date(oriCurrentTime);
  String dTime = formatter.format(d2);
  strCurrentTime = dTime;
  println(strCurrentTime);
}
//========================================================================================
void mouseWheel(MouseEvent event) {
  float e = event.getCount();
  if (e<0) scale-=0.025;
  else scale+=0.025;
}
//========================================================================================
void mouseClicked() {
if(zoom==1){
  zoom = 0;
}
    else{
      zoom = 1;
    }
}
//========================================================================================
void keyPressed() { 


  if (key == 'F' || key == 'f') {
    if(timeRate<15){ 
      timeRate++; 
      } 
} 
else if (key == 'l' || key == 'L') { 
  if(timeRate>1) {
      timeRate--;
     }
  }
  
  else if (key == CODED) {
    if (keyCode == UP){ 
      camx+=0.05;
    }
    else if (keyCode == DOWN){
      camx-=0.05;
    }
    else if (keyCode == LEFT){
      camy-=0.05;
    }
    else if (keyCode == RIGHT){ 
      camy+=0.05;
    }

  }

}
//========================================================================================

This is the code for the solar system simulation. :grin:
I want to apply the Hohmann transfer orbit to this simulation. :sweat_smile:
(I’d like to get a destination input,
and then visualize the Hohmann transfer orbit from Earth to destination.)
But I can’t get the hang of it. :sob: :sob:
Can you help me?

(Sites that show my goals : https://transfercalculator.com/calculator/index.html
:raised_back_of_hand:

1 Like

See also

1 Like