git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@246 92aac97c-a6ce-11dd-a772-7fcde58d38e6

This commit is contained in:
chappuis.daniel 2010-01-02 23:54:36 +00:00
parent 50ab396882
commit fb416001ad

View File

@ -93,53 +93,64 @@ inline std::vector<reactphysics3d::Vector3D> movePoints(const std::vector<reactp
// Return the result set of points // Return the result set of points
return result; return result;
} }
*/
// TODO : Test this method // TODO : Test this method
// Return the intersection between two Segment3D that are on the same line. The result of the intersection // Compute the intersection between two parallel segments (the first segment is between the points "seg1PointA" and "seg1PointB" and the second
// will be another Segment3D. // segment is between the points "seg2PointA" and "seg2PointB"). The result is the segment intersection (represented by the points "resultPointA"
inline reactphysics3d::Segment3D computeParallelSegmentsIntersection(const reactphysics3d::Segment3D& segment1, const reactphysics3d::Segment3D& segment2) { // and "resultPointB". Because the two given segments don't have to be on the same exact line, the result intersection segment will a segment
// The two segments should be colinear // halway between the first and the second given segments.
assert(approxEqual(std::abs(segment1.getSegmentVector().scalarProduct(segment2.getSegmentVector())), segment1.getSegmentVector().length() * segment2.getSegmentVector().length())); inline void computeParallelSegmentsIntersection(const reactphysics3d::Vector3D& seg1PointA, const reactphysics3d::Vector3D& seg1PointB
const reactphysics3d::Vector3D& seg2PointA, const reactphysics3d::Vector3D& seg2PointB,
reactphysics3d::Vector3D& resultPointA, reactphysics3d::Vector3D& resultPointB) {
// Compute the segment vectors
reactphysics3d::Vector3D d1 = seg1PointB - seg1PointA;
reactphysics3d::Vector3D d2 = seg2PointB - seg2PointA;
// Result segment // The two segments should be parallel
reactphysics3d::Segment3D resultSegment; assert(d1.isParallelWith(d2));
// Compute the vector of the line where both segments are // Compute the projection of the two points of the second segment onto the vector of segment 1
reactphysics3d::Vector3D lineVector = segment1.getSegmentVector(); double projSeg2PointA = d1.getUnit().scalarProduct(seg2PointA() - seg1PointA());
double projSeg2PointB = d1.getUnit().scalarProduct(seg2PointB() - seg1PointA());
// Compute the projection of the two points of the second segment on the line
double projSegment2PointA = lineVector.getUnit().scalarProduct(segment2.getPointA() - segment1.getPointA());
double projSegment2PointB = lineVector.getUnit().scalarProduct(segment2.getPointB() - segment1.getPointA());
std::cout << "Segment 2 - Proj A : " << projSegment2PointA << std::endl;
std::cout << "Segment 2 - Proj B : " << projSegment2PointB << std::endl;
std::cout << "Segment 1 - length : " << segment1.getLength() << std::endl;
// The projections intervals should intersect // The projections intervals should intersect
assert(!(projSegment2PointA < 0.0 && projSegment2PointB < 0.0)); assert(!(projSeg2PointA < 0.0 && projSegment2PointB < 0.0));
assert(!(projSegment2PointA > segment1.getLength() && projSegment2PointB > segment1.getLength())); 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 // Return the segment intersection according to the configuration of two projection intervals
if (projSegment2PointA >= 0 && projSegment2PointA <= segment1.getLength() && projSegment2PointB >= segment1.getLength()) { if (projSeg2PointA >= 0 && projSeg2PointA <= d1.length() && projSeg2PointB >= d1.length()) {
resultSegment.setPointA(segment2.getPointA()); resultPointA = seg2PointA;
resultSegment.setPointB(segment1.getPointB()); resultPointB = seg1PointB;
return resultSegment;
// Move the contact points halfway between the two segments
} }
else if (projSegment2PointA <= 0 && projSegment2PointB >= 0 && projSegment2PointB <= segment1.getLength()) { else if (projSeg2PointA <= 0 && projSeg2PointB >= 0 && projSeg2PointB <= d1.length()) {
resultSegment.setPointA(segment1.getPointA()); resultPointA = seg1PointA;
resultSegment.setPointB(segment2.getPointB()); resultPointB = seg2PointB;
return resultSegment;
} }
else if (projSegment2PointA <= 0 && projSegment2PointB >= segment1.getLength()) { else if (projSeg2PointA <= 0 && projSeg2PointB >= d1.length()) {
return segment1; resultPointA = seg1PointA;
resultPointB = seg1PointB;
} }
else if (projSegment2PointA <= segment1.getLength() && projSegment2PointB <= segment1.getLength()) { 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 #endif