Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Function returns distance between two points in three dimensional space.
=> getDistance(Array(0,4,3), Array(0,0,0));
5
/**
 * Function returns distance between two points in three dimensional space
 * 
 * @param a as Array(x, y, z)
 * @param b as Array(x, y, z)
 * 
 * @return Number
 */
getDistance = function(a, b) {
  return Math.sqrt(
    Math.pow((b[0] - a[0]), 2) +
    Math.pow((b[1] - a[1]), 2) +
    Math.pow((b[2] - a[2]), 2)
  );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment