title: How do I calculate angle from two coordinates?
body: <p>I'm working on a project with 3D based objects and manipulating them via my program.  I currently have a textbox that allows me to put a heading in degrees and a button that will calculate the required values to make my main object change its heading. This is the code for that function:</p>
  
  <pre><code>    private void btnSetHeading_Click(object sender, EventArgs e)
      {
          if (this.textBoxHeading.Text.Length == 0)
              return;
  
          float heading = (float)0;
          try
          {
              heading = float.Parse(this.textBoxHeading.Text);
          }
          catch (FormatException ex)
          {
              MessageBox.Show(ex.Message);
              return;
          }
  
          if (heading &lt; (float)0 || heading &gt; (float)360)
          {
              MessageBox.Show("Invalid heading parameter. Acceptable range: 0 - 360");
              return;
          }
  
          float tempCosine = (float)Math.Cos(((heading * Math.PI) / (float)360.0));
          float tempSine = -((float)Math.Sin(((heading * Math.PI) / (float)360.0)));
          try
          {
              ProgramInterop.CreateInstance.SetHeading(tempCosine, tempSine);
          }
          catch (Exception ex)
          {
              MessageBox.Show("Caught: " + ex.Message);
  
          }
      }
  </code></pre>
  
  <p>If I supply 90 as the heading to face, the results are tempCosine=0.7071068 and tempSine=-0.7071068, which then makes my main object face 90 degrees or due east.</p>
  
  <p>The program requires the heading to be given in two seperate values(tempCosine and tempSine) which I'm not familiar with geometry enough to understand why I would multiply by 360 instead of 180 but this is how its required to work.</p>
  
  <p>Now for the next part of my project involves making my main object face another object given both of their (x,y) coordinates.  If for example my main object is at (9112.94, 22088.74) and the new object I want to face is at (9127.04, 22088.88), it would require almost exactly 90 degrees heading to make it face the new object.</p>
  
  <p>How can I calculate the tempCosine and tempSine from those two coordinates?</p>