Skip to content

Commit 085cd5c

Browse files
committed
new Vector3d fns, minor improvements
1 parent 07dbdf3 commit 085cd5c

File tree

4 files changed

+49
-11
lines changed

4 files changed

+49
-11
lines changed

math/AxisAlignedBox3d.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public void MoveMin(double fNewX, double fNewY, double fNewZ) {
199199

200200

201201
public override string ToString() {
202-
return string.Format("x[{0:F8},{1:F8}] y[{2:F8},{3:F8}] z[{2:F8},{3:F8}]", Min.x, Max.x, Min.y, Max.y, Min.z, Max.z);
202+
return string.Format("x[{0:F8},{1:F8}] y[{2:F8},{3:F8}] z[{4:F8},{5:F8}]", Min.x, Max.x, Min.y, Max.y, Min.z, Max.z);
203203
}
204204

205205

math/AxisAlignedBox3f.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public void MoveMin(float fNewX, float fNewY, float fNewZ)
223223

224224
public override string ToString()
225225
{
226-
return string.Format("x[{0:F8},{1:F8}] y[{2:F8},{3:F8}] z[{2:F8},{3:F8}]", Min.x, Max.x, Min.y, Max.y, Min.z, Max.z);
226+
return string.Format("x[{0:F8},{1:F8}] y[{2:F8},{3:F8}] z[{4:F8},{5:F8}]", Min.x, Max.x, Min.y, Max.y, Min.z, Max.z);
227227
}
228228

229229

math/Vector3d.cs

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

shapes3/Circle3.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace g3
44
{
5+
// somewhat ported from WildMagic5
56
public class Circle3d
67
{
78
// The plane containing the circle is Dot(N,X-C) = 0, where X is any point
@@ -25,13 +26,13 @@ public Circle3d(Vector3d center, double radius, Vector3d axis0, Vector3d axis1,
2526
PlaneY = axis1;
2627
Radius = radius;
2728
}
28-
public Circle3d(Vector3d center, double radius, Frame3f f, int nNormalAxis = 1)
29+
public Circle3d(Frame3f frame, double radius, int nNormalAxis = 1)
2930
{
3031
IsReversed = false;
31-
Center = center;
32-
Normal = f.GetAxis(nNormalAxis);
33-
PlaneX = f.GetAxis((nNormalAxis + 1) % 3);
34-
PlaneY = f.GetAxis((nNormalAxis + 2) % 3);
32+
Center = frame.Origin;
33+
Normal = frame.GetAxis(nNormalAxis);
34+
PlaneX = frame.GetAxis((nNormalAxis + 1) % 3);
35+
PlaneY = frame.GetAxis((nNormalAxis + 2) % 3);
3536
Radius = radius;
3637
}
3738
public Circle3d(Vector3d center, double radius)

0 commit comments

Comments
 (0)