51 #pragma warning( disable : 4231 )
66 template<
class Type >
69 template<
class Type >
92 inline Vector3d( Type x, Type y, Type z ): _x(x), _y(y), _z(z) {}
108 inline Type
x()
const {
return _x; }
115 inline Type
y()
const {
return _y; }
122 inline Type
z()
const {
return _z; }
131 inline void set( Type x, Type y, Type z ) {
183 assert( i >= 0 && i <= 2 &&
"Invalid index for Vector3" );
184 return i == 0 ? _x : ( i == 1 ? _y : _z );
195 assert( i >= 0 && i <= 2 &&
"Invalid index for Vector3" );
196 return i == 0 ? _x : ( i == 1 ? _y : _z );
203 _x = _y = _z = (Type)0;
227 return _x * v.
_x + _y * v.
_y + _z * v.
_z;
251 const float invS = 1.f / s;
288 return _x == v.
_x && _y == v.
_y && _z == v.
_z;
300 return _x != v.
_x || _y != v.
_y || _z != v.
_z;
325 const float invS = 1.f / s;
371 float len = sqrtf( _x * _x + _y * _y + _z * _z );
403 float newY = _y, newZ = _z;
404 rotatePair( angle, &newY, &newZ );
415 float newX = _x, newZ = _z;
416 rotatePair( angle, &newX, &newZ );
427 float newX = _x, newY = _y;
428 rotatePair( -angle, &newX, &newY );
440 assert ( abs( v ) > 0.999 && abs( v ) < 1.001 );
441 Type c = cos( angle );
442 Type s = sin( angle );
445 Type vx = _x * (v.
_x * v.
_x * omc + c) + _y * (v.
_y * v.
_x * omc + v.
_z * s) + _z * (v.
_z * v.
_x * omc - v.
_y * s);
446 Type vy = _x * (v.
_x * v.
_y * omc - v.
_z * s) + _y * (v.
_y * v.
_y * omc + c) + _z * (v.
_z * v.
_y * omc + v.
_x * s);
447 Type vz = _x * (v.
_x * v.
_z * omc + v.
_y * s) + _y * (v.
_y * v.
_z * omc - v.
_x * s) + _z * (v.
_z * v.
_z * omc + c);
458 assert ( abs( v ) > 0.999 && abs( v ) < 1.001 );
459 Type c = cos( angle );
463 Type vx = _x * (v.
_x * v.
_x * omc + c) + _y * (v.
_y * v.
_x * omc + v.
_z * s) + _z * (v.
_z * v.
_x * omc - v.
_y * s);
464 Type vy = _x * (v.
_x * v.
_y * omc - v.
_z * s) + _y * (v.
_y * v.
_y * omc + c) + _z * (v.
_z * v.
_y * omc + v.
_x * s);
465 Type vz = _x * (v.
_x * v.
_z * omc + v.
_y * s) + _y * (v.
_y * v.
_z * omc - v.
_x * s) + _z * (v.
_z * v.
_z * omc + c);
479 return sqrt( _x * _x + _y * _y + _z * _z );
491 _z * v.
_x - _x * v.
_z,
492 _x * v.
_y - _y * v.
_x);
503 float dx = _x - p.
_x;
504 float dy = _y - p.
_y;
505 float dz = _z - p.
_z;
506 return sqrtf( dx * dx + dy * dy + dz * dz );
517 inline float distance(
float x,
float y,
float z )
const {
521 return sqrtf( dx * dx + dy * dy + dz * dz );
532 float dx = _x - p.
_x;
533 float dy = _y - p.
_y;
534 float dz = _z - p.
_z;
535 return dx * dx + dy * dy + dz * dz ;
550 return dx * dx + dy * dy + dz * dz;
576 void rotatePair(
float angle,
float * x,
float * y )
const {
577 float c = cos( angle );
578 float s = sin( angle );
579 float newX = c * (*x) + s * (*y);
580 float newY = c * (*y) - s * (*x);
595 typedef Vector3d<float>
Vector3;
610 template<
class Type >
619 MATHEXTERN
template MENGE_API Vector3d<float> operator*(
float s,
const Vector3d<float>& v);
630 template<
class Type >
631 inline MENGE_API Logger& operator<<(Logger& logger, const Vector3d<Type>& v ) {
632 logger <<
"(" << v.x() <<
"," << v.y() <<
", " << v.z() <<
")";
646 template<
class Type >
647 inline MENGE_API std::ostream& operator<<(std::ostream& os, const Vector3d<Type>& v ) {
648 os <<
"(" << v.x() <<
"," << v.y() <<
", " << v.z() <<
")";
656 MATHEXTERN
template MENGE_API Logger& operator<<(Logger& os, const Vector3d<float>& v );
665 template<
class Type >
666 inline MENGE_API Type abs(
const Vector3d<Type>& v ) {
667 return std::sqrt( v * v );
674 MATHEXTERN
template MENGE_API
float abs(
const Vector3d<float>& v );
684 template<
class Type >
685 inline MENGE_API Type absSq(
const Vector3d<Type>& v ) {
693 MATHEXTERN
template MENGE_API
float absSq(
const Vector3d<float>& v );
703 template<
class Type >
704 inline MENGE_API Vector3d<Type> norm(
const Vector3d<Type>& vector ) {
705 Type mag = abs( vector );
710 return Vector3d<Type>( 1.f, 0.f, 0.f );
720 MATHEXTERN
template MENGE_API Vector3d<float> norm(
const Vector3d<float>& vector );
732 template<
class Type >
733 inline MENGE_API
bool equivalent(
const Vector3d<Type> & v1,
const Vector3d<Type> & v2,
float threshSqd=0.000001f ) {
734 return absSq( v1 - v2 ) < threshSqd;
741 MATHEXTERN
template MENGE_API
bool equivalent(
const Vector3d<float> & v1,
const Vector3d<float> & v2,
float threshSqd );
759 #pragma warning( default : 4231 )
Vector3d & operator/=(float s)
Perform in-place scalar division on this vector.
Definition: Vector3.h:324
Vector3d rotateY(float angle) const
Rotate the vector around the y axis.
Definition: Vector3.h:414
Type _x
x-component of the vector
Definition: Vector3.h:556
The core namespace. All elements of Menge are contained in this namespace.
Definition: AgentGenerator.cpp:43
Vector3d(const Vector3d &v)
Copy constructor.
Definition: Vector3.h:99
float distance(float x, float y, float z) const
Compute the distance from this vector to another point.
Definition: Vector3.h:517
Vector3d & operator+=(const Vector3d &v)
Perform in-place vector addition on this vector.
Definition: Vector3.h:338
float distanceSq(const Vector3d &p) const
Compute the squared-distance from this vector to another point.
Definition: Vector3.h:531
Sets up the proper compiler directives for platform and dll export/import.
Vector3d operator-(const Vector3d &v) const
Computes the vector difference of this vector with the given vector.
Definition: Vector3.h:275
Vector3d & operator-=(const Vector3d &v)
Perform in-place vector subtraction on this vector.
Definition: Vector3.h:351
Vector3d< Type > operator*(float s) const
Computes the scalar multiplication of this vector with the given scalar value.
Definition: Vector3.h:238
Type y() const
Get the y-value.
Definition: Vector3.h:115
Type _y
y-component of the vector
Definition: Vector3.h:561
float distanceSq(float x, float y, float z) const
Compute the squared-distance from this vector to another point.
Definition: Vector3.h:546
void rotateV_ip(Type angle, const Vector3d &v)
Rotate the vector around an arbitrary vector - change the vector in place.
Definition: Vector3.h:457
A compilation of file system operations.
Type _z
z-component of the vector
Definition: Vector3.h:566
void normalize()
Normalize the vector in place.
Definition: Vector3.h:370
MENGE_API const float EPS
Suitably small number for testing for functional zero values.
Definition: geomQuery.cpp:52
bool operator!=(const Vector3d &v) const
Reports if this vector is the different from the given vector.
Definition: Vector3.h:299
float operator*(const Vector3d &v) const
Computes the dot product of this vector with the given vector.
Definition: Vector3.h:226
void set(const Vector3d &v)
Set the x-, y- and z-values from a vector.
Definition: Vector3.h:142
void set(Type x, Type y, Type z)
Set the x- and y-values from scalar values.
Definition: Vector3.h:131
Type & operator[](const int i)
Index-style access to vector components as a reference.
Definition: Vector3.h:194
Type operator[](const int i) const
Index-style access to vector components.
Definition: Vector3.h:182
Type Length() const
Compute the magnitude (aka length) of the vector.
Definition: Vector3.h:478
The specificaiton of a message logger for menge, such that all messages to the system get properly re...
Some common mathematical constants.
Vector3d(Type x, Type y, Type z)
Constructor with arguments.
Definition: Vector3.h:92
Vector3d rotateX(float angle) const
Rotate the vector around the x axis.
Definition: Vector3.h:402
The namespace for math primitives for simulation and visualization.
float distance(const Vector3d &p) const
Compute the distance from this vector to another point.
Definition: Vector3.h:502
Vector3d rotateV(Type angle, const Vector3d &v) const
Rotate the vector around an arbitrary vector.
Definition: Vector3.h:439
Vector3d cross(const Vector3d< Type > &v)
Cross product of this vector with the given vector this x v.
Definition: Vector3.h:489
Vector3d()
Default constructor. It does NOT initialize the fields.
Definition: Vector3.h:83
Vector3d< Type > operator-() const
Vector negation. Creates a new vector which is the negation of this vector.
Definition: Vector3.h:214
void setZ(Type z)
Set the z-value.
Definition: Vector3.h:171
bool operator==(const Vector3d &v) const
Reports if this vector is the same as the given vector.
Definition: Vector3.h:287
Logger logger
Globally available Logger.
Definition: Logger.cpp:49
Type x() const
Get the x-value.
Definition: Vector3.h:108
Type z() const
Get the z-value.
Definition: Vector3.h:122
void setX(Type x)
Set the x-value.
Definition: Vector3.h:153
void negate()
Negate the vector in place.
Definition: Vector3.h:361
void zero()
Set the vector to zero.
Definition: Vector3.h:202
void setY(Type y)
Set the y-value.
Definition: Vector3.h:162
void SumScale(Type s, const Vector3d &v)
Adds in a scaled version of another vector this += s * v.
Definition: Vector3.h:388
Vector3d & operator*=(float s)
Perform in-place scalar multiplication on this vector.
Definition: Vector3.h:311
Vector3d operator+(const Vector3d &v) const
Computes the vector sum of this vector with the given vector.
Definition: Vector3.h:263
Templated vector in R3.
Definition: Vector3.h:67
Vector3d< Type > operator/(float s) const
Computes the scalar division of this vector with the given scalar value.
Definition: Vector3.h:250
Vector3d rotateZ(float angle) const
Rotate the vector around the z axis.
Definition: Vector3.h:426