From 2cf0461241509a6a7349c95d3fd8c9e2089fd8d3 Mon Sep 17 00:00:00 2001 From: "chappuis.daniel" Date: Tue, 5 Jan 2010 20:50:40 +0000 Subject: [PATCH] git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@248 92aac97c-a6ce-11dd-a772-7fcde58d38e6 --- .../reactphysics3d/mathematics/mathematics.h | 59 ++++++++++--------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/sources/reactphysics3d/mathematics/mathematics.h b/sources/reactphysics3d/mathematics/mathematics.h index 7602dfd2..610bdaca 100644 --- a/sources/reactphysics3d/mathematics/mathematics.h +++ b/sources/reactphysics3d/mathematics/mathematics.h @@ -95,12 +95,25 @@ inline std::vector movePoints(const std::vector d1.length() && projSeg2PointB > d1.length())); - // Compute the distance between the two segments - double distance = computeDistanceBetweenPointAndLine(seg2PointA, seg1PointA, d1); + // Compute the vector "v" from a point on the line 1 to the orthogonal point of the line 2 + reactphysics3d::Vector3D point = computeOrthogonalProjectionOfPointOntoALine(seg2PointA, seg1PointA, d1); + reactphysics3d::Vector3D v = seg2PointA - point; // Return the segment intersection according to the configuration of two projection intervals if (projSeg2PointA >= 0 && projSeg2PointA <= d1.length() && projSeg2PointB >= d1.length()) { - resultPointA = seg2PointA; - resultPointB = seg1PointB; - // Move the contact points halfway between the two segments - + resultPointA = seg2PointA - 0.5 * v; + resultPointB = seg1PointB + 0.5 * v; } else if (projSeg2PointA <= 0 && projSeg2PointB >= 0 && projSeg2PointB <= d1.length()) { - resultPointA = seg1PointA; - resultPointB = seg2PointB; + // Move the contact points halfway between the two segments + resultPointA = seg1PointA + 0.5 * v; + resultPointB = seg2PointB - 0.5 * v; } else if (projSeg2PointA <= 0 && projSeg2PointB >= d1.length()) { - resultPointA = seg1PointA; - resultPointB = seg1PointB; + // Move the contact points halfway between the two segments + resultPointA = seg1PointA + 0.5 * v; + resultPointB = seg1PointB + 0.5 * v; } - else if (projSegment2PointA <= segment1.getLength() && projSegment2PointB <= segment1.getLength()) { - resultPointA = seg2PointA; - resultPointB = seg2PointB; + else if (projSeg2PointA <= d1.length() && projSeg2PointB <= d1.length()) { + // Move the contact points halfway between the two segments + resultPointA = seg2PointA - 0.5 * v; + resultPointB = seg2PointB - 0.5 * v; } - - - - -} - -// 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