aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D/math-utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/3D/math-utils.js')
-rwxr-xr-xjs/helper-classes/3D/math-utils.js252
1 files changed, 126 insertions, 126 deletions
diff --git a/js/helper-classes/3D/math-utils.js b/js/helper-classes/3D/math-utils.js
index 8a9be4b5..3c981d0d 100755
--- a/js/helper-classes/3D/math-utils.js
+++ b/js/helper-classes/3D/math-utils.js
@@ -33,8 +33,8 @@ POSSIBILITY OF SUCH DAMAGE.
33// Math Utility functions 33// Math Utility functions
34/////////////////////////////////////////////////////////////////////// 34///////////////////////////////////////////////////////////////////////
35var VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils, 35var VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils,
36 ViewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, 36 ViewUtils = require("js/helper-classes/3D/view-utils").ViewUtils,
37 Rectangle = require("js/helper-classes/3D/rectangle").Rectangle; 37 Rectangle = require("js/helper-classes/3D/rectangle").Rectangle;
38 38
39var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { 39var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
40 /////////////////////////////////////////////////////////////////////// 40 ///////////////////////////////////////////////////////////////////////
@@ -61,7 +61,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
61 // Vector Methods 61 // Vector Methods
62 /////////////////////////////////////////////////////////////////////// 62 ///////////////////////////////////////////////////////////////////////
63 63
64 vecIntersectPlaneForParam: { 64 vecIntersectPlaneForParam: {
65 value: function( pt0, vec, plane ) 65 value: function( pt0, vec, plane )
66 { 66 {
67 // declare the variable to return - undefined when there is no solution 67 // declare the variable to return - undefined when there is no solution
@@ -82,7 +82,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
82 } 82 }
83 }, 83 },
84 84
85 vecMag3: { 85 vecMag3: {
86 value: function( vec ) 86 value: function( vec )
87 { 87 {
88 if (vec.length < 3) return; 88 if (vec.length < 3) return;
@@ -92,7 +92,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
92 } 92 }
93 }, 93 },
94 94
95 vecMag: { 95 vecMag: {
96 value: function( dimen, vec ) 96 value: function( dimen, vec )
97 { 97 {
98 var sum = 0.0; 98 var sum = 0.0;
@@ -102,7 +102,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
102 } 102 }
103 }, 103 },
104 104
105 vecSubtract: { 105 vecSubtract: {
106 value: function( a, b ) 106 value: function( a, b )
107 { 107 {
108 var rtnVec; 108 var rtnVec;
@@ -119,7 +119,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
119 } 119 }
120 }, 120 },
121 121
122 vecAdd: { 122 vecAdd: {
123 value: function( a, b ) 123 value: function( a, b )
124 { 124 {
125 var rtnVec; 125 var rtnVec;
@@ -136,7 +136,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
136 } 136 }
137 }, 137 },
138 138
139 vecDist: { 139 vecDist: {
140 value: function( a, b ) 140 value: function( a, b )
141 { 141 {
142 var sum; 142 var sum;
@@ -176,7 +176,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
176 } 176 }
177 }, 177 },
178 178
179 getPointOnPlane: { 179 getPointOnPlane: {
180 value: function( plane ) 180 value: function( plane )
181 { 181 {
182 // abreviate the plane equation 182 // abreviate the plane equation
@@ -203,7 +203,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
203 } 203 }
204 }, 204 },
205 205
206 transformPlane: { 206 transformPlane: {
207 value: function( plane, mat ) 207 value: function( plane, mat )
208 { 208 {
209 // we will project a point down one of the coordinate axes to find a point on the plane 209 // we will project a point down one of the coordinate axes to find a point on the plane
@@ -213,7 +213,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
213 // find a point on the plane 213 // find a point on the plane
214 var ptOnPlane = this.getPointOnPlane(plane); 214 var ptOnPlane = this.getPointOnPlane(plane);
215 215
216 ptOnPlane[3] = 1.0; // 4 dimen so we can transform it 216 ptOnPlane[3] = 1.0; // 4 dimen so we can transform it
217 217
218 // transform the point 218 // transform the point
219 //ptOnPlane = mat.multiply( ptOnPlane ); 219 //ptOnPlane = mat.multiply( ptOnPlane );
@@ -225,12 +225,12 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
225 } 225 }
226 }, 226 },
227 227
228 transformHomogeneousPoint: { 228 transformHomogeneousPoint: {
229 value: function( srcPt, mat ) 229 value: function( srcPt, mat )
230 { 230 {
231 var pt = srcPt.slice(0); 231 var pt = srcPt.slice(0);
232 this.makeDimension4( pt ); 232 this.makeDimension4( pt );
233 var x = VecUtils.vecDot(4, pt, [mat[0], mat[4], mat[ 8], mat[12]] ), 233 var x = VecUtils.vecDot(4, pt, [mat[0], mat[4], mat[ 8], mat[12]] ),
234 y = VecUtils.vecDot(4, pt, [mat[1], mat[5], mat[ 9], mat[13]] ), 234 y = VecUtils.vecDot(4, pt, [mat[1], mat[5], mat[ 9], mat[13]] ),
235 z = VecUtils.vecDot(4, pt, [mat[2], mat[6], mat[10], mat[14]] ), 235 z = VecUtils.vecDot(4, pt, [mat[2], mat[6], mat[10], mat[14]] ),
236 w = VecUtils.vecDot(4, pt, [mat[3], mat[7], mat[11], mat[15]] ); 236 w = VecUtils.vecDot(4, pt, [mat[3], mat[7], mat[11], mat[15]] );
@@ -239,7 +239,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
239 } 239 }
240 }, 240 },
241 241
242 applyHomogeneousCoordinate: { 242 applyHomogeneousCoordinate: {
243 value: function( hPt ) 243 value: function( hPt )
244 { 244 {
245 var w = hPt[3]; 245 var w = hPt[3];
@@ -252,19 +252,19 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
252 } 252 }
253 }, 253 },
254 254
255 transformAndDivideHomogeneousPoint: { 255 transformAndDivideHomogeneousPoint: {
256 value: function( pt, mat ) 256 value: function( pt, mat )
257 { 257 {
258 return this.applyHomogeneousCoordinate( this.transformHomogeneousPoint(pt, mat) ); 258 return this.applyHomogeneousCoordinate( this.transformHomogeneousPoint(pt, mat) );
259 } 259 }
260 }, 260 },
261 261
262 transformPoint: { 262 transformPoint: {
263 value: function( srcPt, mat ) 263 value: function( srcPt, mat )
264 { 264 {
265 var pt = srcPt.slice(0); 265 var pt = srcPt.slice(0);
266 this.makeDimension3( pt ); 266 this.makeDimension3( pt );
267 var x = VecUtils.vecDot(3, pt, [mat[0], mat[4], mat[ 8]] ) + mat[12], 267 var x = VecUtils.vecDot(3, pt, [mat[0], mat[4], mat[ 8]] ) + mat[12],
268 y = VecUtils.vecDot(3, pt, [mat[1], mat[5], mat[ 9]] ) + mat[13], 268 y = VecUtils.vecDot(3, pt, [mat[1], mat[5], mat[ 9]] ) + mat[13],
269 z = VecUtils.vecDot(3, pt, [mat[2], mat[6], mat[10]] ) + mat[14]; 269 z = VecUtils.vecDot(3, pt, [mat[2], mat[6], mat[10]] ) + mat[14];
270 270
@@ -272,11 +272,11 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
272 } 272 }
273 }, 273 },
274 274
275 transformVector: { 275 transformVector: {
276 value: function( vec, mat ) 276 value: function( vec, mat )
277 { 277 {
278 this.makeDimension3( vec ); 278 this.makeDimension3( vec );
279 var x = VecUtils.vecDot(3, vec, [mat[0], mat[4], mat[ 8]] ), 279 var x = VecUtils.vecDot(3, vec, [mat[0], mat[4], mat[ 8]] ),
280 y = VecUtils.vecDot(3, vec, [mat[1], mat[5], mat[ 9]] ), 280 y = VecUtils.vecDot(3, vec, [mat[1], mat[5], mat[ 9]] ),
281 z = VecUtils.vecDot(3, vec, [mat[2], mat[6], mat[10]] ); 281 z = VecUtils.vecDot(3, vec, [mat[2], mat[6], mat[10]] );
282 282
@@ -284,7 +284,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
284 } 284 }
285 }, 285 },
286 286
287 interpolateLine3D: { 287 interpolateLine3D: {
288 value: function( pt0, pt1, t ) 288 value: function( pt0, pt1, t )
289 { 289 {
290 var x0 = pt0[0], y0 = pt0[1], z0 = pt0[2], 290 var x0 = pt0[0], y0 = pt0[1], z0 = pt0[2],
@@ -444,7 +444,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
444 } 444 }
445 }, 445 },
446 446
447 nearestPointOnLine2D: { 447 nearestPointOnLine2D: {
448 value: function( linePt, lineDir, pt ) 448 value: function( linePt, lineDir, pt )
449 { 449 {
450 var vec = this.vecSubtract( pt, linePt ); 450 var vec = this.vecSubtract( pt, linePt );
@@ -458,7 +458,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
458 } 458 }
459 }, 459 },
460 460
461 parameterizePointOnLine2D: { 461 parameterizePointOnLine2D: {
462 value: function( linePt, lineDir, ptOnLine ) 462 value: function( linePt, lineDir, ptOnLine )
463 { 463 {
464 var t; 464 var t;
@@ -483,7 +483,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
483 } 483 }
484 }, 484 },
485 485
486 pointsEqual: { 486 pointsEqual: {
487 value: function( dimen, a, b ) 487 value: function( dimen, a, b )
488 { 488 {
489 if ((a.length < dimen) || (b.length < dimen)) 489 if ((a.l