aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/3D')
-rw-r--r--js/helper-classes/3D/math-utils.js18
1 files changed, 10 insertions, 8 deletions
diff --git a/js/helper-classes/3D/math-utils.js b/js/helper-classes/3D/math-utils.js
index 71ed62a0..3d24f76e 100644
--- a/js/helper-classes/3D/math-utils.js
+++ b/js/helper-classes/3D/math-utils.js
@@ -802,19 +802,21 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
802 getAxisAngleBetween3DVectors: { 802 getAxisAngleBetween3DVectors: {
803 value: function (vec1, vec2, axis) { 803 value: function (vec1, vec2, axis) {
804 //compute magnitudes of the vectors 804 //compute magnitudes of the vectors
805 var mag1 = VecUtils.vecMag(3, vec1); 805 var v1n = VecUtils.vecNormalize(3, vec1, 1.0);
806 var mag2 = VecUtils.vecMag(3, vec2); 806 var v2n = VecUtils.vecNormalize(3, vec2, 1.0);
807
808 if (mag1 < this.EPSILON || mag2 < this.EPSILON) {
809 return 0; //if angle 0 is returned nothing from this function should be used
810 }
811 //angle between the vectors (acos for now...) 807 //angle between the vectors (acos for now...)
812 var angle = Math.acos(VecUtils.vecDot(3, vec1, vec2) / (mag1 * mag2)); 808 var angle = Math.acos(VecUtils.vecDot(3, v1n, v2n));
813 if (Math.abs(angle) < this.EPSILON) { 809 if (Math.abs(angle) < this.EPSILON) {
814 return 0; 810 return 0;
815 } 811 }
812 //TODO testing...remove this block
813 console.log("getAxisAngleBetween3DVectors Angle: "+angle);
814 if (isNaN(angle)){
815 console.log("getAxisAngleBetween3DVectors Angle is NaN");
816 }
817 //TODO end testing block
816 //optionally, if axis is provided, create the axis of rotation as well 818 //optionally, if axis is provided, create the axis of rotation as well
817 var rotAxis = VecUtils.vecCross(3, vec1, vec2); 819 var rotAxis = VecUtils.vecCross(3, v1n, v2n);
818 rotAxis = VecUtils.vecNormalize(3, rotAxis, 1); 820 rotAxis = VecUtils.vecNormalize(3, rotAxis, 1);
819 axis[0] = rotAxis[0]; 821 axis[0] = rotAxis[0];
820 axis[1] = rotAxis[1]; 822 axis[1] = rotAxis[1];