Gravity help?

Hey, so I have a question about the gravity of two objects acting on one object. I heard that you just need to find the net gravitational force, but it's not working for me, as the ball just goes in a different direction. Help, please?

PVector location1;
PVector velocity1;
PVector acceleration1;
PVector locationSun;
PVector locationSun2;
PVector distance;
float r;
float r1;
float vSun = 1;

void setup() {
  size(600, 600);

  location1 = new PVector(350, 30);
  velocity1 = new PVector(6, 0);
  acceleration1 = new PVector(0, 0);

  locationSun = new PVector(100, 300);
  locationSun2 = new PVector(500, 300);
}

void draw() {
  background(0);
  r = dist(location1.x, location1.y, locationSun.x+locationSun2.x+100, locationSun.y+locationSun2.y+100);

  if ( r < 50 ) {
    r = 50;
  }

 /* println(acceleration1.x);
  println(locationSun.x);
  println(acceleration1.x);
  println(acceleration1.x);*/

  acceleration1.x = ((locationSun.x - location1.x)*100000/pow(r, 3)) + (locationSun2.x - location1.x)*100000/pow(r, 3);
  acceleration1.y = ((locationSun.y - location1.y)*100000/pow(r, 3)) + (locationSun2.y - location1.y)*100000/pow(r, 3);

  velocity1.add(acceleration1);
  location1.add(velocity1);

  //locationSun.x += vSun;

  if ((locationSun.x >= width) || (locationSun.x <= 0)) {
    vSun *= -1;
  }

  ellipse(locationSun.x, locationSun.y, 50, 50);
  ellipse(locationSun2.x, locationSun2.y, 50, 50);
  ellipse(location1.x, location1.y, 20, 20);

}

Answers

Sign In or Register to comment.