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

This commit is contained in:
chappuis.daniel 2009-12-22 16:23:09 +00:00
parent 4b1dbb2f47
commit 2bd9701164
3 changed files with 9 additions and 2 deletions

View File

@ -55,6 +55,7 @@ class Vector3D {
Vector3D getOpposite() const; // Return the vector in the opposite direction Vector3D getOpposite() const; // Return the vector in the opposite direction
double scalarProduct(const Vector3D& vector) const; // Scalar product of two vectors double scalarProduct(const Vector3D& vector) const; // Scalar product of two vectors
Vector3D crossProduct(const Vector3D& vector) const; // Cross product of two vectors Vector3D crossProduct(const Vector3D& vector) const; // Cross product of two vectors
bool isParallelWith(const Vector3D& vector) const; // Return true if two vectors are parallel
// --- Overloaded operators --- // // --- Overloaded operators --- //
Vector3D operator+(const Vector3D& vector) const; // Overloaded operator for addition Vector3D operator+(const Vector3D& vector) const; // Overloaded operator for addition
@ -126,6 +127,11 @@ inline Vector3D Vector3D::crossProduct(const Vector3D& vector) const {
return Vector3D(y * vector.z - z * vector.y, z * vector.x - x * vector.z , x * vector.y - y * vector.x); return Vector3D(y * vector.z - z * vector.y, z * vector.x - x * vector.z , x * vector.y - y * vector.x);
} }
// Return true if two vectors are parallel
inline bool Vector3D::isParallelWith(const Vector3D& vector) const {
return (approxEqual(this->scalarProduct(vector), length * vector.getLength()));
}
// Overloaded operator for multiplication between a number and a Vector3D (inline) // Overloaded operator for multiplication between a number and a Vector3D (inline)
inline Vector3D operator * (double number, const Vector3D& vector) { inline Vector3D operator * (double number, const Vector3D& vector) {
// Compute and return the result vector // Compute and return the result vector

View File

@ -22,6 +22,7 @@
// Constant used for the precision // Constant used for the precision
const double EPSILON = 0.00001; const double EPSILON = 0.00001;
const double ONE_MINUS_EPSILON = 0.99999;
// Pi constant // Pi constant
const double PI = 3.14159265; const double PI = 3.14159265;

View File

@ -40,7 +40,7 @@
// function to test if two numbers are (almost) equal // function to test if two numbers are (almost) equal
// We test if two numbers a and b are such that (a-b) are in [-EPSILON; EPSILON] // We test if two numbers a and b are such that (a-b) are in [-EPSILON; EPSILON]
inline bool equal(double a, double b) { inline bool approxEqual(double a, double b) {
double difference = a - b; double difference = a - b;
return (difference < EPSILON && difference > -EPSILON); return (difference < EPSILON && difference > -EPSILON);
} }
@ -80,7 +80,7 @@ inline std::vector<reactphysics3d::Vector3D> movePoints(const std::vector<reactp
// will be another Segment3D. // will be another Segment3D.
inline reactphysics3d::Segment3D computeParallelSegmentsIntersection(const reactphysics3d::Segment3D& segment1, const reactphysics3d::Segment3D& segment2) { inline reactphysics3d::Segment3D computeParallelSegmentsIntersection(const reactphysics3d::Segment3D& segment1, const reactphysics3d::Segment3D& segment2) {
// The two segments should be colinear // The two segments should be colinear
assert(equal(std::abs(segment1.getSegmentVector().scalarProduct(segment2.getSegmentVector())), segment1.getSegmentVector().length() * segment2.getSegmentVector().length())); assert(approxEqual(std::abs(segment1.getSegmentVector().scalarProduct(segment2.getSegmentVector())), segment1.getSegmentVector().length() * segment2.getSegmentVector().length()));
// Result segment // Result segment
reactphysics3d::Segment3D resultSegment; reactphysics3d::Segment3D resultSegment;