#include <Algebra.h>
Basic functionality of a 3D vector. The class is designed to be compatible with standard class for 3D vector SbVec3f used in Open Inventor.
Public Member Functions | |
| TVector () | |
| Default constructor. | |
| TVector (const float v[3]) | |
| Initializing constructor. | |
| TVector (const float x, const float y, const float z) | |
| Initializing constructor. | |
| TVector (const TVector &v) | |
| Copy constructor. | |
| const float * | getValue () const |
| Returns the components of the vector. | |
| void | getValue (float &x, float &y, float &z) const |
| Returns the components of the vector. | |
| TVector & | setValue (const float v[3]) |
| Sets the components of the vector. | |
| TVector & | setValue (const float x, const float y, const float z) |
| Sets the components of the vector. | |
| float & | operator[] (const int i) |
| Returns one component of the vector. | |
| const float & | operator[] (const int i) const |
| Returns one component of the vector. | |
| TVector & | operator *= (const float d) |
| Multiply components of the vector by the scalar value d. | |
| TVector & | operator/= (const float d) |
| Divides components of the vector by the scalar value d. | |
| TVector & | operator+= (const TVector &u) |
| Adds u vector to this vector. | |
| TVector & | operator-= (const TVector &u) |
| Substract u vector from this vector. | |
| TVector | operator- () const |
| Non-destructive operator that returns a vector of the opposite direction. | |
| TVector | cross (const TVector &v) const |
| Returns cross product with vector v. | |
| float | dot (const TVector &v) const |
| Returns dot product with vector v. | |
| bool | equals (const TVector &v, const float sqrTolerance) const |
| Returns true if the vector does not differ from the vector v more than tolerance. | |
| TVector | getClosestAxis () const |
| Returns closest axis of the vector. | |
| float | length () const |
| Returns length of the vector. | |
| float | sqrLength () const |
| Returns square length of the vector. | |
| void | negate () |
| Switches the direction of the vector to the opposite. | |
| float | normalize () |
| Normalizes the length of the vector to the unit. | |
Private Attributes | |
| float | vec [3] |
| Vector data. | |
|
|
Returns cross product with vector v. Returns the cross-product of this vector and the vector v. Time cost: low (one constructor, 6 multiplications, 3 substractions) |
|
|
Returns dot product with vector v. Returns the dot-product of this vector and the vector v. Time cost: very low (3 multiplications, 2 additions) |
|
||||||||||||
|
Returns true if the vector does not differ from the vector v more than tolerance. Compares the vector with vector v to see if distance between their end-points is less or equal to root of sqrTolerance. Time cost: very low (3 multiplications, 2+3 adds/subs, 1 compare) |
|
|
Returns closest axis of the vector. The function find out to which of x,y and z axis this vector is the closest. Then it returns the unit vector in the direction of this axis. |
|
|
Returns length of the vector. Returns the length of the vector. When possible, use sqrLength() instead, because it does not need to compute square root that is CPU expensive operation. Time cost: high (1 square root) |
|
|
Switches the direction of the vector to the opposite. Returns the same vector but of opposite direction. The original vector is not modified. |
|
|
Normalizes the length of the vector to the unit. The function normalizes the vector to the unit length. It returns the original length of the vector before normalization. Time cost: high (1 square root, 1 division) |
|
|
Returns square length of the vector. Returns the square of vector length. sqrLength() is preffered over length(), because it does not need to compute square root that is CPU expensive operation. Time cost: very low (3 mult, 2 adds) |
1.4.6-NO