title: C# gravity simulation code acting weird
body: <p>I have been working on a (kind of) gravity simulation using C# and Winforms, and I am getting some very weird behavior. It pretty much makes an object when you click, and is attracted to the other objects. The problem is that, unless they are within some weird distances, they will not be attracted in the positive directions (right, down.), but they are attracted upwards and to the left.</p>
  
  <p>This is the update code:</p>
  
  <pre class="lang-cs prettyprint-override"><code>    public Vector GetGravEffect(GravObject other)
      {
          if ((Math.Abs(X - other.X) &lt;= Mass * Form.DrawScale + other.Mass * Form.DrawScale) &amp;&amp; 
              (Math.Abs(Y - other.Y) &lt;= Mass * Form.DrawScale + other.Mass * Form.DrawScale))
          {
              return new Vector(0, 0);
          }
  
          double tAngle = Math.Atan2((other.Y - Y), (other.X - X));
  
          double tMagnitude = (GravModifier * Mass * other.Mass / ((Math.Pow((other.X - X), 2)) + (Math.Pow((other.Y - Y), 2))) * 1000);
  
          Complex c = Complex.FromPolarCoordinates(tMagnitude, tAngle);
  
          Vector r = new Vector(c.Real, c.Imaginary);
  
          return r;
      }
  </code></pre>
  
  <p>Full code is here: <a href="https://docs.google.com/open?id=0B79vmyWxBr-kTnUtQURPUlVidzQ" rel="nofollow">https://docs.google.com/open?id=0B79vmyWxBr-kTnUtQURPUlVidzQ</a></p>
  
  <p>Thanks for any help!</p>