MTK++ Latest version: 0.2.0

Public Member Functions | Protected Attributes | Friends
MTKpp::vector3d Class Reference

A 3-dimensional vector class. More...

#include <mtkpp/src/Utils/vector3d.h>

List of all members.

Public Member Functions

 vector3d ()
 vector3d Constructor
 vector3d (double x, double y, double z)
 vector3d Constructor
 vector3d (double xyz)
 vector3d Constructor
void set (double x, double y, double z)
 Set x, y, and z coordinates.
void setX (double x)
 Set x coordinate to this value.
void setY (double y)
 Set y coordinate to this value.
void setZ (double z)
 Set z coordinate to this value.
double getX ()
 Get x coordinate.
double getY ()
 Get y coordinate.
double getZ ()
 Get z coordinate.
double & operator[] (int i)
 Access coordinate as array.
vector3doperator= (const double &value)
 Set vector equal to constant.
void operator+= (const vector3d &rhs)
 Add another vector3d object to this.
void operator-= (const vector3d &rhs)
 Subtract another vector3d object to this.
void operator*= (const double &value)
 Multiply vector3d by a constant.
void operator/= (const double &value)
 Divide vector3d by a constant.
double length ()
 Return the magnitude of a vector.
double length_squared ()
 Returns the square of the magnitude.
vector3d unit ()
 Returns the unit vector.
double dist (const vector3d &v2)
 Return the "distance" between two vectors.
double dist2 (const vector3d &v2)
 Return the square of the "distance" between two vectors.
void rotateX (const double &ang)
 Rotate about the X-axis.
void rotateX (const double &ang, const vector3d &o)
 Rotate about the X-axis, with origin o.
void rotateY (const double &ang)
 Rotate about the Y-axis.
void rotateY (const double &ang, const vector3d &o)
 Rotate about the Y-axis, with origin o.
void rotateZ (const double &ang)
 Rotate about the Z-axis.
void rotateZ (const double &ang, const vector3d &o)
 Rotate about the Z-axis, with origin o.
void rotateXYZ (const double R[9], const vector3d &o)
 Rotate xyz according to the rotation matrix R with origin o.

Protected Attributes

double X
 X coordinate.
double Y
 Y coordinate.
double Z
 Z coordinate.

Friends

vector3d operator- (const vector3d &lhs)
 Set negative of the vector.
bool operator== (const vector3d &lhs, const vector3d &rhs)
 Checks equality of two vectors.
bool operator!= (const vector3d &lhs, const vector3d &rhs)
 Checks equality of two vectors.
vector3d operator+ (const vector3d &lhs, const vector3d &rhs)
 Add two vectors together.
vector3d operator- (const vector3d &lhs, const vector3d &rhs)
 Subtract two vectors.
double operator* (const vector3d &lhs, const vector3d &rhs)
 Calculate the dot-product of two vectors.
vector3d operator+ (const vector3d &lhs, const double &scalar)
 Add a vector to a scalar.
vector3d operator+ (const double &scalar, const vector3d &rhs)
 Add a scalar to a vector.
vector3d operator- (const vector3d &lhs, const double &scalar)
 Subtract a scalar from a vector.
vector3d operator- (const double &scalar, const vector3d &rhs)
 Subtract a vector from a scalar.
vector3d operator* (const vector3d &lhs, const double &scalar)
 Return the product of a vector with a scalar.
vector3d operator* (const double &scalar, const vector3d &rhs)
 Return the product of a scalar with a vector.
vector3d operator/ (const vector3d &lhs, const double &scalar)
 Divide a vector with a scalar.
std::ostream & operator<< (std::ostream &os, vector3d &v)
 Output.
vector3d cross (const vector3d &lhs, const vector3d &rhs)
 Return the cross product of two vectors.
double angle (const vector3d &a, const vector3d &b, const vector3d &c)
 Return the angle between three vectors.
double torsion (const vector3d &a, const vector3d &b, const vector3d &c, const vector3d &d)
 Return the torsion between four vectors.
double torsion2 (const vector3d &a, const vector3d &b, const vector3d &c, const vector3d &d)
 Return the torsion between four vectors.
int formRotMat (const vector3d &a, const vector3d &b, const vector3d &c, const vector3d &d, double angle, double rotMat[9])
 Form rotation matrix R from a torsion and rotational angle in radians.
void buildCoord (vector3d &a, const vector3d &b, const vector3d &c, const vector3d &d, double dist, double angle, double torsion)
 Generate coordinate a from b, c, d, dist, angle, and torsion.

Detailed Description

A 3-dimensional vector class.

Author:
Andrew Wollacott
Martin Peters
Version:
0.1
Date:
2005

Constructor & Destructor Documentation

MTKpp::vector3d::vector3d ( ) [inline]

vector3d Constructor

Initializes coordinates to 0,0,0

Referenced by unit().

MTKpp::vector3d::vector3d ( double  x,
double  y,
double  z 
) [inline]

vector3d Constructor

Parameters:
xx coordinate
yy coordinate
zz coordinate
MTKpp::vector3d::vector3d ( double  xyz) [inline]

vector3d Constructor

Parameters:
xyzSets all three coordinates to this value

Member Function Documentation

void MTKpp::vector3d::set ( double  x,
double  y,
double  z 
) [inline]

Set x, y, and z coordinates.

Parameters:
xx value
yy value
zz value

References X, Y, and Z.

Referenced by main(), and MTKpp::atom::setCoords().

void MTKpp::vector3d::setX ( double  x) [inline]

Set x coordinate to this value.

Parameters:
xx value

References X.

Referenced by MTKpp::stdFrag::generateCoordinates(), MTKpp::gaussianParser::Read(), and MTKpp::watProtonate::run().

void MTKpp::vector3d::setY ( double  y) [inline]

Set y coordinate to this value.

Parameters:
yy value

References Y.

Referenced by MTKpp::stdFrag::generateCoordinates(), MTKpp::gaussianParser::Read(), and MTKpp::watProtonate::run().

void MTKpp::vector3d::setZ ( double  z) [inline]

Set z coordinate to this value.

Parameters:
zz value

References Z.

Referenced by MTKpp::gaussianParser::Read(), and MTKpp::watProtonate::run().

double MTKpp::vector3d::getX ( ) [inline]

Get x coordinate.

Returns:
x value

References X.

Referenced by MTKpp::atom::getX(), main(), MTKpp::molecule::moveCenterOfMass(), and MTKpp::watProtonate::run().

double MTKpp::vector3d::getY ( ) [inline]

Get y coordinate.

Returns:
y value

References Y.

Referenced by MTKpp::atom::getY(), main(), MTKpp::molecule::moveCenterOfMass(), and MTKpp::watProtonate::run().

double MTKpp::vector3d::getZ ( ) [inline]

Get z coordinate.

Returns:
z value

References Z.

Referenced by MTKpp::atom::getZ(), main(), MTKpp::molecule::moveCenterOfMass(), and MTKpp::watProtonate::run().

double& MTKpp::vector3d::operator[] ( int  i) [inline]

Access coordinate as array.

Parameters:
iCoordinate to be returned
Returns:
Coordinate i

References X, Y, and Z.

vector3d& MTKpp::vector3d::operator= ( const double &  value) [inline]

Set vector equal to constant.

Parameters:
valueValue to be set
Returns:
vector3d

References X, Y, and Z.

void MTKpp::vector3d::operator+= ( const vector3d rhs) [inline]

Add another vector3d object to this.

Parameters:
rhsvector3d object

References X, Y, and Z.

void MTKpp::vector3d::operator-= ( const vector3d rhs) [inline]

Subtract another vector3d object to this.

Parameters:
rhsvector3d object

References X, Y, and Z.

void MTKpp::vector3d::operator*= ( const double &  value) [inline]

Multiply vector3d by a constant.

Parameters:
valueValue thats multiplied

References X, Y, and Z.

void MTKpp::vector3d::operator/= ( const double &  value) [inline]

Divide vector3d by a constant.

Parameters:
valueValue thats divided

References X, Y, and Z.

double MTKpp::vector3d::length ( ) [inline]

Return the magnitude of a vector.

Returns:
length of vector3d

References X, Y, and Z.

Referenced by unit().

double MTKpp::vector3d::length_squared ( ) [inline]

Returns the square of the magnitude.

Returns:
length of vector3d squared

References X, Y, and Z.

vector3d MTKpp::vector3d::unit ( ) [inline]

Returns the unit vector.

Returns:
vector3d object

References length(), vector3d(), X, Y, and Z.

Referenced by MTKpp::gaussianParser::getForceConstant(), MTKpp::watProtonate::run(), and MTKpp::watProtonate::setup().

double MTKpp::vector3d::dist ( const vector3d v2) [inline]
double MTKpp::vector3d::dist2 ( const vector3d v2) [inline]

Return the square of the "distance" between two vectors.

Returns:
distance squared

References X, Y, and Z.

Referenced by MTKpp::gaussianParser::getForceConstant().

void MTKpp::vector3d::rotateX ( const double &  ang) [inline]

Rotate about the X-axis.

Parameters:
angAngle to be rotated by

References Y, and Z.

void MTKpp::vector3d::rotateX ( const double &  ang,
const vector3d o 
) [inline]

Rotate about the X-axis, with origin o.

Parameters:
angAngle to be rotated by
oorigin

References Y, and Z.

void MTKpp::vector3d::rotateY ( const double &  ang) [inline]

Rotate about the Y-axis.

Parameters:
angAngle to be rotated by

References X, and Z.

void MTKpp::vector3d::rotateY ( const double &  ang,
const vector3d o 
) [inline]

Rotate about the Y-axis, with origin o.

Parameters:
angAngle to be rotated by
oorigin

References X, and Z.

void MTKpp::vector3d::rotateZ ( const double &  ang) [inline]

Rotate about the Z-axis.

Parameters:
angAngle to be rotated by

References X, and Y.

void MTKpp::vector3d::rotateZ ( const double &  ang,
const vector3d o 
) [inline]

Rotate about the Z-axis, with origin o.

Parameters:
angAngle to be rotated by
oorigin

References X, and Y.

void MTKpp::vector3d::rotateXYZ ( const double  R[9],
const vector3d o 
) [inline]

Rotate xyz according to the rotation matrix R with origin o.

Parameters:
Rrotation matrix
oorigin

References X, Y, and Z.


Friends And Related Function Documentation

vector3d operator- ( const vector3d lhs) [friend]

Set negative of the vector.

Parameters:
lhsnegative of this vector
Returns:
vector3d
bool operator== ( const vector3d lhs,
const vector3d rhs 
) [friend]

Checks equality of two vectors.

Parameters:
lhsLeft hand side vector3d object
rhsRight hand side vector3d object
bool operator!= ( const vector3d lhs,
const vector3d rhs 
) [friend]

Checks equality of two vectors.

Parameters:
lhsLeft hand side vector3d object
rhsRight hand side vector3d object
vector3d operator+ ( const vector3d lhs,
const vector3d rhs 
) [friend]

Add two vectors together.

Parameters:
lhsLeft hand side vector3d object
rhsRight hand side vector3d object
vector3d operator- ( const vector3d lhs,
const vector3d rhs 
) [friend]

Subtract two vectors.

Parameters:
lhsLeft hand side vector3d object
rhsRight hand side vector3d object
double operator* ( const vector3d lhs,
const vector3d rhs 
) [friend]

Calculate the dot-product of two vectors.

Parameters:
lhsLeft hand side vector3d object
rhsRight hand side vector3d object
Returns:
dot-product
vector3d operator+ ( const vector3d lhs,
const double &  scalar 
) [friend]

Add a vector to a scalar.

Parameters:
lhsLeft hand side vector3d object
scalarScalar to be added
Returns:
vector3d object
vector3d operator+ ( const double &  scalar,
const vector3d rhs 
) [friend]

Add a scalar to a vector.

Parameters:
scalarScalar to be added
rhsRight hand side vector3d object
Returns:
vector3d object
vector3d operator- ( const vector3d lhs,
const double &  scalar 
) [friend]

Subtract a scalar from a vector.

Parameters:
lhsLeft hand side vector3d object
scalarScalar to be subtracted
Returns:
vector3d object
vector3d operator- ( const double &  scalar,
const vector3d rhs 
) [friend]

Subtract a vector from a scalar.

Parameters:
scalarScalar to be subtracted
rhsRight hand side vector3d object
Returns:
vector3d object
vector3d operator* ( const vector3d lhs,
const double &  scalar 
) [friend]

Return the product of a vector with a scalar.

Parameters:
lhsLeft hand side vector3d object
scalarScalar to be multiplied
Returns:
vector3d object
vector3d operator* ( const double &  scalar,
const vector3d rhs 
) [friend]

Return the product of a scalar with a vector.

Parameters:
scalarScalar to be multiplied
rhsRight hand side vector3d object
Returns:
vector3d object
vector3d operator/ ( const vector3d lhs,
const double &  scalar 
) [friend]

Divide a vector with a scalar.

Parameters:
lhsLeft hand side vector3d object
scalarScalar to be multiplied
Returns:
vector3d object
std::ostream& operator<< ( std::ostream &  os,
vector3d v 
) [friend]

Output.

Parameters:
osstream
vvector3d object
vector3d cross ( const vector3d lhs,
const vector3d rhs 
) [friend]

Return the cross product of two vectors.

Returns:
vector3d object
double angle ( const vector3d a,
const vector3d b,
const vector3d c 
) [friend]

Return the angle between three vectors.

Parameters:
avector3d a
bvector3d b
cvector3d c
Returns:
angle in radians
double torsion ( const vector3d a,
const vector3d b,
const vector3d c,
const vector3d d 
) [friend]

Return the torsion between four vectors.

Parameters:
avector3d a
bvector3d b
cvector3d c
dvector3d d
Returns:
angle in radians

\[ \cos{\phi} & = & {{t \cdot u} \over {|t||u|}} \]

where:

\begin{eqnarray*} r_{ab} & = & r_{a} - r_{b} \\ r_{cb} & = & r_{c} - r_b \\ r_{cd} & = & r_c - r_d \\ t & = & r_{ab} \times r_{cb} \\ u & = & r_{cb} \times r_{cd} \nonumber \end{eqnarray*}

double torsion2 ( const vector3d a,
const vector3d b,
const vector3d c,
const vector3d d 
) [friend]

Return the torsion between four vectors.

Parameters:
avector3d a
bvector3d b
cvector3d c
dvector3d d
Returns:
angle in radians

\[ \phi & = & { \arctan2(|b2|b1 \cdot [b2 \times b3], [b1 \times b1] \cdot [b2 \times b3] )} \]

where:

\begin{eqnarray*} b1 & = & r_a - r_b \\ b2 & = & r_c - r_b \\ b3 & = & r_c - r_d \nonumber \end{eqnarray*}

int formRotMat ( const vector3d a,
const vector3d b,
const vector3d c,
const vector3d d,
double  angle,
double  rotMat[9] 
) [friend]

Form rotation matrix R from a torsion and rotational angle in radians.

This is axis angle rotation

Parameters:
aCoordinate 1
bCoordinate 2
cCoordinate 3
dCoordinate 4
angleAngle of rotation
rotMatRotation matrix which gets returned
Returns:
successful or not
         1) Measure torsion, t, a-b-c-d

         2) Make sure t lies between 0 and 2*PI

         3) Calculate rotAngle = angle - t

         4) Calculate cos(rotAngle) and sin(rotAngle), and Normalize the vector b - c

         5) Calculate rotation matrix, R:

               +-                               -+
               | t*x*x+c    t*x*y+s*z  t*x*z-s*y |
         R =   | t*x*y-s*z  t*y*y+c    t*y*z+s*x |
               | t*x*z+s*y  t*y*z-s*x  t*z*z+c   |
               +-                               -+

         where:
           c = cos(angle)
           s = sin(angle)
           t = 1 - c
           x,y,z = normalized b-c x,y,z coordinates
void buildCoord ( vector3d a,
const vector3d b,
const vector3d c,
const vector3d d,
double  dist,
double  angle,
double  torsion 
) [friend]

Generate coordinate a from b, c, d, dist, angle, and torsion.

Parameters:
acoordinate to be generated
bbonded coordinate
cangle coordinate
dtorsion coordinate
distdistance of a-b (angstrom)
angleangle a-b-c (radians)
torsiontorsion a-b-c-d (radians)
          b -- c
         /      \
        a        d

Member Data Documentation

double MTKpp::vector3d::X [protected]
double MTKpp::vector3d::Y [protected]
double MTKpp::vector3d::Z [protected]

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

Generated on Fri Dec 23 2011 09:28:58 for MTK++ by Doxygen 1.7.5.1