Permalink
Browse files

Merge pull request #7 from Coreh/feature-vec3-dist

Implement vec3.dist, a method for calculating the distance between two vectors
  • Loading branch information...
2 parents 303f749 + b88f6bc commit 24a901f488b74fa9063937aefb5a7f1e09152da4 @toji toji committed Dec 13, 2011
Showing with 19 additions and 0 deletions.
  1. +19 −0 gl-matrix.js
View
@@ -347,6 +347,25 @@ vec3.lerp = function (vec, vec2, lerp, dest) {
};
/*
+ * vec3.dist
+ * Calculates the euclidian distance between two vec3
+ *
+ * Params:
+ * vec - vec3, first vector
+ * vec2 - vec3, second vector
+ *
+ * Returns:
+ * distance between vec and vec2
+ */
+vec3.dist = function (vec, vec2) {
+ var x = vec2[0] - vec[0],
+ y = vec2[1] - vec[1],
+ z = vec2[2] - vec[2];
+
+ return Math.sqrt(x*x + y*y + z*z);
+};
+
+/*
* vec3.str
* Returns a string representation of a vector
*

0 comments on commit 24a901f

Please sign in to comment.