Skip to content

Instantly share code, notes, and snippets.

@JordanDelcros
Created July 30, 2015 13:33
Show Gist options
  • Save JordanDelcros/f1cb9b5cf15566075435 to your computer and use it in GitHub Desktop.
Save JordanDelcros/f1cb9b5cf15566075435 to your computer and use it in GitHub Desktop.
Find distance between two vectors
// Easy way to find distance between two vectors in JavaScript
// [x, y, z]
var vectorFrom = [10, 10, 1];
var vectorTo = [12, 11, 0];
var distance = Math.sqrt(((vectorFrom[0] - vectorTo[0]) * (vectorFrom[0] - vectorTo[0])) + ((vectorFrom[1] - vectorTo[1]) * (vectorFrom[1] - vectorTo[1])) + ((vectorFrom[2] - vectorTo[2]) * (vectorFrom[2] - vectorTo[2])));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment