Skip to content

Commit

Permalink
Merge pull request #481 from hypar-io/angle-to-fix
Browse files Browse the repository at this point in the history
also return 180 if (dot / length ~ -1), it's close
  • Loading branch information
wynged authored Jan 19, 2021
2 parents 7c8de1c + eb5c148 commit fe2b705
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions Elements/src/Geometry/Vector3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ public double Dot(Vector3 v)
}

/// <summary>
/// The angle in degrees from this vector to the provided vector.
/// Note that for angles in the plane that can be greater than 180 degrees,
/// The angle in degrees from this vector to the provided vector.
/// Note that for angles in the plane that can be greater than 180 degrees,
/// you should use Vector3.PlaneAngleTo.
/// </summary>
/// <param name="v">The vector with which to measure the angle.</param>
Expand All @@ -182,7 +182,12 @@ public double AngleTo(Vector3 v)
{
return 0.0;
}
if (r.ApproximatelyEquals(-1.0))
{
return 180;
}
var rad = Math.Acos(r);

return rad * 180 / Math.PI;
}

Expand Down Expand Up @@ -263,7 +268,7 @@ public double DistanceTo(Plane p)
}

/// <summary>
/// Find the distance from this point to the line, and output the location
/// Find the distance from this point to the line, and output the location
/// of the closest point on that line.
/// Using formula from https://diego.assencio.com/?index=ec3d5dfdfc0b6a0d147a656f0af332bd
/// </summary>
Expand Down Expand Up @@ -725,17 +730,17 @@ public static bool AreCollinear(this IList<Vector3> points)
/// <summary>
/// Compute a transform with the origin at points[0], with
/// an X axis along points[1]->points[0], and a normal
/// computed using the vectors points[2]->points[1] and
/// computed using the vectors points[2]->points[1] and
/// points[1]->points[0].
/// </summary>
/// <param name="points"></param>
/// <returns></returns>
public static Transform ToTransform(this IList<Vector3> points)
{
var a = (points[1] - points[0]).Unitized();
// We need to search for a second vector that is not colinear
// We need to search for a second vector that is not colinear
// with the first. If all the vectors are tried, and one isn't
// found that's not parallel to the first, you'll
// found that's not parallel to the first, you'll
// get a zero-length normal.
Vector3 b = new Vector3();
for (var i = 2; i < points.Count; i++)
Expand Down

0 comments on commit fe2b705

Please sign in to comment.