Advertisement
calcpage

LACS09_TwoBodyG.java

Jun 21st, 2012
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.74 KB | None | 0 0
  1. //TwoBodyG.java     MrG     2012.0621 (work in progress)
  2. public class TwoBodyG
  3. {
  4.     private double size;
  5.     private BodyG[] planets;
  6.  
  7.     public TwoBodyG(double size, BodyG b1, BodyG b2)
  8.     {
  9.         this.size = size;
  10.         StdDraw.setXscale(-size,size);
  11.         StdDraw.setYscale(-size,size);
  12.         planets = new BodyG[2];
  13.         planets[0]=b1;
  14.         planets[1]=b2;
  15.     }
  16.  
  17.     public void draw()
  18.     {
  19.         planets[0].draw();
  20.         planets[1].draw();
  21.     }
  22.  
  23.     public void move(double time)
  24.     {
  25.         Vector f0 = new Vector(0,0);
  26.         f0.sum(planets[0].pullFrom(planets[1]));
  27.         f0.sum(planets[1].pullFrom(planets[0]));
  28.         planets[0].move(f0,time);
  29.        
  30.         Vector f1 = new Vector(0,0);
  31.         f1.sum(planets[1].pullFrom(planets[0]));
  32.         f1.sum(planets[0].pullFrom(planets[1]));
  33.         planets[1].move(f1,time);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement