cgma
Vector3d Class Reference

#include <geometry.hpp>

List of all members.

Public Member Functions

 Vector3d ()
 Vector3d (const double p[3])
 Vector3d (double x, double y, double z)
 Vector3d (const std::vector< double > &p, int idx=0)
double length () const
Vector3d normalize () const
Vector3d operator- () const
Vector3d reverse () const
Vector3d scale (double d) const
Vector3d operator* (double d) const
Vector3d add (const Vector3d &alt) const
Vector3d operator+ (const Vector3d &alt) const
double dot (const Vector3d &alt) const
Vector3d cross (const Vector3d &alt) const
Vector3d rotate_about (const Vector3d &v_p, double theta_p, bool degrees=true) const
Vector3d projection (const Vector3d &v) const
 project v onto this vector, return the result

Public Attributes

double v [3]

Detailed Description

Definition at line 17 of file geometry.hpp.


Constructor & Destructor Documentation

Vector3d::Vector3d ( ) [inline]

Definition at line 22 of file geometry.hpp.

            {
    v[2] = v[1] = v[0] = 0;
  }
Vector3d::Vector3d ( const double  p[3]) [inline]

Definition at line 26 of file geometry.hpp.

                               {
    v[0] = p[0];
    v[1] = p[1];
    v[2] = p[2];
  }
Vector3d::Vector3d ( double  x,
double  y,
double  z 
) [inline]

Definition at line 32 of file geometry.hpp.

                                          {
    v[0] = x; 
    v[1] = y;
    v[2] = z;
  }
Vector3d::Vector3d ( const std::vector< double > &  p,
int  idx = 0 
) [inline]

Definition at line 38 of file geometry.hpp.

                                                     {
    v[0] = p.at(idx+0);
    v[1] = p.at(idx+1);
    v[2] = p.at(idx+2);
  }

Member Function Documentation

Vector3d Vector3d::add ( const Vector3d alt) const [inline]

Definition at line 69 of file geometry.hpp.

                                            {
    return Vector3d( v[0]+alt.v[0], v[1]+alt.v[1], v[2]+alt.v[2] );
  }
Vector3d Vector3d::cross ( const Vector3d alt) const [inline]

Definition at line 81 of file geometry.hpp.

                                              { 
    Vector3d c;
    c.v[0] = v[1]*alt.v[2] - v[2]*alt.v[1];
    c.v[1] = v[2]*alt.v[0] - v[0]*alt.v[2];
    c.v[2] = v[0]*alt.v[1] - v[1]*alt.v[0];
    return c;
  }
double Vector3d::dot ( const Vector3d alt) const [inline]

Definition at line 77 of file geometry.hpp.

                                          {
    return v[0]*alt.v[0] + v[1]*alt.v[1] + v[2]*alt.v[2];
  }
double Vector3d::length ( ) const [inline]

Definition at line 44 of file geometry.hpp.

                       {
    return sqrt( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] );
  }
Vector3d Vector3d::normalize ( ) const [inline]

Definition at line 48 of file geometry.hpp.

                             {
    double length = this->length();
    return Vector3d( v[0]/length, v[1]/length, v[2]/length );
  }
Vector3d Vector3d::operator* ( double  d) const [inline]

Definition at line 65 of file geometry.hpp.

                                       {
    return scale(d);
  }
Vector3d Vector3d::operator+ ( const Vector3d alt) const [inline]

Definition at line 73 of file geometry.hpp.

                                                  {
    return add(alt);
  }
Vector3d Vector3d::operator- ( ) const [inline]

Definition at line 53 of file geometry.hpp.

                             {
    return Vector3d(-v[0], -v[1], -v[2]);
  }
Vector3d Vector3d::projection ( const Vector3d v) const [inline]

project v onto this vector, return the result

Definition at line 99 of file geometry.hpp.

                                                 {
    return scale( this->dot(v) / this->dot(*this) );
  }
Vector3d Vector3d::reverse ( void  ) const [inline]

Definition at line 57 of file geometry.hpp.

                           { 
    return -(*this);
  }
Vector3d Vector3d::rotate_about ( const Vector3d v_p,
double  theta_p,
bool  degrees = true 
) const [inline]

Definition at line 89 of file geometry.hpp.

                                                                                          {
    Vector3d v = v_p.normalize();
    double theta = theta_p;
    if( degrees ) { theta *= M_PI / 180.0; }
    double cos_t = cos( theta );
    Vector3d ret = scale(cos_t) + v.scale((1.0-cos_t)*(dot(v))) + cross(v).scale( sin(theta) );
    return ret;
  }
Vector3d Vector3d::scale ( double  d) const [inline]

Definition at line 61 of file geometry.hpp.

                                   {
    return Vector3d(v[0]*d, v[1]*d, v[2]*d);
  }

Member Data Documentation

double Vector3d::v[3]

Definition at line 21 of file geometry.hpp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines