aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/classes/share/javax/media/j3d/Utils.java175
1 files changed, 175 insertions, 0 deletions
diff --git a/src/classes/share/javax/media/j3d/Utils.java b/src/classes/share/javax/media/j3d/Utils.java
index 276b1e5..81a3391 100644
--- a/src/classes/share/javax/media/j3d/Utils.java
+++ b/src/classes/share/javax/media/j3d/Utils.java
@@ -99,6 +99,181 @@ static final double ptToRaySquare(Point3d pt, Point3d start, Vector3d dir, Point
private static final double ZERO_TOL = 1e-5d;
/**
+ * Return the square of the minimum distance between a ray and a segment.
+ * Geometric Tools, LLC
+ * Copyright (c) 1998-2012
+ * Distributed under the Boost Software License, Version 1.0.
+ * http://www.boost.org/LICENSE_1_0.txt
+ * http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
+ * http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
+ * File Version: 5.0.1 (2010/10/01)
+ */
+static public double rayToSegment(Point3d rayorig, Vector3d raydir,
+ Point3d segstart, Point3d segend,
+ Point3d rayint, Point3d segint, double[] param) {
+// Vector3<Real> diff = mRay->Origin- mSegment->Center;
+// Real a01 = -mRay->Direction.Dot(mSegment->Direction);
+// Real b0 = diff.Dot(mRay->Direction);
+// Real b1 = -diff.Dot(mSegment->Direction);
+// Real c = diff.SquaredLength();
+// Real det = Math<Real>::FAbs((Real)1 - a01*a01);
+// Real s0, s1, sqrDist, extDet;
+//
+// if (det >= Math<Real>::ZERO_TOLERANCE)
+// {
+// // The ray and segment are not parallel.
+// s0 = a01*b1 - b0;
+// s1 = a01*b0 - b1;
+// extDet = mSegment->Extent*det;
+//
+// if (s0 >= (Real)0)
+// {
+// if (s1 >= -extDet)
+// {
+// if (s1 <= extDet) // region 0
+// {
+// // Minimum at interior points of ray and segment.
+// Real invDet = ((Real)1)/det;
+// s0 *= invDet;
+// s1 *= invDet;
+// sqrDist = s0*(s0 + a01*s1 + ((Real)2)*b0) +
+// s1*(a01*s0 + s1 + ((Real)2)*b1) + c;
+// }
+// else // region 1
+// {
+// s1 = mSegment->Extent;
+// s0 = -(a01*s1 + b0);
+// if (s0 > (Real)0)
+// {
+// sqrDist = -s0*s0 + s1*(s1 + ((Real)2)*b1) + c;
+// }
+// else
+// {
+// s0 = (Real)0;
+// sqrDist = s1*(s1 + ((Real)2)*b1) + c;
+// }
+// }
+// }
+// else // region 5
+// {
+// s1 = -mSegment->Extent;
+// s0 = -(a01*s1 + b0);
+// if (s0 > (Real)0)
+// {
+// sqrDist = -s0*s0 + s1*(s1 + ((Real)2)*b1) + c;
+// }
+// else
+// {
+// s0 = (Real)0;
+// sqrDist = s1*(s1 + ((Real)2)*b1) + c;
+// }
+// }
+// }
+// else
+// {
+// if (s1 <= -extDet) // region 4
+// {
+// s0 = -(-a01*mSegment->Extent + b0);
+// if (s0 > (Real)0)
+// {
+// s1 = -mSegment->Extent;
+// sqrDist = -s0*s0 + s1*(s1 + ((Real)2)*b1) + c;
+// }
+// else
+// {
+// s0 = (Real)0;
+// s1 = -b1;
+// if (s1 < -mSegment->Extent)
+// {
+// s1 = -mSegment->Extent;
+// }
+// else if (s1 > mSegment->Extent)
+// {
+// s1 = mSegment->Extent;
+// }
+// sqrDist = s1*(s1 + ((Real)2)*b1) + c;
+// }
+// }
+// else if (s1 <= extDet) // region 3
+// {
+// s0 = (Real)0;
+// s1 = -b1;
+// if (s1 < -mSegment->Extent)
+// {
+// s1 = -mSegment->Extent;
+// }
+// else if (s1 > mSegment->Extent)
+// {
+// s1 = mSegment->Extent;
+// }
+// sqrDist = s1*(s1 + ((Real)2)*b1) + c;
+// }
+// else // region 2
+// {
+// s0 = -(a01*mSegment->Extent + b0);
+// if (s0 > (Real)0)
+// {
+// s1 = mSegment->Extent;
+// sqrDist = -s0*s0 + s1*(s1 + ((Real)2)*b1) + c;
+// }
+// else
+// {
+// s0 = (Real)0;
+// s1 = -b1;
+// if (s1 < -mSegment->Extent)
+// {
+// s1 = -mSegment->Extent;
+// }
+// else if (s1 > mSegment->Extent)
+// {
+// s1 = mSegment->Extent;
+// }
+// sqrDist = s1*(s1 + ((Real)2)*b1) + c;
+// }
+// }
+// }
+// }
+// else
+// {
+// // Ray and segment are parallel.
+// if (a01 > (Real)0)
+// {
+// // Opposite direction vectors.
+// s1 = -mSegment->Extent;
+// }
+// else
+// {
+// // Same direction vectors.
+// s1 = mSegment->Extent;
+// }
+//
+// s0 = -(a01*s1 + b0);
+// if (s0 > (Real)0)
+// {
+// sqrDist = -s0*s0 + s1*(s1 + ((Real)2)*b1) + c;
+// }
+// else
+// {
+// s0 = (Real)0;
+// sqrDist = s1*(s1 + ((Real)2)*b1) + c;
+// }
+// }
+//
+// mClosestPoint0 = mRay->Origin + s0*mRay->Direction;
+// mClosestPoint1 = mSegment->Center + s1*mSegment->Direction;
+// mRayParameter = s0;
+// mSegmentParameter = s1;
+//
+// // Account for numerical round-off errors.
+// if (sqrDist < (Real)0)
+// {
+// sqrDist = (Real)0;
+// }
+// return sqrDist;
+ return 0.0d;
+}
+
+/**
* Return the square of the minimum distance between two line segments.
*
* Code in this method adapted from: