@@ -262,7 +262,10 @@ public static explicit operator Vector3(Vector3d v)
262262 // complicated functions go down here...
263263
264264
265- public static void Orthonormalize ( ref Vector3d u , ref Vector3d v , ref Vector3d w )
265+ // [RMS] this is from WildMagic5, but I added returning the minLength value
266+ // from GTEngine, because I use this in place of GTEngine's Orthonormalize in
267+ // ComputeOrthogonalComplement below
268+ public static double Orthonormalize ( ref Vector3d u , ref Vector3d v , ref Vector3d w )
266269 {
267270 // If the input vectors are v0, v1, and v2, then the Gram-Schmidt
268271 // orthonormalization produces vectors u0, u1, and u2 as follows,
@@ -275,18 +278,24 @@ public static void Orthonormalize(ref Vector3d u, ref Vector3d v, ref Vector3d w
275278 // product of vectors A and B.
276279
277280 // compute u0
278- u . Normalize ( ) ;
281+ double minLength = u . Normalize ( ) ;
279282
280283 // compute u1
281284 double dot0 = u . Dot ( v ) ;
282285 v -= dot0 * u ;
283- v . Normalize ( ) ;
286+ double l = v . Normalize ( ) ;
287+ if ( l < minLength )
288+ minLength = l ;
284289
285290 // compute u2
286291 double dot1 = v . Dot ( w ) ;
287292 dot0 = u . Dot ( w ) ;
288293 w -= dot0 * u + dot1 * v ;
289- w . Normalize ( ) ;
294+ l = w . Normalize ( ) ;
295+ if ( l < minLength )
296+ minLength = l ;
297+
298+ return minLength ;
290299 }
291300
292301
@@ -318,7 +327,35 @@ public static void GenerateComplementBasis(ref Vector3d u, ref Vector3d v, Vecto
318327 }
319328 }
320329
330+ // this function is from GTEngine
331+ // Compute a right-handed orthonormal basis for the orthogonal complement
332+ // of the input vectors. The function returns the smallest length of the
333+ // unnormalized vectors computed during the process. If this value is nearly
334+ // zero, it is possible that the inputs are linearly dependent (within
335+ // numerical round-off errors). On input, numInputs must be 1 or 2 and
336+ // v0 through v(numInputs-1) must be initialized. On output, the
337+ // vectors v0 through v2 form an orthonormal set.
338+ public static double ComputeOrthogonalComplement ( int numInputs , Vector3d v0 , ref Vector3d v1 , ref Vector3d v2 /*, bool robust = false*/ )
339+ {
340+ if ( numInputs == 1 ) {
341+ if ( Math . Abs ( v0 [ 0 ] ) > Math . Abs ( v0 [ 1 ] ) ) {
342+ v1 = new Vector3d ( - v0 [ 2 ] , 0.0 , + v0 [ 0 ] ) ;
343+ }
344+ else
345+ {
346+ v1 = new Vector3d ( 0.0 , + v0 [ 2 ] , - v0 [ 1 ] ) ;
347+ }
348+ numInputs = 2 ;
349+ }
321350
351+ if ( numInputs == 2 ) {
352+ v2 = Vector3d . Cross ( v0 , v1 ) ;
353+ return Vector3d . Orthonormalize ( ref v0 , ref v1 , ref v2 ) ;
354+ //return Orthonormalize<3, Real>(3, v, robust);
355+ }
356+
357+ return 0 ;
358+ }
322359
323360 }
324361}
0 commit comments