Skip to content

Instantly share code, notes, and snippets.

@calvinte
Created April 29, 2012 02:47
Show Gist options
  • Select an option

  • Save calvinte/2525919 to your computer and use it in GitHub Desktop.

Select an option

Save calvinte/2525919 to your computer and use it in GitHub Desktop.
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