#include <vector3.h>
Public Member Functions | |
vector3 (const double x=0.0, const double y=0.0, const double z=0.0) | |
Constructor. | |
vector3 (const vector3 &v) | |
Copy Constructor. | |
void | Set (const double x, const double y, const double z) |
set x,y and z-component of a vector | |
void | Set (const double *c) |
set x,y and z-component of a vector from c[0]..c[2] | |
void | SetX (const double x) |
access function to get the x-coordinate of the vector | |
void | SetY (const double y) |
access function to get the y-coordinate of the vector | |
void | SetZ (const double z) |
access function to get the z-coordinate of the vector | |
void | Get (double *c) |
set c[0]..c[2] to the components of the vector | |
double & | operator[] (unsigned int i) |
access function | |
vector3 & | operator= (const vector3 &v) |
assignment | |
vector3 & | operator+= (const vector3 &v) |
vector3 & | operator-= (const vector3 &v) |
vector3 & | operator+= (const double *f) |
vector3 & | operator-= (const double *f) |
vector3 & | operator *= (const double &c) |
vector3 & | operator/= (const double &c) |
vector3 & | operator *= (const matrix3x3 &) |
multiplication of matrix and vector | |
void | randomUnitVector (OBRandom *oeRand=0L) |
create a random unit vector | |
vector3 & | normalize () |
scales a vector to give it length one. | |
double | length () const |
vector length | |
double | length_2 () const |
vector length squared | |
double | x () const |
access function to get the x-coordinate of the vector | |
double | y () const |
access function to get the y-coordinate of the vector | |
double | z () const |
access function to get the z-coordinate of the vector | |
double | distSq (const vector3 &vv) const |
square to the distance between *this and vv | |
void | createOrthoVector (vector3 &v) const |
creates a vector of length one, orthogonal to *this. | |
Friends | |
std::ostream & | operator<< (std::ostream &, const vector3 &) |
prints a representation of the vector as a row vector of the form "<0.1,1,2>" | |
int | operator== (const vector3 &, const vector3 &) |
int | operator!= (const vector3 &, const vector3 &) |
vector3 | operator+ (const vector3 &v1, const vector3 &v2) |
vector addition | |
vector3 | operator- (const vector3 &v1, const vector3 &v2) |
vector subtraction | |
vector3 | operator- (const vector3 &v) |
unary minus | |
vector3 | operator * (const double &c, const vector3 &v) |
multiplication with a scalar | |
vector3 | operator * (const vector3 &v, const double &c) |
multiplication with a scalar | |
vector3 | operator/ (const vector3 &v, const double &c) |
division by a scalar | |
vector3 | operator * (const matrix3x3 &m, const vector3 &v) |
multiplication of matrix and vector | |
double | dot (const vector3 &, const vector3 &) |
dot product of two vectors | |
vector3 | cross (const vector3 &, const vector3 &) |
cross product of two vectors | |
double | vectorAngle (const vector3 &v1, const vector3 &v2) |
calculate angle between vectors | |
double | CalcTorsionAngle (const vector3 &a, const vector3 &b, const vector3 &c, const vector3 &d) |
calculate the torsion angle between vectors |
The vector3 class was designed to simplify operations with floating point coordinates. To this end many of the common operations have been overloaded for simplicity. Vector addition, subtraction, scalar multiplication, dot product, cross product, magnitude and a number of other utility functions are built in to the vector class. For a full description of the class member functions please consult the header file vector3.h. The following code demonstrates several of the functions of the vector class:
vector3 | ( | const double | x = 0.0 , |
|
const double | y = 0.0 , |
|||
const double | z = 0.0 | |||
) | [inline] |
Constructor.
void Set | ( | const double | x, | |
const double | y, | |||
const double | z | |||
) | [inline] |
set x,y and z-component of a vector
void Set | ( | const double * | c | ) | [inline] |
set x,y and z-component of a vector from c[0]..c[2]
void SetX | ( | const double | x | ) | [inline] |
access function to get the x-coordinate of the vector
void SetY | ( | const double | y | ) | [inline] |
access function to get the y-coordinate of the vector
void SetZ | ( | const double | z | ) | [inline] |
access function to get the z-coordinate of the vector
void Get | ( | double * | c | ) | [inline] |
set c[0]..c[2] to the components of the vector
double & operator[] | ( | unsigned int | i | ) |
access function
This (slow) method allows to access the elements of the vector as if it were an array of doubles. If the index is > 2, then a warning is printed, and the program is terminated via exit(-1). Otherwise, if i is 0, 1 or 2, then a reference to x, y or z is returned, respectively.
vector3& operator+= | ( | const double * | f | ) | [inline] |
vector3& operator-= | ( | const double * | f | ) | [inline] |
vector3& operator *= | ( | const double & | c | ) | [inline] |
vector3& operator/= | ( | const double & | c | ) | [inline] |
multiplication of matrix and vector
calculates the product m*(*this) of the matrix m and the column vector represented by *this
void randomUnitVector | ( | OBRandom * | obRandP = 0L |
) |
create a random unit vector
replaces *this with a random unit vector, which is (supposed to be) uniformly distributed over the unit sphere. Uses the random number generator obRand, or uses the system number generator with a time seed if obRand == NULL.
obRandP | random number generator to use, or 0L, if the system random number generator (with time seed) should be used |
vector3 & normalize | ( | ) |
scales a vector to give it length one.
This method checks if the current vector has length() == 0.0. If so, *this remains unchanged. Otherwise, *this is scaled by 1.0/length().
double length | ( | ) | const [inline] |
vector length
double length_2 | ( | ) | const [inline] |
vector length squared
double x | ( | ) | const [inline] |
access function to get the x-coordinate of the vector
double y | ( | ) | const [inline] |
access function to get the y-coordinate of the vector
double z | ( | ) | const [inline] |
access function to get the z-coordinate of the vector
double distSq | ( | const vector3 & | vv | ) | const [inline] |
square to the distance between *this and vv
equivalent to length_2(*this-vv)
void createOrthoVector | ( | vector3 & | res | ) | const |
creates a vector of length one, orthogonal to *this.
This method checks if the current vector *this is zero (i.e. if all entries == 0.0). If so, a warning message is printed, and the whole program is aborted with exit(0). Otherwise, a vector of length one is generated, which is orthogonal to *this, and stored in v. The resulting vector is not random.
res | a reference to a vector where the result will be stored |
std::ostream& operator<< | ( | std::ostream & | co, | |
const vector3 & | v | |||
) | [friend] |
prints a representation of the vector as a row vector of the form "<0.1,1,2>"
multiplication of matrix and vector
calculates the product m*v of the matrix m and the column vector represented by v
calculate angle between vectors
This method calculates the angle between two vectors
double CalcTorsionAngle | ( | const vector3 & | a, | |
const vector3 & | b, | |||
const vector3 & | c, | |||
const vector3 & | d | |||
) | [friend] |
calculate the torsion angle between vectors
This function calculates the torsion angle of three vectors, represented by four points A--B--C--D, i.e. B and C are vertexes, but none of A--B, B--C, and C--D are colinear. A "torsion angle" is the amount of "twist" or torsion needed around the B--C axis to bring A--B into the same plane as B--C--D. The torsion is measured by "looking down" the vector B--C so that B is superimposed on C, then noting how far you'd have to rotate A--B to superimpose A over D. Angles are + in the anticlockwise direction. The operation is symmetrical in that if you reverse the image (look from C to B and rotate D over A), you get the same answer.