vector3 Class Reference

Represents a vector in the 3-dimensional real space. More...

#include <vector3.h>

List of all members.

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
vector3operator= (const vector3 &v)
 assignment
vector3operator+= (const vector3 &v)
vector3operator-= (const vector3 &v)
vector3operator+= (const double *f)
vector3operator-= (const double *f)
vector3operator *= (const double &c)
vector3operator/= (const double &c)
vector3operator *= (const matrix3x3 &)
 multiplication of matrix and vector
void randomUnitVector (OBRandom *oeRand=0L)
 create a random unit vector
vector3normalize ()
 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


Detailed Description

Represents a vector in the 3-dimensional real space.

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 v1,v2,v3;
v1 = VX;
v2 = VY;
v3 = cross(v1,v2);
v3 *= 2.5;
v3.normalize();


Constructor & Destructor Documentation

vector3 ( const double  x = 0.0,
const double  y = 0.0,
const double  z = 0.0 
) [inline]

Constructor.

vector3 ( const vector3 v  )  [inline]

Copy Constructor.


Member Function Documentation

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.

Warning:
This method is primarily designed to facilitate the integration ('Open Babelization') of code that uses arrays of doubles rather than the vector class. Due to the error checks the method is of course very slow and should therefore be avoided in production code.

vector3& operator= ( const vector3 v  )  [inline]

assignment

vector3& operator+= ( const vector3 v  )  [inline]

vector3& operator-= ( const vector3 v  )  [inline]

vector3& operator+= ( const double *  f  )  [inline]

vector3& operator-= ( const double *  f  )  [inline]

vector3& operator *= ( const double &  c  )  [inline]

vector3& operator/= ( const double &  c  )  [inline]

vector3 & operator *= ( const matrix3x3 m  ) 

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.

Parameters:
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().

Warning:
If length() is very close to zero, but not == 0.0, this method may behave in unexpected ways and return almost random results; details may depend on your particular floating point implementation. The use of this method is therefore highly discouraged, unless you are certain that length() is in a reasonable range, away from 0.0 (Stefan Kebekus)
Deprecated:
This method will probably replaced by a safer algorithm in the future.
Todo:
Replace this method with a more fool-proof version.
Returns:
a reference to *this

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.

Warning:
If the entries of the *this (in particular the z-component) are very close to zero, but not == 0.0, this method may behave in unexpected ways and return almost random results; details may depend on your particular floating point implementation. The use of this method is therefore highly discouraged, unless you are certain that all components of this are in a reasonable range, away from 0.0 (Stefan Kebekus)
Deprecated:
This method will probably replaced by a safer algorithm in the future.
Todo:
Replace this method with a more fool-proof version that does not call exit()
Parameters:
res a reference to a vector where the result will be stored


Friends And Related Function Documentation

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>"

int operator== ( const vector3 v1,
const vector3 v2 
) [friend]

int operator!= ( const vector3 v1,
const vector3 v2 
) [friend]

vector3 operator+ ( const vector3 v1,
const vector3 v2 
) [friend]

vector addition

vector3 operator- ( const vector3 v1,
const vector3 v2 
) [friend]

vector subtraction

vector3 operator- ( const vector3 v  )  [friend]

unary minus

vector3 operator * ( const double &  c,
const vector3 v 
) [friend]

multiplication with a scalar

vector3 operator * ( const vector3 v,
const double &  c 
) [friend]

multiplication with a scalar

vector3 operator/ ( const vector3 v,
const double &  c 
) [friend]

division by a scalar

vector3 operator * ( const matrix3x3 m,
const vector3 v 
) [friend]

multiplication of matrix and vector

calculates the product m*v of the matrix m and the column vector represented by v

double dot ( const vector3 v1,
const vector3 v2 
) [friend]

dot product of two vectors

vector3 cross ( const vector3 v1,
const vector3 v2 
) [friend]

cross product of two vectors

double vectorAngle ( const vector3 v1,
const vector3 v2 
) [friend]

calculate angle between vectors

This method calculates the angle between two vectors

Warning:
If length() of any of the two vectors is == 0.0, this method will divide by zero. If the product of the length() of the two vectors is very close to 0.0, but not == 0.0, this method may behave in unexpected ways and return almost random results; details may depend on your particular floating point implementation. The use of this method is therefore highly discouraged, unless you are certain that the length()es are in a reasonable range, away from 0.0 (Stefan Kebekus)
Deprecated:
This method will probably replaced by a safer algorithm in the future.
Todo:
Replace this method with a more fool-proof version.
Returns:
the angle in degrees (0-360)

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.


The documentation for this class was generated from the following files: