mcneel / rhinocommon

RhinoCommon is the .NET SDK for Rhino5 / Grasshopper
http://wiki.mcneel.com/developer/rhinocommon
243 stars 93 forks source link

Why Rhino.Geometry.Vector3d.VectorAngle returns (2π - angle)? #178

Open goznauk opened 7 years ago

goznauk commented 7 years ago
public static double VectorAngle(Vector3d a, Vector3d b, Plane plane)
    {
      Point3d testPoint1 = plane.Origin + a;
      Point3d testPoint2 = plane.Origin + b;
      Point3d point3d1 = plane.ClosestPoint(testPoint1);
      Point3d point3d2 = plane.ClosestPoint(testPoint2);
      a = point3d1 - plane.Origin;
      b = point3d2 - plane.Origin;
      if (!a.Unitize() || !b.Unitize())
        return -1.23432101234321E+308;
      double d = a * b;
      if (d >= 1.0)
        d = 1.0;
      else if (d < -1.0)
        d = -1.0;
      double num = Math.Acos(d);
      if (Math.Abs(num) < 1E-64)
        return 0.0;
      if (Math.Abs(num - Math.PI) < 1E-64)
        return Math.PI;
      Vector3d other = Vector3d.CrossProduct(a, b);
      if (plane.ZAxis.IsParallelTo(other) == 1)
        return num;
      return 2.0 * Math.PI - num;
    }

This is what I've found in Rhino.Geometry.Vector3d.VectorAngle(Vector3d a, Vector3d b, Plane plane). I don't know why we should get (2π - angle) in most cases - when the input plane is not the plane contains both a and b. Is there any reason for this?