From fb416001ad34e5e5a07673ebdbe1d3bbee59e886 Mon Sep 17 00:00:00 2001 From: "chappuis.daniel" Date: Sat, 2 Jan 2010 23:54:36 +0000 Subject: [PATCH] git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@246 92aac97c-a6ce-11dd-a772-7fcde58d38e6 --- .../reactphysics3d/mathematics/mathematics.h | 77 +++++++++++-------- 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/sources/reactphysics3d/mathematics/mathematics.h b/sources/reactphysics3d/mathematics/mathematics.h index 1a9d7f24..7602dfd2 100644 --- a/sources/reactphysics3d/mathematics/mathematics.h +++ b/sources/reactphysics3d/mathematics/mathematics.h @@ -93,53 +93,64 @@ inline std::vector movePoints(const std::vector segment1.getLength() && projSegment2PointB > segment1.getLength())); + assert(!(projSeg2PointA < 0.0 && projSegment2PointB < 0.0)); + assert(!(projSeg2PointA > d1.length() && projSeg2PointB > d1.length())); + + // Compute the distance between the two segments + double distance = computeDistanceBetweenPointAndLine(seg2PointA, seg1PointA, d1); // Return the segment intersection according to the configuration of two projection intervals - if (projSegment2PointA >= 0 && projSegment2PointA <= segment1.getLength() && projSegment2PointB >= segment1.getLength()) { - resultSegment.setPointA(segment2.getPointA()); - resultSegment.setPointB(segment1.getPointB()); - return resultSegment; + if (projSeg2PointA >= 0 && projSeg2PointA <= d1.length() && projSeg2PointB >= d1.length()) { + resultPointA = seg2PointA; + resultPointB = seg1PointB; + + // Move the contact points halfway between the two segments + } - else if (projSegment2PointA <= 0 && projSegment2PointB >= 0 && projSegment2PointB <= segment1.getLength()) { - resultSegment.setPointA(segment1.getPointA()); - resultSegment.setPointB(segment2.getPointB()); - return resultSegment; + else if (projSeg2PointA <= 0 && projSeg2PointB >= 0 && projSeg2PointB <= d1.length()) { + resultPointA = seg1PointA; + resultPointB = seg2PointB; } - else if (projSegment2PointA <= 0 && projSegment2PointB >= segment1.getLength()) { - return segment1; + else if (projSeg2PointA <= 0 && projSeg2PointB >= d1.length()) { + resultPointA = seg1PointA; + resultPointB = seg1PointB; } else if (projSegment2PointA <= segment1.getLength() && projSegment2PointB <= segment1.getLength()) { - return segment2; + resultPointA = seg2PointA; + resultPointB = seg2PointB; } - // We should never go here - assert(false); + + + +} + +// Compute the distance between a point "pointP" and a line (given by a point "pointA" and a vector "v") +inline double computeDistanceBetweenPointAndLine(const reactphysics3d::Vector3D& pointP, const reactphysics3d::Vector3D& pointA, const reactphysics3d::Vector3D& v) { + assert(v.length() != 0); + return ((pointP-pointA).crossProduct(v).length() / (v.length())); } -*/ #endif