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

This commit is contained in:
chappuis.daniel 2009-11-29 10:54:35 +00:00
parent ad0cf1debc
commit d8fd9b09b7
6 changed files with 138 additions and 17 deletions

View File

@ -33,3 +33,24 @@ Polygon3D::Polygon3D(const std::vector<Vector3D>& vertexList)
Polygon3D::~Polygon3D() {
}
// TODO : Delete this function if not needed
// Return true if a point is in the same plane and inside the polygon
// Hypothesis : The point has to be on the same plane as the polygon.
/*
bool Polygon3D::isPointInside(const Vector3D& point) const {
// TODO : Implement this method
}
*/
// TODO : Delete this function if not needed
// Return the intersection point between a segment and an egde of the polygon.
// Hypothesis : The segment must be in the same plane as the polygon and it
// must intersection with at least one edge of the polygon.
/*
Vector3D Polygon3D::getEdgeIntersectionWithSegment(const Segment3D& segment) const {
// TODO : Implement this method
}
*/

View File

@ -43,6 +43,9 @@ class Polygon3D {
int getNbVertex() const; // Return the number of vertex of the polygon
Vector3D getVertex(unsigned int index) const throw(std::invalid_argument); // Return a vertex of the polygon
bool isPointInside(const Vector3D& point) const; // Return true if a point is in the same plane and inside the polygon
// TODO : Delete the following function if not needed
//Vector3D getEdgeIntersectionWithSegment(const Segment3D& segment) const; // Return the intersection point between a segment and an egde of the polygon
};
// TODO : Test the Polygon3D class
@ -64,7 +67,7 @@ inline Vector3D Polygon3D::getVertex(unsigned int index) const throw(std::invali
}
}
} // End of the ReactPhysics3D
} // End of the ReactPhysics3D namespace
#endif

View File

@ -29,17 +29,11 @@ Segment3D::Segment3D() {
}
// Constructor with arguments
Segment3D::Segment3D(Vector3D& pointA, Vector3D& pointB) {
Segment3D::Segment3D(const Vector3D& pointA, const Vector3D& pointB) {
this->pointA = pointA;
this->pointB = pointB;
}
// Copy-constructor
Segment3D::Segment3D(const Segment3D& segment)
:pointA(segment.pointA), pointB(segment.pointB) {
}
// Destructor
Segment3D::~Segment3D() {

View File

@ -39,34 +39,51 @@ class Segment3D {
public :
Segment3D(); // Constructor
Segment3D(Vector3D& pointA, Vector3D& pointB); // Constructor with arguments
Segment3D(const Segment3D& segment); // Copy-constructor
Segment3D(const Vector3D& pointA, const Vector3D& pointB); // Constructor with arguments
~Segment3D(); // Destructor
Vector3D getPointA() const; // Return the point A
void setPointA(const Vector3D& pointA); // Set the point A
Vector3D getPointB() const; // Return the point B
void setPointB(const Vector3D& pointB); // Set the point B
Vector3D getSegmentVector() const; // Return the vector between points A and B
double getLength() const; // Return the length of the segment
};
// TODO : Test the Segment3D class
// Return the point A
inline Vector3D Segment3D::getPointA() const {
return pointA;
}
// Set the point A
inline void Segment3D::setPointA(const Vector3D& pointA) {
this->pointA = pointA;
}
// Get the point B
inline Vector3D Segment3D::getPointB() const {
return pointB;
}
// Set the point B
inline void Segment3D::setPointB(const Vector3D& pointB) {
this->pointB = pointB;
}
// Return the vector between points A and B
inline Vector3D Segment3D::getSegmentVector() const {
return (pointB - pointA);
}
// Return the length of the segment
inline double Segment3D::getLength() const {
return (pointB - pointA).length();
}
} // End of the ReactPhysics3D namespace
#endif

View File

@ -52,6 +52,7 @@ class Vector3D {
void setAllValues(double x, double y, double z); // Set all the values of the vector
double length() const; // Return the lenght of the vector
Vector3D getUnit() const throw(MathematicsException); // Return the corresponding unit vector
Vector3D getOpposite() const; // Return the vector in the opposite direction
double scalarProduct(const Vector3D& vector) const; // Scalar product of two vectors
Vector3D crossProduct(const Vector3D& vector) const; // Cross product of two vectors
@ -107,6 +108,12 @@ inline double Vector3D::length() const {
return sqrt(x*x + y*y + z*z);
}
// Return the vector in the opposite direction
// TODO : Test this function
inline Vector3D Vector3D::getOpposite() const {
return (Vector3D(0.0, 0.0, 0.0) - *this);
}
// Scalar product of two vectors (inline)
inline double Vector3D::scalarProduct(const Vector3D& vector) const {
// Compute and return the result of the scalar product

View File

@ -33,6 +33,8 @@
#include "constants.h"
#include "exceptions.h"
#include <cstdio>
#include <cassert>
#include <cmath>
// ---------- Mathematics functions ---------- //
@ -57,4 +59,81 @@ inline reactphysics3d::Vector3D rotateVectorWithQuaternion(const reactphysics3d:
return quaternionResult.vectorV();
}
// TODO : Test this method
// Move a set of points by a given vector.
// The method returns a set of points moved by the given vector.
inline std::vector<reactphysics3d::Vector3D> movePoints(const std::vector<reactphysics3d::Vector3D>& points, const reactphysics3d::Vector3D& vector) {
std::vector<reactphysics3d::Vector3D> result;
// For each point of the set
for (unsigned int i=0; i<points.size(); ++i) {
// Move the point
result.push_back(points.at(i) + vector);
}
// Return the result set of points
return result;
}
// TODO : Test this method
// Return the intersection between two Segment3D that are on the same line. The result of the intersection
// will be another Segment3D.
inline reactphysics3d::Segment3D computeParallelSegmentsIntersection(const reactphysics3d::Segment3D& segment1, const reactphysics3d::Segment3D& segment2) {
// The two segments should be colinear
assert(equal(std::abs(segment1.getSegmentVector().scalarProduct(segment2.getSegmentVector())), segment1.getSegmentVector().length() * segment2.getSegmentVector().length()));
// Result segment
reactphysics3d::Segment3D resultSegment;
// Compute the vector of the line where both segments are
reactphysics3d::Vector3D lineVector = segment1.getSegmentVector();
// 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
assert(!(projSegment2PointA < 0.0 && projSegment2PointB < 0.0));
assert(!(projSegment2PointA > segment1.getLength() && projSegment2PointB > segment1.getLength()));
// 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;
}
else if (projSegment2PointA <= 0 && projSegment2PointB >= 0 && projSegment2PointB <= segment1.getLength()) {
resultSegment.setPointA(segment1.getPointA());
resultSegment.setPointB(segment2.getPointB());
return resultSegment;
}
else if (projSegment2PointA <= 0 && projSegment2PointB >= segment1.getLength()) {
return segment1;
}
else if (projSegment2PointA <= segment1.getLength() && projSegment2PointB <= segment1.getLength()) {
return segment2;
}
// We should never go here
assert(false);
}
// TODO : Delete this method if not needed
// Return the intersection between a Segment3D and a Polygon3D that are on the same plane. The result of the intersection
// will be another Segment3D.
//inline reactphysics3d::Segment3D computeSegmentPolygonIntersection(const reactphysics3d::Segment3D& segment, const reactphysics3d::Polygon3D& polygon) {
// TODO : Implement this method
//}
// TODO : Delete this method if not needed
// Return the intersection between two Polygon3D that are on the same plane. The result of the intersection
// will be another Polygon3D.
//inline reactphysics3d::Polygon3D computePolygonPolygonIntersection(const reactphysics3d::Polygon3D& polygon1, const reactphysics3d::Polygon3D& polygon2) {
// TODO : Implement this method
//}
#endif