aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarvey Harrison <[email protected]>2013-06-28 14:04:11 -0700
committerHarvey Harrison <[email protected]>2013-06-28 14:04:11 -0700
commit10328f8af2ba8e67b0c20c91470bf6c2cf5fdf9b (patch)
treec82d6dee10868737b9a12b76a00a63c289a4b9c7 /src
parent2886665b8c759fc097f6230d11ec9bc6a2f0938b (diff)
j3dcore: check in a snapshot of the GeometricTools ray to segment distance function
- adapted from code under the Boost 1.0 license, here distributed as GPLv2 + classpath Signed-off-by: Harvey Harrison <[email protected]>
Diffstat (limited to 'src')
-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: