Active Processing program to simulate a planet orbiting around a sun

Am trying to write a code to make my planet increase and decrease with respect to PI/2 and 3*PI/2 as it orbits round the sun please any tips

What have you got so far?

Seriously. Post your code.

Without knowing what you already have working, we are at a total loss as to how to help you.

Are you trying to increase the radius of the planets? Are you trying to have elliptical orbits? I have no idea what you have already.

Post your code. Tell us what works, and what doesn’t.

Orbital mechanics are great fun!

I’m not sure about your reference to PI / 2 and 3 * PI / 2. How does this relate to orbits?

Here’s a quick brain dump of things you should be aware of:

  • 2-body orbital motion is elliptical with the parent body at one of the foci of the ellipse.
  • A body orbiting another obeys Kepler’s Laws of Planetary Motion.
  • Orbits are frequently parameterized based on the following:
    • The angle between some reference direction and the “ascending node” which is the point at which the orbit crosses from below to above the “celestial plane” which is the plane that you think of as “level”
    • The angle of inclination, which is how tilted the orbit is relative to the “celestial plane”
    • The angle of periapse, which is the angle in the plane of the orbit between the ascending node and the point where the satellite is closest to it’s parent
    • The eccentricity, which is how elongated the orbit is (0 is circular, 1 is parabolic, in between 0 and 1 is elliptical, > 1 is hyperbolic)
    • The semi major axis (which is half the long diameter of the ellipse, although the meaning for hyperbolic orbits is different)
  • These are called “orbital elements”.
  • The position of a satellite within it’s orbit is denoted by it’s “True Anomaly” which is the angle between the point of periapsis as the satellites current position.
  • The True Anomaly varies non-linearly because a satellite moves quickly when it is close to it’s parent and more slowly when it is far away.
  • However True Anomaly can be related to the “Mean Anomaly”, which basically denotes what fraction it’s orbit a satellite has progressed through in terms of an angle, via Kepler’s Equation.
  • Solving Kepler’s equation to go from Mean Anomaly to True Anomaly is a bit complicated because it doesn’t have a simple algebraic solution so you wind up using either an approximation or iteration (see Newton’s Method).

I have a sketch that demonstrates some of these principles, however, I must apologize because it is implemented in p5.js not processing, and it is incomplete and uncommented: Orbit Diagram - OpenProcessing

2 Likes

Hey man i was able to figure it out thanks

1 Like

Hello can you help me with this same question

Hello can I get help with the same question

THE SAME REPLY APPLIES TO YOU.

What have you got so far?

Seriously. Post your code.

Without knowing what you already have working, we are at a total loss as to how to help you.

Are you trying to increase the radius of the planets? Are you trying to have elliptical orbits? I have no idea what you have already.

Post your code. Tell us what works, and what doesn’t.

final int SUN_DIAM = 50;
final int ORBIT_X = 150;
final int ORBIT_Y = 35;
final float SPEED = 0.03;
float angle = 0;
float planetDiam = 25;
float xPos, yPos;

void setup () {
size(500, 500);
}

void draw () {
background(0);
fill(255, 255, 0);
circle(width/2, height/2, SUN_DIAM);

xPos = ORBIT_X * cos(angle) + width/2;
yPos = ORBIT_Y * sin(angle) + height/2;

fill(120);
circle(xPos, yPos, planetDiam);

angle = angle + SPEED;
planetDiam = 10 * cos(angle) + 15;
}

this is my code so far

I want to make the diameter of the planet change, depending on angle using a sin or cos function. Thank you !

This makes the diameter of your planet change, depending on the angle, using a cos() function. You have what you want already. I have no idea what more you want.

1 Like

@MacJ ,

You already have a topic on this here and tagged as homework:
Scale using cos/sin

Our forum:
https://discourse.processing.org/faq#keep-tidy

Asks that you:

Don’t cross-post the same thing in multiple topics

1 Like

Hello,

An example:

void setup() 
  {
  size(300, 300);
  }

void draw() 
  {
  background(0);
  
  // This advances every frame by TWO_PI/360
  float angle = frameCount*TAU/360; //TAU = TWO_PI radians
  
  //Useful:
  println(frameCount, angle, degrees(angle));
  
  float planetDiam = 150 + 100 * cos(angle);
  circle(width/2, height/2, planetDiam);
  }

You may find some of this useful in projects.

:)