Skip to content

Instantly share code, notes, and snippets.

@chuongmep
Last active May 13, 2021 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuongmep/2b7636b2be3dbb243968767d976cd834 to your computer and use it in GitHub Desktop.
Save chuongmep/2b7636b2be3dbb243968767d976cd834 to your computer and use it in GitHub Desktop.
/// <summary>
/// Obtains the distance between two points.
/// </summary>
/// <param name="u">Vector3.</param>
/// <param name="v">Vector3.</param>
/// <returns>Distance.</returns>
public static double Distance(this XYZ u, XYZ v)
{
return u.DistanceTo(v);
}
/// <summary>
/// Obtains the distance between two points.
/// </summary>
/// <param name="u">Vector3.</param>
/// <param name="v">Vector3.</param>
/// <returns>Distance.</returns>
public static double Distance(this XYZ u, XYZ v)
{
return Math.Sqrt(SquareDistance(u, v));
}
/// <summary>
/// Obtains the square distance between two points.
/// </summary>
/// <param name="u">Vector3.</param>
/// <param name="v">Vector3.</param>
/// <returns>Square distance.</returns>
public static double SquareDistance(this XYZ u, XYZ v)
{
return (u.X - v.X) * (u.X - v.X) + (u.Y - v.Y) * (u.Y - v.Y) + (u.Z - v.Z) * (u.Z - v.Z);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment