This reference page is linked to from the following overview topics: Math and Geometry Utilities.
Represents a 3D vector or point with S23E8 floating point elements.
CurveBrush/CurveCreator.h, MeshDisplace/displacer.h, and PLYImport/Importer.cpp.
#include <math.h>
Public Member Functions |
|
Vector (void) throw () | |
Constructs the vector with zero values.
|
|
Vector (float fX, float fY, float fZ=0.0f) throw () | |
Constructs the vector with specified values.
|
|
Vector (const Vector &vVector) throw () | |
Copy constructor. |
|
Vector (const char *pVector) throw () | |
Construct the vector from a pointer to 8bit
signed data. |
|
Vector (const short *pVector) throw () | |
Construct the vector from a pointer to 16bit
signed data. |
|
Vector & | Set (float fX, float fY, float fZ) throw () |
Sets the values of the vector elements and
returns the vector. |
|
Vector & | Clear (void) throw () |
Zeros all the components of the
Vector, then returns it. |
|
Vector & | Normalize (void) throw () |
Normalizes the vector and returns it.
|
|
Vector & | NormalizeApprox (void) throw () |
Normalizes the vector and returns it.
|
|
Vector | Normalized (void) const throw () |
Returns a normalized version of the vector,
without changing this vector. |
|
Vector & | MakeOrthogonal (const Vector &vBase) |
Makes this vector orthogonal to the given
vBase vector and normalizes it. |
|
Vector & | SetLength (float fLength) |
Sets the vector to the given length, without
changing its direction. |
|
Vector & | RotateOrthogonal (const Vector &vBase) |
Rotates this vector to be orthogonal to
vBase without changing its length, and returns it. |
|
float | LengthSquare (void) const |
Returns the square of the length of the
vector. |
|
float | Length () const throw () |
Returns the length of the vector. |
|
float | Length2D () const throw () |
Returns the 2D length of the vector,
ignoring the z element. |
|
float | DistanceFrom (const Vector &v) const |
Returns the distance between two points
(this and another, represented as
Vector objects). |
|
float | DistanceFromLine (const Vector &v0, const Vector &v1) const |
Returns the shortest distance between this
point and a line defined by two other points (all points
represented by vector objects). |
|
float | DistanceFromSegment (const Vector &v0, const Vector &v1) const |
Returns the distance between this point and
a line segment defined by the two ending points. |
|
float | DistanceFromTriangleSquared (const Vector &v0, const Vector &v1, const Vector &v2, float *aBaryCoords=0) const |
Returns the squared distance from this point
to the closest point on the triangle defined by v0, v1, v2.
|
|
const Vector & | Relocate2D (const Vector &v0, const Vector &v1) |
Converts this (2d) vector to represent
itself as a linear combination of the supplied basis vectors.
|
|
void | Relocate (const Vector &v0, const Vector &v1, const Vector &v2) |
Converts this vector to represent itself as
a linear combination of the supplied basis vectors. |
|
bool | Relocate2DQuad (const Vector &v0, const Vector &v1, const Vector &v2, const Vector &v3) |
This operation calculates the baricentric
coordinates inside a quad where the quad corners are v0,v1,v2,v3.
|
|
bool | RelocateQuad (const Vector &v0, const Vector &v1, const Vector &v2, const Vector &v3) |
This operation calculates the baricentric
coordinates inside a quad where the quad corners are v0,v1,v2,v3.
|
|
float | AngleCos (const Vector &v1) const throw () |
Returns the cosine of the angle between this
vector and the one passed in. |
|
Vector | Minimum (const Vector &o) |
Returns the minimum of this and the argument
vector. |
|
Vector | Maximum (const Vector &o) |
Returns the maximum of this and the argument
vector. |
|
Vector | operator- (void) const throw () |
Returns the inverse of the vector. |
|
Vector | operator+ (float f) const throw () |
Returns the sum of a vector and a scalar.
|
|
Vector | operator+ (const Vector &v) const throw () |
Returns the sum of two vectors. |
|
Vector | operator- (const Vector &v) const throw () |
Returns the difference between two
vectors/points. |
|
Vector | operator* (const Vector &v) const throw () |
Returns the product of two vectors by
components. |
|
Vector | operator* (float f) const throw () |
Returns the product of the vector and a
scalar. |
|
Vector | operator/ (const Vector &v) const throw () |
Returns the quotient of two vectors by
components. |
|
Vector | operator/ (float f) const throw () |
Returns the quotient of a vector and a
scalar. |
|
Vector | operator* (int i) const throw () |
Returns the product of a vector and an
integer. |
|
Vector | operator/ (int i) const throw () |
Returns the quotient of a vector and an
integer. |
|
Vector | operator/ (unsigned int i) const throw () |
Returns the quotient of a vector and an
unsigned integer. |
|
float | operator| (const Vector &v) const throw () |
Returns the dot product of two vectors.
|
|
Vector | operator& (const Vector &v) const |
Returns the cross product of two vectors.
|
|
bool | operator== (const Vector &v) const throw () |
Returns true if the two vectors are
identical, false otherwise. |
|
bool | operator!= (const Vector &v) const throw () |
Returns true if the two vectors are
different, false otherwise. |
|
operator bool (void) const throw () | |
Returns true if the vector is not a
zero vector, false otherwise. |
|
bool | operator! (void) const throw () |
Returns true if the vector is a zero
vector, false otherwise. |
|
Vector & | operator= (const Vector &v) |
Sets this vector to equal another one and
returns it. |
|
Vector & | operator<< (const Vector &v) |
Sets this vector to equal another one and
returns it. |
|
Vector & | operator-= (const Vector &v) throw () |
Subtracts the component values of another
vector from this one's, and returns the result. |
|
Vector & | operator+= (const Vector &v) throw () |
Adds another vector to this one and returns
the result. |
|
Vector & | operator*= (float f) |
Multiplies the components of the vector with
a scalar value and returns the result. |
|
Vector & | operator*= (const Vector &v) |
Multiplies the vector with another vector by
components and returns the result. |
|
Vector & | operator/= (float f) |
Divides the vector by a scalar and returns
the result. |
|
float & | operator[] (int i) throw () |
Returns a individual components of the
vector. |
|
float & | operator[] (unsigned int i) throw () |
Returns a component of the vector. |
|
operator const float * (void) const | |
Returns a pointer to the data of the vector.
Do not delete this pointer. |
|
Public Attributes |
|
union { | |
struct { | |
float m_fX | |
float m_fY | |
float m_fZ | |
} | |
struct { | |
float x | |
float y | |
float z | |
} | |
float m_aCoors [3] | |
}; |
Vector | ( | void | ) | throw () [inline] |
Vector | ( | float | fX, |
float | fY, | ||
float | fZ = 0.0f |
||
) | throw () [inline] |
Vector | ( | const char * | pVector | ) | throw () [inline] |
Vector | ( | const short * | pVector | ) | throw () [inline] |
Vector& Set | ( | float | fX, |
float | fY, | ||
float | fZ | ||
) | throw () [inline] |
Vector& Clear | ( | void | ) | throw () [inline] |
Vector& Normalize | ( | void | ) | throw () |
Normalizes the vector and returns it.
If the vector is zero length, it is set to (0,1,0)
Vector& NormalizeApprox | ( | void | ) | throw () |
Normalizes the vector and returns it.
If the vector is zero length, it is set to (0,1,0) TO BE REMOVED. This was an experiment at improving speed in exchange for accurracy.
Vector Normalized | ( | void | ) | const throw () |
Returns a normalized version of the vector, without changing this vector.
Makes this vector orthogonal to the given vBase vector and normalizes it.
Returns the vector.
The resulting vector will lie on the plane defined by the original value of this vector, and vBase.
Vector& SetLength | ( | float | fLength | ) | [inline] |
Sets the vector to the given length, without changing its direction.
If the vector is of zero length, then it is arbitrarily made parallel to the Y axis.
Definition at line 94 of file math.h.
{ Normalize(); operator *=( fLength ); return *this; };
Rotates this vector to be orthogonal to vBase without changing its length, and returns it.
The resulting vector will lie on the plane defined by the original value of this vector, and vBase.
Definition at line 103 of file math.h.
{ float fLen = Length(); MakeOrthogonal( vBase ); SetLength( fLen ); return *this; };
float LengthSquare | ( | void | ) | const [inline] |
float Length | ( | ) | const throw () |
Returns the length of the vector.
float Length2D | ( | ) | const throw () |
Returns the 2D length of the vector, ignoring the z element.
float DistanceFrom | ( | const Vector & | v | ) | const [inline] |
Returns the distance between two points (this and another, represented as Vector objects).
Definition at line 118 of file math.h.
{ return operator -(v).Length(); };
Returns the shortest distance between this point and a line defined by two other points (all points represented by vector objects).
Returns the distance between this point and a line segment defined by the two ending points.
float DistanceFromTriangleSquared | ( | const Vector & | v0, |
const Vector & | v1, | ||
const Vector & | v2, | ||
float * | aBaryCoords =
0 |
||
) | const |
Returns the squared distance from this point to the closest point on the triangle defined by v0, v1, v2.
Optionally, the barycentric coordinates of the point on the triangle are returned in aBaryCoords, which must be an array of 3 floats, or NULL. To compute the 3d point use: Vector vPoint = v0 * aBaryCoords[0] + v1 * aBaryCoords[1] + v2 * aBaryCoords[2]
Converts this (2d) vector to represent itself as a linear combination of the supplied basis vectors.
Returns the result.
This function works in 2d, ignoring the Z component of all the vectors. The supplied basis vectors must not be parallel.
This method figures out how to express this vector (x,y) as a linear combination of the two vector arguments. X is set to the multiplier on the first vector, and Y to the multiplier on the second vector. So the original vector could be reconstructed from the final one like this: original = x*v0 + y*v1
Converts this vector to represent itself as a linear combination of the supplied basis vectors.
This method figures out how to express this vector (x,y,z) as a linear combination of the three vector arguments. X is set to the multiplier on the first vector, Y to the multiplier on the second vector, and Z to the multiplier on the third. The supplied basis vectors must not be parallel. So the original vector could be reconstructed from the final one like this: original = x*v0 + y*v1 + z*v2
This operation calculates the baricentric coordinates inside a quad where the quad corners are v0,v1,v2,v3.
2d points in this function are represented by 3d Vector objects, with the Z component ignored. This function works in 2d only. If v0, v1, v2 and v3 are the corners of a quad in a 2d space (such as UV space), and this object's (x,y) coordinates represent a point inside that quad, then this function will calculate the baricentric coordinates inside the quad (v0 and v3 are opposite corners). After this operation the following code can calculate the original value stored in the vector (this can help you understand what the function does):
This operation calculates the baricentric coordinates inside a quad where the quad corners are v0,v1,v2,v3.
This is the 3d version of the Relocate2DQuad function. The result will only be correct if the four points lie on the same plane.
float AngleCos | ( | const Vector & | v1 | ) | const throw () [inline] |
Returns the cosine of the angle between this vector and the one passed in.
Vector operator- | ( | void | ) | const throw () [inline] |
Vector operator+ | ( | float | f | ) | const throw () [inline] |
Vector operator* | ( | float | f | ) | const throw () [inline] |
Vector operator/ | ( | float | f | ) | const throw () [inline] |
Returns the quotient of a vector and a scalar.
Definition at line 239 of file math.h.
{ return operator *( 1.0f/f ); };
Vector operator* | ( | int | i | ) | const throw () [inline] |
Returns the product of a vector and an integer.
Definition at line 243 of file math.h.
{ return operator *( float(i) ); };
Vector operator/ | ( | int | i | ) | const throw () [inline] |
Returns the quotient of a vector and an integer.
Definition at line 247 of file math.h.
{ return operator /( float(i) ); };
Vector operator/ | ( | unsigned int | i | ) | const throw () [inline] |
Returns the quotient of a vector and an unsigned integer.
Definition at line 251 of file math.h.
{ return operator /( float(i) ); };
float operator| | ( | const Vector & | v | ) | const throw () [inline] |
bool operator== | ( | const Vector & | v | ) | const throw () [inline] |
bool operator!= | ( | const Vector & | v | ) | const throw () [inline] |
Returns true if the two vectors are different, false otherwise.
Definition at line 275 of file math.h.
{ return !operator ==( v ); };
operator bool | ( | void | ) | const throw () [inline] |
bool operator! | ( | void | ) | const throw () [inline] |
Returns true if the vector is a zero vector, false otherwise.
Definition at line 282 of file math.h.
{ return !operator bool(); };
Vector& operator*= | ( | float | f | ) | [inline] |
Vector& operator/= | ( | float | f | ) | [inline] |
Divides the vector by a scalar and returns the result.
Definition at line 311 of file math.h.
{ return operator *=( 1.0f/f ); };
float& operator[] | ( | int | i | ) | throw () [inline] |
float& operator[] | ( | unsigned int | i | ) | throw () [inline] |
operator const float * | ( | void | ) | const [inline] |
float m_fX |
float m_fY |
float m_fZ |
float x |
float y |
float z |
float m_aCoors[3] |
union { ... } |