From 2bd970116452d2b1d634856d6acfb3a83aa05929 Mon Sep 17 00:00:00 2001 From: "chappuis.daniel" Date: Tue, 22 Dec 2009 16:23:09 +0000 Subject: [PATCH] git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@231 92aac97c-a6ce-11dd-a772-7fcde58d38e6 --- sources/reactphysics3d/mathematics/Vector3D.h | 6 ++++++ sources/reactphysics3d/mathematics/constants.h | 1 + sources/reactphysics3d/mathematics/mathematics.h | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/sources/reactphysics3d/mathematics/Vector3D.h b/sources/reactphysics3d/mathematics/Vector3D.h index 42b7bd73..5ea1b49e 100644 --- a/sources/reactphysics3d/mathematics/Vector3D.h +++ b/sources/reactphysics3d/mathematics/Vector3D.h @@ -55,6 +55,7 @@ class Vector3D { 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 + bool isParallelWith(const Vector3D& vector) const; // Return true if two vectors are parallel // --- Overloaded operators --- // 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 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) inline Vector3D operator * (double number, const Vector3D& vector) { // Compute and return the result vector diff --git a/sources/reactphysics3d/mathematics/constants.h b/sources/reactphysics3d/mathematics/constants.h index 8c419aa4..942fe552 100644 --- a/sources/reactphysics3d/mathematics/constants.h +++ b/sources/reactphysics3d/mathematics/constants.h @@ -22,6 +22,7 @@ // Constant used for the precision const double EPSILON = 0.00001; +const double ONE_MINUS_EPSILON = 0.99999; // Pi constant const double PI = 3.14159265; diff --git a/sources/reactphysics3d/mathematics/mathematics.h b/sources/reactphysics3d/mathematics/mathematics.h index d032e08f..f8bb7caa 100644 --- a/sources/reactphysics3d/mathematics/mathematics.h +++ b/sources/reactphysics3d/mathematics/mathematics.h @@ -40,7 +40,7 @@ // 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] -inline bool equal(double a, double b) { +inline bool approxEqual(double a, double b) { double difference = a - b; return (difference < EPSILON && difference > -EPSILON); } @@ -80,7 +80,7 @@ inline std::vector movePoints(const std::vector