Javascript phsyics in 2d space

So, I'm working on teaching myself Canvas (HTML5) and having most of the simple game engine. This is a 2d representation of the cosmic scene (planets, stars, celestial bodies, etc.). My "Sprite" class has a frame listener by default, such as:

"baseClass" contains a function that allows you to inherit and applies "a" to "this.a". So, "var aTest = new Sprite ({foo:" bar "}); will do" aTest.foo = "bar" ". This is how I open my objects to each other.

Sprite = baseClass.extend({
  init: function(a){
    baseClass.init(this, a);
    this.fields = new Array(); // list of fields of gravity one is in. Not sure if this is a good idea.
    this.addFL(function(tick){ // this will change to be independent of framerate soon.

      // gobjs is an array of all the Sprite objects in the "world".
      for(i = 0; i < gobjs.length; i++){

        // Make sure its got setup correctly, make sure it -wants- gravity, and make sure it not -this- sprite.
        if(typeof(gobjs[i].a) != undefined && !gobjs[i].a.ignoreGravity && gobjs[i].id != this.id){
          // Check if it within a certain range (obviously, gravity doesn't work this way... But I plan on having a large "space" area,
          // And I can't very well have all objects accounted for at all times, can I?
          if(this.distanceTo(gobjs[i]) < this.a.size*10 && gobjs[i].fields.indexOf(this.id) == -1){
            gobjs[i].fields.push(this.id);
          }
        }
      }
      for(i = 0; i < this.fields.length; i++){
        distance = this.distanceTo(gobjs[this.fields[i]]); 

        angletosun = this.angleTo(gobjs[this.fields[i]])*(180/Math.PI); // .angleTo works very well, returning the angle in radians, which I convert to degrees here.

        // I have no idea what should happen here, although through trial and error (and attempting to read Maths papers on gravity (eeeeek!)), this sort of mimics gravity.
        // angle is its orientation, currently I assign a constant velocity to one of my objects, and leave the other static (it ignores gravity, but still emits it).
        // This cant be right, because it just _sets_ the angle regardless of whatever it was.
        // This is where we need to find "the average of the forces".
        this.a.angle = angletosun+(75+(distance*-1)/5); //todo: omg learn math

        if(this.distanceTo(gobjs[this.fields[i]]) > gobjs[this.fields[i]].a.size*10){
          this.fields.splice(i); // out of range, stop effecting.
        }
      }
    });

    //draw objects based on new position (from fixed velocity and angle).

  }
});

Thanks in advance. The real trick is that there is one line, and by the way, I know that this makes no sense. Degrees + distance = failure.

this.a.angle = angletosun+(75+(distance*-1)/5);

, Javascript, - . .

+5
1

, , - .

, , , , , , , , , , . http://en.wikipedia.org/wiki/Euclidean_vector

--, , , .

, , , .

: :

p=p+v

. B - A:

B.v=B.v+(A.p-B.p)*(A.m/(|A.p-B.p|^3))

, .

+3

All Articles