Created
July 30, 2015 13:33
-
-
Save JordanDelcros/f1cb9b5cf15566075435 to your computer and use it in GitHub Desktop.
Find distance between two vectors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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