Loading...
Searching...
No Matches
vector3.h
Go to the documentation of this file.
/**********************************************************************
vector3.h - Handle 3D coordinates.
Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
Some portions Copyright (C) 2001-2006 by Geoffrey R. Hutchison
Some portions Copyright (C) 2006 by Benoit Jacob
This file is part of the Open Babel project.
For more information, see <http://openbabel.org/>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
***********************************************************************/
#ifndef OB_VECTOR_H
#define OB_VECTOR_H
#include <ostream>
#include <math.h>
#include <iostream>
#include <openbabel/babelconfig.h>
#ifndef RAD_TO_DEG
#define RAD_TO_DEG (180.0/M_PI)
#endif
#ifndef DEG_TO_RAD
#define DEG_TO_RAD (M_PI/180.0)
#endif
namespace OpenBabel
{
class matrix3x3; // declared in math/matrix3x3.h
// class introduction in vector3.cpp
class OBAPI vector3
{
private :
double _vx, _vy, _vz ;
public :
vector3 (const double inX=0.0, const double inY=0.0, const double inZ=0.0):
_vx(inX), _vy(inY), _vz(inZ)
{}
vector3 (double inV[3]):
_vx(inV[0]), _vy(inV[1]), _vz(inV[2])
{}
vector3 (const vector3& v):
_vx(v._vx), _vy(v._vy), _vz(v._vz)
{ }
~vector3() { }
typedef double* iterator;
typedef const double* const_iterator;
typedef std::ptrdiff_t difference_type;
iterator begin() { return &_vx; }
iterator end() { return &_vx + 3; }
const_iterator begin() const { return &_vx; }
const_iterator end() const { return &_vx + 3; }
void Set(const double inX, const double inY, const double inZ)
{
_vx = inX;
_vy = inY;
_vz = inZ;
}
void Set(const double *c)
{
_vx = c[0];
_vy = c[1];
_vz = c[2];
}
void SetX(const double inX)
{
_vx = inX;
}
void SetY(const double inY)
{
_vy = inY;
}
void SetZ(const double inZ)
{
_vz = inZ;
}
double GetX() const
{
return _vx;
}
double GetY() const
{
return _vy;
}
double GetZ() const
{
return _vz;
}
void Get(double *c)
{
c[0]=_vx;
c[1]=_vy;
c[2]=_vz;
}
double operator[] ( unsigned int i) const;
vector3& operator= ( const vector3& v)
{
_vx = v._vx;
_vy = v._vy;
_vz = v._vz;
return *this;
}
const double *AsArray() const
{
return &_vx;
}
vector3& operator+= ( const vector3& v)
{
_vx += v._vx;
_vy += v._vy;
_vz += v._vz;
return *this;
};
vector3& operator-= ( const vector3& v)
{
_vx -= v._vx;
_vy -= v._vy;
_vz -= v._vz;
return *this;
};
vector3& operator+= ( const double* f)
{
_vx += f[0];
_vy += f[1];
_vz += f[2];
return *this;
};
vector3& operator-= ( const double* f)
{
_vx -= f[0];
_vy -= f[1];
_vz -= f[2];
return *this;
};
vector3& operator*= ( const double& c)
{
_vx *= c;
_vy *= c;
_vz *= c;
return *this;
};
vector3& operator/= ( const double& c)
{
double inv = 1.0 / c;
return( (*this) *= inv );
};
vector3& operator*= ( const matrix3x3 &);
void randomUnitVector();
// Member Functions
vector3& normalize () ;
bool CanBeNormalized () const;
inline double length_2 () const
{
return _vx*_vx + _vy*_vy + _vz*_vz;
};
double length () const
{
return sqrt( length_2() );
};
const double & x () const
{
return _vx ;
} ;
const double & y () const
{
return _vy ;
} ;
const double & z () const
{
return _vz ;
} ;
double & x ()
{
return _vx ;
} ;
double & y ()
{
return _vy ;
} ;
double & z ()
{
return _vz ;
} ;
// @{
int operator== ( const vector3& ) const;
int operator!= ( const vector3& other ) const
{
return ! ( (*this) == other );
}
bool IsApprox( const vector3 & other, const double & precision ) const;
double distSq(const vector3 &vv) const
{
double dx = x() - vv.x();
double dy = y() - vv.y();
double dz = z() - vv.z();
return( dx*dx + dy*dy + dz*dz );
}
bool createOrthoVector(vector3 &v) const;
};
OBAPI std::ostream& operator<< ( std::ostream&, const vector3& );
// Sum, Difference, Scalar Product
inline OBAPI vector3 operator+ ( const vector3& v1, const vector3& v2)
{
return vector3(v1.x()+v2.x(), v1.y()+v2.y(), v1.z()+v2.z());
}
inline OBAPI vector3 operator- ( const vector3& v1, const vector3& v2)
{
return vector3(v1.x()-v2.x(), v1.y()-v2.y(), v1.z()-v2.z());
}
inline OBAPI vector3 operator- ( const vector3& v)
{
return vector3(-v.x(), -v.y(), -v.z());
}
inline OBAPI vector3 operator* ( const double& c, const vector3& v)
{
return vector3( c*v.x(), c*v.y(), c*v.z());
}
inline OBAPI vector3 operator* ( const vector3& v, const double& c)
{
return vector3( c*v.x(), c*v.y(), c*v.z());
}
inline OBAPI vector3 operator/ ( const vector3& v, const double& c)
{
return vector3( v.x()/c, v.y()/c, v.z()/c);
}
// @removed@ misleading operation
// friend vector3 operator* ( const vector3 &,const vector3 &);
//vector and matrix ops
// @removed@ misleading operation; matrix multiplication is not commutitative
// friend vector3 operator *(const vector3 &v,const matrix3x3 &m);
OBAPI vector3 operator *(const matrix3x3 &m, const vector3 &v);
inline OBAPI double dot ( const vector3& v1, const vector3& v2 )
{
return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z() ;
}
OBAPI vector3 cross ( const vector3&, const vector3& );
OBAPI double vectorAngle ( const vector3& v1, const vector3& v2 );
OBAPI double CalcTorsionAngle(const vector3 &a, const vector3 &b,
const vector3 &c, const vector3 &d);
OBAPI double Point2PlaneSigned(vector3 a, vector3 b, vector3 c, vector3 d);
OBAPI double Point2Plane(vector3 a, vector3 b, vector3 c, vector3 d);
OBAPI double Point2PlaneAngle(const vector3 a, const vector3 b, const vector3 c, const vector3 d);
OBAPI double Point2Line(const vector3& a, const vector3& b, const vector3& c);
// The global constant vector3 objects
extern OBAPI const vector3 VZero;
extern OBAPI const vector3 VX;
extern OBAPI const vector3 VY;
extern OBAPI const vector3 VZ;
}
#endif // OB_VECTOR_H
OpenBabel::matrix3x3
Represents a real 3x3 matrix.
Definition matrix3x3.h:43
OpenBabel::vector3
Represents a vector in 3-dimensional real space.
Definition vector3.h:45
OpenBabel::vector3::~vector3
~vector3()
Destructor.
Definition vector3.h:63
OpenBabel::vector3::AsArray
const double * AsArray() const
Definition vector3.h:151
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::begin
const_iterator begin() const
/return const_iterator to beginning
Definition vector3.h:81
OpenBabel::vector3::z
double & z()
Access function to set the z-coordinate of the vector.
Definition vector3.h:262
OpenBabel::vector3::GetY
double GetY() const
Access function to get the y-coordinate of the vector.
Definition vector3.h:121
OpenBabel::vector3::x
double & x()
Access function to set the x-coordinate of the vector.
Definition vector3.h:252
OpenBabel::vector3::SetY
void SetY(const double inY)
Access function to set the y-coordinate of the vector.
Definition vector3.h:106
OpenBabel::vector3::iterator
double * iterator
A random access iterator over x, y, z.
Definition vector3.h:66
OpenBabel::vector3::length_2
double length_2() const
Definition vector3.h:227
OpenBabel::vector3::x
const double & x() const
Access function to get the x-coordinate of the vector.
Definition vector3.h:237
OpenBabel::vector3::Set
void Set(const double inX, const double inY, const double inZ)
Set x,y and z-component of a vector.
Definition vector3.h:87
OpenBabel::vector3::const_iterator
const double * const_iterator
A random access iterator over const x, y, z.
Definition vector3.h:69
OpenBabel::vector3::length
double length() const
Definition vector3.h:232
OpenBabel::vector3::vector3
vector3(double inV[3])
Definition vector3.h:54
OpenBabel::vector3::Get
void Get(double *c)
Set c[0]..c[2] to the components of the vector.
Definition vector3.h:132
OpenBabel::vector3::z
const double & z() const
Access function to get the z-coordinate of the vector.
Definition vector3.h:247
OpenBabel::vector3::y
double & y()
Access function to set the y-coordinate of the vector.
Definition vector3.h:257
OpenBabel::vector3::SetX
void SetX(const double inX)
Access function to set the x-coordinate of the vector.
Definition vector3.h:101
OpenBabel::vector3::vector3
vector3(const vector3 &v)
Copy Constructor.
Definition vector3.h:58
OpenBabel::vector3::Set
void Set(const double *c)
Set x,y and z-component of a vector from c[0]..c[2].
Definition vector3.h:94
OpenBabel::vector3::GetX
double GetX() const
Access function to get the x-coordinate of the vector.
Definition vector3.h:116
OpenBabel::vector3::end
iterator end()
Definition vector3.h:78
OpenBabel::vector3::end
const_iterator end() const
/return const_iterator to end
Definition vector3.h:84
OpenBabel::vector3::SetZ
void SetZ(const double inZ)
Access function to set the z-coordinate of the vector.
Definition vector3.h:111
OpenBabel::vector3::difference_type
std::ptrdiff_t difference_type
A signed integral type for differences between two iterators.
Definition vector3.h:72
OpenBabel::vector3::y
const double & y() const
Access function to get the y-coordinate of the vector.
Definition vector3.h:242
OpenBabel::vector3::GetZ
double GetZ() const
Access function to get the z-coordinate of the vector.
Definition vector3.h:126
OpenBabel::vector3::begin
iterator begin()
Definition vector3.h:75
OpenBabel::vector3::distSq
double distSq(const vector3 &vv) const
}@
Definition vector3.h:296
OpenBabel
Global namespace for all Open Babel code.
Definition alias.h:23
OpenBabel::vectorAngle
double vectorAngle(const vector3 &v1, const vector3 &v2)
Calculate the angle between vectors (in degrees).
Definition vector3.cpp:194
OpenBabel::operator/
vector3 operator/(const vector3 &v, const double &c)
Division by a scalar.
Definition vector3.h:340
OpenBabel::VZ
const vector3 VZ
The z unit vector: <0.0, 0.0, 1.0>.
OpenBabel::operator-
vector3 operator-(const vector3 &v1, const vector3 &v2)
Vector subtraction.
Definition vector3.h:320
OpenBabel::operator*
vector3 operator*(const double &c, const vector3 &v)
Multiplication with a scalar.
Definition vector3.h:330
OpenBabel::operator+
vector3 operator+(const vector3 &v1, const vector3 &v2)
Vector addition.
Definition vector3.h:315
OpenBabel::Point2PlaneSigned
double Point2PlaneSigned(vector3 a, vector3 b, vector3 c, vector3 d)
Calculate the signed distance of point a to the plane determined by b,c,d.
Definition vector3.cpp:308
OpenBabel::Point2PlaneAngle
double Point2PlaneAngle(const vector3 a, const vector3 b, const vector3 c, const vector3 d)
Calculate the angle between point a and the plane determined by b,c,d.
Definition vector3.cpp:322
OpenBabel::VY
const vector3 VY
The y unit vector: <0.0, 1.0, 0.0>.
OpenBabel::Point2Line
double Point2Line(const vector3 &a, const vector3 &b, const vector3 &c)
Calculate the distance of a point a to a line determined by b and c.
Definition vector3.cpp:337
OpenBabel::IsApprox
bool IsApprox(const double &a, const double &b, const double precision=1e-11)
Definition obutil.h:227
OpenBabel::CalcTorsionAngle
double CalcTorsionAngle(const vector3 &a, const vector3 &b, const vector3 &c, const vector3 &d)
Calculate the torsion angle between vectors (in degrees).
Definition vector3.cpp:222
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>.
OpenBabel::operator<<
std::ostream & operator<<(std::ostream &, const vector3 &)
Prints a representation of the vector as a row vector of the form "<0.1,1,2>".
Definition vector3.cpp:109
OpenBabel::dot
double dot(const vector3 &v1, const vector3 &v2)
Dot product of two vectors.
Definition vector3.h:355
OpenBabel::VZero
const vector3 VZero
The zero vector: <0.0, 0.0, 0.0>.
OpenBabel::Point2Plane
double Point2Plane(vector3 a, vector3 b, vector3 c, vector3 d)
Calculate the distance of point a to the plane determined by b,c,d.
Definition vector3.cpp:316