@@ -262,7 +262,10 @@ public static explicit operator Vector3(Vector3d v)
262
262
// complicated functions go down here...
263
263
264
264
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 )
266
269
{
267
270
// If the input vectors are v0, v1, and v2, then the Gram-Schmidt
268
271
// 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
275
278
// product of vectors A and B.
276
279
277
280
// compute u0
278
- u . Normalize ( ) ;
281
+ double minLength = u . Normalize ( ) ;
279
282
280
283
// compute u1
281
284
double dot0 = u . Dot ( v ) ;
282
285
v -= dot0 * u ;
283
- v . Normalize ( ) ;
286
+ double l = v . Normalize ( ) ;
287
+ if ( l < minLength )
288
+ minLength = l ;
284
289
285
290
// compute u2
286
291
double dot1 = v . Dot ( w ) ;
287
292
dot0 = u . Dot ( w ) ;
288
293
w -= dot0 * u + dot1 * v ;
289
- w . Normalize ( ) ;
294
+ l = w . Normalize ( ) ;
295
+ if ( l < minLength )
296
+ minLength = l ;
297
+
298
+ return minLength ;
290
299
}
291
300
292
301
@@ -318,7 +327,35 @@ public static void GenerateComplementBasis(ref Vector3d u, ref Vector3d v, Vecto
318
327
}
319
328
}
320
329
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
+ }
321
350
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
+ }
322
359
323
360
}
324
361
}
0 commit comments