Loading...
Searching...
No Matches
vector3 Class Reference

`#include <openbabel/math/vector3.h>`

Inheritance diagram for vector3:
[legend]

## Public Types

typedef double * | iterator
typedef const double * | const_iterator
typedef std::ptrdiff_t | difference_type

## Public Member Functions

| vector3 (const double inX=0.0, const double inY=0.0, const double inZ=0.0)
| vector3 (double inV[3])
| vector3 (const vector3 &v)
| ~vector3 ()
iterator | begin ()
iterator | end ()
const_iterator | begin () const
const_iterator | end () const
void | Set (const double inX, const double inY, const double inZ)
void | Set (const double *c)
void | SetX (const double inX)
void | SetY (const double inY)
void | SetZ (const double inZ)
double | GetX () const
double | GetY () const
double | GetZ () const
void | Get (double *c)
double | operator[] (unsigned int i) const
vector3 & | operator= (const vector3 &v)
const double * | AsArray () const
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 &)
void | randomUnitVector ()
vector3 & | normalize ()
bool | CanBeNormalized () const
double | length_2 () const
double | length () const
const double & | x () const
const double & | y () const
const double & | z () const
double & | x ()
double & | y ()
double & | z ()
int | operator== (const vector3 &) const
int | operator!= (const vector3 &other) const
bool | IsApprox (const vector3 &other, const double &precision) const
double | distSq (const vector3 &vv) const
bool | createOrthoVector (vector3 &v) const

## Detailed Description

Represents a vector in 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 documentation. 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();
OpenBabel::vector3::vector3
vector3(const double inX=0.0, const double inY=0.0, const double inZ=0.0)
Constructor.
Definition vector3.h:51
OpenBabel::vector3::normalize
vector3 & normalize()
Definition vector3.cpp:152
OpenBabel::VY
const vector3 VY
The y unit vector: <0.0, 1.0, 0.0>.
OpenBabel::cross
vector3 cross(const vector3 &, const vector3 &)
Cross product of two vectors.
Definition vector3.cpp:163
OpenBabel::VX
const vector3 VX
The x unit vector: <1.0, 0.0, 0.0>.

## Member Typedef Documentation

## iterator

typedef double* iterator

A random access iterator over x, y, z.

## const_iterator

typedef const double* const_iterator

A random access iterator over const x, y, z.

## difference_type

typedef std::ptrdiff_t difference_type

A signed integral type for differences between two iterators.

## Constructor & Destructor Documentation

## vector3() [1/3]

vector3 | ( | const double | inX = 0.0,
|  | const double | inY = 0.0,
|  | const double | inZ = 0.0 )

inline

Constructor.

Referenced by createOrthoVector(), transform3d::DescribeAsString(), transform3d::DescribeAsValues(), distSq(), IsApprox(), transform3d::Normalize(), normalize(), operator!=(), transform3d::operator*(), transform3d::operator*(), operator*=(), operator*=(), operator+=(), operator+=(), operator-=(), operator-=(), operator/=(), operator=(), operator==(), transform3d::transform3d(), transform3d::transform3d(), transform3d::transform3d(), transform3d::transform3d(), transform3d::transform3d(), and vector3().

## vector3() [2/3]

vector3 | ( | double | inV[3] | ) |

inline

## vector3() [3/3]

vector3 | ( | const vector3 & | v | ) |

inline

Copy Constructor.

## ~vector3()

~vector3 | ( |  | ) |

inline

Destructor.

## Member Function Documentation

## begin() [1/2]

iterator begin | ( |  | ) |

inline

Returns
  iterator to beginning

## end() [1/2]

iterator end | ( |  | ) |

inline

Returns
  iterator to end

## begin() [2/2]

const_iterator begin | ( |  | ) | const

inline

/return const_iterator to beginning

## end() [2/2]

const_iterator end | ( |  | ) | const

inline

/return const_iterator to end

## Set() [1/2]

void Set | ( | const double | inX,
|  | const double | inY,
|  | const double | inZ )

inline

Set x,y and z-component of a vector.

Referenced by OBRotamerList::AddRotamer(), OBRing::findCenterAndNormal(), OBFloatGrid::GetMidpointVector(), OBBuilder::GetNewBondVector(), OBForceField::NumericalDerivative(), OBForceField::NumericalSecondDerivative(), randomUnitVector(), OBForceField::ValidateConjugateGradients(), and OBForceField::ValidateSteepestDescent().

## Set() [2/2]

void Set | ( | const double * | c | ) |

inline

Set x,y and z-component of a vector from c[0]..c[2].

## SetX()

void SetX | ( | const double | inX | ) |

inline

Access function to set the x-coordinate of the vector.

Referenced by OpenBabel::areDuplicateAtoms(), OBForceField::GetGrid(), OBForceField::MolecularDynamicsTakeNSteps(), and operator*=().

## SetY()

void SetY | ( | const double | inY | ) |

inline

Access function to set the y-coordinate of the vector.

Referenced by OpenBabel::areDuplicateAtoms(), OBForceField::GetGrid(), OBForceField::MolecularDynamicsTakeNSteps(), and operator*=().

## SetZ()

void SetZ | ( | const double | inZ | ) |

inline

Access function to set the z-coordinate of the vector.

Referenced by OpenBabel::areDuplicateAtoms(), OBForceField::GetGrid(), OBForceField::MolecularDynamicsTakeNSteps(), and operator*=().

## GetX()

double GetX | ( |  | ) | const

inline

Access function to get the x-coordinate of the vector.

## GetY()

double GetY | ( |  | ) | const

inline

Access function to get the y-coordinate of the vector.

## GetZ()

double GetZ | ( |  | ) | const

inline

Access function to get the z-coordinate of the vector.

## Get()

void Get | ( | double * | c | ) |

inline

Set c[0]..c[2] to the components of the vector.

Warning
  No error checking is performed

Referenced by OBForceField::VectorBondDerivative().

## operator[]()

double operator[] | ( | unsigned int | i | ) | const

Access function to x: [0], y: [1], and z[2].

This (slow) method allows one 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 0.0 is returned. 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.

## operator=()

vector3 & operator= | ( | const vector3 & | v | ) |

inline

Assignment.

## AsArray()

const double * AsArray | ( |  | ) | const

inline

Returns
  the vector as a const double *

## operator+=() [1/2]

vector3 & operator+= | ( | const vector3 & | v | ) |

inline

Vector addition (add `v` to *this).

Returns
  *this + v

## operator-=() [1/2]

vector3 & operator-= | ( | const vector3 & | v | ) |

inline

Vector subtraction (subtract `v` from *this).

Returns
  *this - v

## operator+=() [2/2]

vector3 & operator+= | ( | const double * | f | ) |

inline

Scalar addition (add `f` to *this).

Returns
  *this + f

## operator-=() [2/2]

vector3 & operator-= | ( | const double * | f | ) |

inline

Scalar subtraction (subtract `f` from *this).

Returns
  *this - f

## operator*=() [1/2]

vector3 & operator*= | ( | const double & | c | ) |

inline

Scalar multiplication (multiply *this by `c`).

Returns
  *this * c

## operator/=()

vector3 & operator/= | ( | const double & | c | ) |

inline

Scalar division (divide *this by `c`).

Returns
  *this divided by c

## operator*=() [2/2]

vector3 & operator*= | ( | const matrix3x3 & | m | ) |

Multiplication of matrix and vector

Returns
  the result (i.e., the updated vector)

Todo
  Currently unimplemented

calculates the product m*(*this) of the matrix m and the column vector represented by *this

## randomUnitVector()

void randomUnitVector | ( |  | ) |

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 system number generator with a time seed.

Referenced by OBBuilder::Build(), OBBuilder::Connect(), OBBuilder::GetNewBondVector(), OBBond::SetLength(), OBForceField::VectorBondDerivative(), and OBForceField::VectorLengthDerivative().

## normalize()

vector3 & normalize | ( |  | ) |

Scales a vector to give it length one.

Returns
  the result (i.e., the normalized vector)

This method normalizes *this. In other words, it divides the x,y,z coords of *this by this->length(). If *this can't be safely normalized, it remains unchanged. See CanBeNormalized().

Returns
  a reference to *this

Referenced by OBRing::findCenterAndNormal(), OBBuilder::GetNewBondVector(), OpenBabel::InternalToCartesian(), OBForceField::LineSearch(), matrix3x3::PlaneReflection(), randomUnitVector(), matrix3x3::RotAboutAxisByAngle(), OBAtom::SetHybAndGeom(), OBBond::SetLength(), OBForceField::ValidateLineSearch(), and OBForceField::VectorAngleDerivative().

## CanBeNormalized()

bool CanBeNormalized | ( |  | ) | const

Returns
  Whether a vector can be normalized

This method returns true if *this can be safely normalized. Vectors that can't be safely normalized are:

- the zero vector (0,0,0)
- vectors having coords that can't be squared without triggering an overflow or underflow. This means doubles having absolute value greater than 1e150 or smaller than 1e-150.

Referenced by createOrthoVector(), and normalize().

## length_2()

double length_2 | ( |  | ) | const

inline

Returns
  The length of the vector squared

Referenced by OpenBabel::areDuplicateAtoms(), OpenBabel::CartesianToInternal(), OBForceField::ConjugateGradientsTakeNSteps(), OBMol::ConnectTheDots(), IsApprox(), length(), randomUnitVector(), OBBond::SetLength(), and OBForceField::SteepestDescentTakeNSteps().

## length()

double length | ( |  | ) | const

inline

Returns
  The vector length

Referenced by OpenBabel::CalcTorsionAngle(), OpenBabel::CartesianToInternal(), OBAtom::GetAngle(), OBForceField::LineSearch(), normalize(), OpenBabel::Point2Line(), OpenBabel::Point2PlaneSigned(), OBUnitCell::SetData(), OBBuilder::Swap(), OpenBabel::vectorAngle(), OBForceField::VectorAngleDerivative(), OBForceField::VectorLengthDerivative(), OBForceField::VectorOOPDerivative(), and OBForceField::VectorTorsionDerivative().

## x() [1/2]

const double & x | ( |  | ) | const

inline

Access function to get the x-coordinate of the vector.

Referenced by OBDepict::AddAtomLabels(), OBMol::AddHydrogens(), OBMol::AddNewHydrogens(), SpaceGroup::AddTransform(), OpenBabel::areDuplicateAtoms(), OBBuilder::Build(), OBForceField::ConjugateGradientsInitialize(), OBForceField::ConjugateGradientsTakeNSteps(), OBBuilder::Connect(), OpenBabel::cross(), transform3d::DescribeAsValues(), distSq(), OpenBabel::dot(), OBUnitCell::FillUnitCell(), OBGridData::GetAxes(), OBBuilder::GetFragmentCoord(), OBForceField::GetGrid(), OpenBabel::GetLabelAlignment(), OBBuilder::GetNewBondVector(), OBGridData::GetValue(), matrix3x3::matrix3x3(), OBUnitCell::MinimumImageFractional(), OBForceField::MolecularDynamicsTakeNSteps(), transform3d::Normalize(), OBForceField::NumericalDerivative(), OBForceField::NumericalSecondDerivative(), matrix3x3::operator*, OpenBabel::operator*(), OpenBabel::operator*(), operator*=(), OpenBabel::operator+(), OpenBabel::operator-(), OpenBabel::operator-(), OpenBabel::operator/(), OpenBabel::operator<<(), operator==(), matrix3x3::PlaneReflection(), OBGrid::PointIsInBox(), matrix3x3::RotAboutAxisByAngle(), matrix3x3::SetColumn(), OBFloatGrid::SetLimits(), matrix3x3::SetRow(), OBAtom::SetVector(), OBForceField::SteepestDescentTakeNSteps(), SpaceGroup::Transform(), OBMol::Translate(), OpenBabel::UpdateConformersFromTree(), OBForceField::ValidateConjugateGradients(), OBForceField::ValidateGradientError(), OBForceField::ValidateSteepestDescent(), and OBUnitCell::WrapFractionalCoordinate().

## y() [1/2]

const double & y | ( |  | ) | const

inline

Access function to get the y-coordinate of the vector.

Referenced by OBDepict::AddAtomLabels(), OBMol::AddHydrogens(), OBMol::AddNewHydrogens(), SpaceGroup::AddTransform(), OpenBabel::areDuplicateAtoms(), OBBuilder::Build(), OBForceField::ConjugateGradientsInitialize(), OBForceField::ConjugateGradientsTakeNSteps(), OBBuilder::Connect(), OpenBabel::cross(), transform3d::DescribeAsValues(), distSq(), OpenBabel::dot(), OBUnitCell::FillUnitCell(), OBGridData::GetAxes(), OBBuilder::GetFragmentCoord(), OBForceField::GetGrid(), OpenBabel::GetLabelAlignment(), OBBuilder::GetNewBondVector(), OBGridData::GetValue(), matrix3x3::matrix3x3(), OBUnitCell::MinimumImageFractional(), OBForceField::MolecularDynamicsTakeNSteps(), transform3d::Normalize(), OBForceField::NumericalDerivative(), OBForceField::NumericalSecondDerivative(), matrix3x3::operator*, OpenBabel::operator*(), OpenBabel::operator*(), operator*=(), OpenBabel::operator+(), OpenBabel::operator-(), OpenBabel::operator-(), OpenBabel::operator/(), OpenBabel::operator<<(), operator==(), matrix3x3::PlaneReflection(), OBGrid::PointIsInBox(), matrix3x3::RotAboutAxisByAngle(), matrix3x3::SetColumn(), OBFloatGrid::SetLimits(), matrix3x3::SetRow(), OBAtom::SetVector(), OBForceField::SteepestDescentTakeNSteps(), SpaceGroup::Transform(), OBMol::Translate(), OpenBabel::UpdateConformersFromTree(), OBForceField::ValidateConjugateGradients(), OBForceField::ValidateGradientError(), OBForceField::ValidateSteepestDescent(), and OBUnitCell::WrapFractionalCoordinate().

## z() [1/2]

const double & z | ( |  | ) | const

inline

Access function to get the z-coordinate of the vector.

Referenced by OBMol::AddHydrogens(), OBMol::AddNewHydrogens(), SpaceGroup::AddTransform(), OpenBabel::areDuplicateAtoms(), OBBuilder::Build(), OBForceField::ConjugateGradientsInitialize(), OBForceField::ConjugateGradientsTakeNSteps(), OBBuilder::Connect(), OBMol::ConnectTheDots(), OpenBabel::cross(), transform3d::DescribeAsValues(), distSq(), OpenBabel::dot(), OBDepict::DrawMolecule(), OBUnitCell::FillUnitCell(), OBGridData::GetAxes(), OBBuilder::GetFragmentCoord(), OBForceField::GetGrid(), OBBuilder::GetNewBondVector(), OBGridData::GetValue(), matrix3x3::matrix3x3(), OBUnitCell::MinimumImageFractional(), OBForceField::MolecularDynamicsTakeNSteps(), transform3d::Normalize(), OBForceField::NumericalDerivative(), OBForceField::NumericalSecondDerivative(), matrix3x3::operator*, OpenBabel::operator*(), OpenBabel::operator*(), operator*=(), OpenBabel::operator+(), OpenBabel::operator-(), OpenBabel::operator-(), OpenBabel::operator/(), OpenBabel::operator<<(), operator==(), matrix3x3::PlaneReflection(), OBGrid::PointIsInBox(), matrix3x3::RotAboutAxisByAngle(), matrix3x3::SetColumn(), OBFloatGrid::SetLimits(), matrix3x3::SetRow(), OBAtom::SetVector(), OBForceField::SteepestDescentTakeNSteps(), SpaceGroup::Transform(), OBMol::Translate(), OpenBabel::UpdateConformersFromTree(), OBForceField::ValidateConjugateGradients(), OBForceField::ValidateGradientError(), and OBUnitCell::WrapFractionalCoordinate().

## x() [2/2]

double & x | ( |  | ) |

inline

Access function to set the x-coordinate of the vector.

## y() [2/2]

double & y | ( |  | ) |

inline

Access function to set the y-coordinate of the vector.

## z() [2/2]

double & z | ( |  | ) |

inline

Access function to set the z-coordinate of the vector.

## operator==()

int operator== | ( | const vector3 & | other | ) | const

Comparison Methods.

Equivalence of vectors

Deprecated
  This method uses unreliable floating point == comparisons Use vector3::IsApprox() instead.

Returns
  true if every component is equal

## operator!=()

int operator!= | ( | const vector3 & | other | ) | const

inline

Deprecated
  This method uses unreliable floating point == comparisons Use vector3::IsApprox() instead.

Returns
  true if at least one component of the two vectors is !=

## IsApprox()

bool IsApprox | ( | const vector3 & | other,
|  | const double & | precision ) const

Safe comparison for floating-point vector3.

Returns
  true if the vector *this is approximately equal to the vector `other`, to the precision `precision`. More specifically, this method works exactly like the OpenBabel::IsApprox() function, replacing the absolute value for doubles by the norm for vectors.

Parameters

  other | The vector for comparison
  precision | This parameter plays the same role as in OpenBabel::IsApprox().

## distSq()

double distSq | ( | const vector3 & | vv | ) | const

inline

}@

Returns
  square of the distance between *this and vv

equivalent to length_2(*this-vv)

Referenced by OBDepict::DrawMolecule(), OBForceField::GetGrid(), and IsApprox().

## createOrthoVector()

bool createOrthoVector | ( | vector3 & | res | ) | const

Construct a unit vector orthogonal to *this.

Creates a vector of length one, orthogonal to *this.

Returns
  Whether the method was successful

It requires that *this is normalizable; otherwise it just returns false. See CanBeNormalized()

Parameters

  res | reference by which to pass the result.

Returns
  always true. (Return value kept for compatibility, as old versions of OpenBabel used to check for normalizability).

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

- vector3.h
- matrix3x3.cpp
- vector3.cpp