title: The angle between two 3D vectors with a result range 0 - 360
body: <p>I'm looking for a way to calculate the angle between three points considered as two vectors (see below):</p>
  
  <pre><code>using System.Windows.Media.Media3D;
  
  public static float AngleBetweenThreePoints(Point3D[] points)
  {
      var v1 = points[1] - points[0];
      var v2 = points[2] - points[1];
  
      var cross = Vector3D.CrossProduct(v1, v2);
      var dot = Vector3D.DotProduct(v1, v2);
  
      var angle = Math.PI - Math.Atan2(cross.Length, dot);
      return (float) angle;
  }
  </code></pre>
  
  <p>If you give this the following points:</p>
  
  <pre><code>var points = new[]
  {
      new Point3D(90, 100, 300),
      new Point3D(100, 200, 300),
      new Point3D(100, 300, 300)
  };
  </code></pre>
  
  <p>or the following:</p>
  
  <pre><code>var points = new[]
  {
      new Point3D(110, 100, 300),
      new Point3D(100, 200, 300),
      new Point3D(100, 300, 300)
  };
  </code></pre>
  
  <p>You get the same result. I can see the cross product in the function returns (0, 0, 10000) in the first case, and (0, 0, -10000) in the second but this information gets lost with cross.Length which could never return a -ve result.</p>
  
  <p>What I'm looking for is a result range 0 - 360 not limited to 0 - 180. How do I achieve that?</p>