Vector3

Defines a 3D vector class with operators.

All class functions are defined inline.


[ GAMB | Source | Keywords | Summary | Ancestors | All Members | Descendants ]

Quick Index

AUTHORS
CHANGES LOG
GOALS
USAGE

Class Summary

class Vector3

{
public:
// define real type.
typedef float real;
// Constructors.
Vector3() ;
Vector3(const real& nx, const real& ny, const real& nz) ;
Vector3(const real x[3]) ;
Vector3(const double x[3]) ;
// Inspection.
Vector3 position() const ;
real x() const ;
real x(const unsigned short coord) const ;
bool isZero() const ;
real norm() const ;
real norm2() const ;
real dist(const Vector3& p) const ;
real dist2(const Vector3& p) const ;
const real& operator[](const unsigned short coord) const ;
Vector3 getPerpendicularVector() const ;
Vector3 getUnitVector() const ;
// Operators.
bool operator==(const Vector3& v) const ;
friend Vector3 operator+(const Vector3& p1, const Vector3& p2) ;
friend Vector3 operator-(const Vector3& p1, const Vector3& p2) ;
friend Vector3 operator-(const Vector3& p) ;
friend real operator*(const Vector3& p1, const Vector3& p2) ;
friend Vector3 operator*(const Vector3& p, const real& m) ;
friend Vector3 operator*(const real& m, const Vector3& p) ;
friend Vector3 operator/(const Vector3& p, const real& m) ;
friend Vector3 operator&(const Vector3& p1, const Vector3& p2) ;
friend real operator|(const Vector3& p1, const Vector3& p2) ;
friend real operator^(const Vector3& p1, const Vector3& p2) ;
Vector3& operator+=(const Vector3& p) ;
Vector3& operator-=(const Vector3& p) ;
Vector3& operator*=(const real& m) ;
Vector3& operator/=(const real& m) ;
friend ostream& operator<<(ostream& s, const Vector3& v) ;
friend istream& operator>>(istream& s, Vector3& v) ;
void output(FILE* outputFile) const ;
protected:
}; // Vector3

Back to the top of Vector3


AUTHORS

Meir Fuchs. (meirfux@math.tau.ac.il)

Copyright: SAMBA group, Tel-Aviv Univ. Israel, 1997.

Back to the top of Vector3


CHANGES LOG

Back to the top of Vector3


GOALS

Since most of the work on protein structure is done in 3D space, a fast, well designed 3D vector class was in place. Knowing the dimension is 3 allows for a fast, loopless implemetation of Vector3 and Matrix3 to be written.

Back to the top of Vector3


USAGE

Many 3D vector operations are supplied including vector addition and subtraction, dot-product mult., multiplication by scalar, distance and angular operators.

A new Vector3 may be constructed using 3 floats or an array of 3 floats.

    Vector3 v(1.0, 2.0, 3.0);
    float x[3];
    Vector3 v(x);

Coordinates may be accessed using the x(int) method which returns the vector's given coordinate (1..3) or using the [] operator (0..2).

    if (v[0] == v.x(1))  cout << "OK\n";

Addition, subtraction, multiplication and division by scalar, dot-product distance, angle.

    w = u+v;                           // addition
    w-= v;                             // in-place subtraction w==u
    if ((w|u) == 0) cout << "OK\n";    // distance operator |
    if (w^u == 0) cout << "OK\n";      // angle operator ^
    w=2*w;                             // multiplicatio by scalar
    float f=w*v;                       // dot-product;

Back to the top of Vector3


typedef float real;

Defines the type with which coordinates are defined. Changing this to double will casue the Vector3 and Matrix3 classes to work with double precision coordinates. float was chosen for considerations of speed. double precision is rarely needed since strctural data is inexact.

  typedef float real;

Back to the top of Vector3


Vector3() ;

Initialize to the 0 vector.

  Vector3()                                  
;

Function is currently defined inline.


Back to the top of Vector3


Vector3(const real& nx, const real& ny, const real& nz) ;

Initialize using 3 coordinates x,y,z.

  Vector3(const real& nx, const real& ny, const real& nz)                                             
;

Function is currently defined inline.


Back to the top of Vector3


Vector3(const real x[3]) ;

initialize using 3 coordinates in array.

  Vector3(const real x[3])                                                         
;

Function is currently defined inline.


Back to the top of Vector3


Vector3(const double x[3]) ;

initialize using 3 double precision coordinates in array.

  Vector3(const double x[3])                                                         
;

Function is currently defined inline.


Back to the top of Vector3


Vector3 position() const ;

Returns position (redundant function)

  Vector3 position() const               
;

Function is currently defined inline.


Back to the top of Vector3


real x() const ;

return the x, y or z coordinates.

  real x() const                       
;

Function is currently defined inline.


Back to the top of Vector3


real x(const unsigned short coord) const ;

Returns x=x(1), y=x(2) or z=x(3) coordinate. If other values are given result are unexpected.

  real x(const unsigned short coord) const                             
;

Function is currently defined inline.


Back to the top of Vector3


bool isZero() const ;

Returns true if the vector is the zero vector
Author: Oranit Dror (oranit@tau.ac.il)

  bool isZero() const                                                               
;

Function is currently defined inline.


Back to the top of Vector3


real norm() const ;

Return Vector3's distance from origin.

  real norm() const                                
;

Function is currently defined inline.


Back to the top of Vector3


real norm2() const ;

Return Vector3's squared distance ffrom origin.

  real norm2() const                                                
;

Function is currently defined inline.


Back to the top of Vector3


real dist(const Vector3& p) const ;

Returns Vector3's distance from Vector3 p.

  real dist(const Vector3& p) const                                 
;

Function is currently defined inline.


Back to the top of Vector3


real dist2(const Vector3& p) const ;

Returns Vector3's distance squared from Vector3 p.

  real dist2(const Vector3& p) const                                                                                                                   
;

Function is currently defined inline.


Back to the top of Vector3


const real& operator[](const unsigned short coord) const ;

Treats vector like a real array. Acceptable indices 0, 1, 2. Other indices may cause run-time errors.

  const real& operator[](const unsigned short coord) const                          
;

Function is currently defined inline.


Back to the top of Vector3


Vector3 getPerpendicularVector() const ;

Returns a perpendicular vector (A zero vector is returned in case of a zero vector).
Author: Oranit Dror (oranit@tau.ac.il)

  Vector3 getPerpendicularVector() const                                                                                                                                                                                                                                                              
;

Function is currently defined inline.


Back to the top of Vector3


Vector3 getUnitVector() const ;

Returns a unit vector in the same direction (A zero vector is returned in case of a zero vector).
Author: Oranit Dror (oranit@tau.ac.il)

  Vector3 getUnitVector() const                                      ;

Function is currently defined inline.


Back to the top of Vector3


bool operator==(const Vector3& v) const ;

Returns true if the two vectors have the same coordinates Author: Oranit Dror (oranit@tau.ac.il)

  bool operator==(const Vector3& v) const                                                                       
;

Function is currently defined inline.


Back to the top of Vector3


friend Vector3 operator+(const Vector3& p1, const Vector3& p2) ;

Returns Vector3 addition of two Vector3s.

  friend Vector3 operator+(const Vector3& p1, const Vector3& p2)                                                                             
;

Function is currently defined inline.


Back to the top of Vector3


friend Vector3 operator-(const Vector3& p1, const Vector3& p2) ;

Returns Vector3 subtraction of two Vector3s.

  friend Vector3 operator-(const Vector3& p1, const Vector3& p2)                                                                             
;

Function is currently defined inline.


Back to the top of Vector3


friend Vector3 operator-(const Vector3& p) ;

Returns Vector3 negative.

  friend Vector3 operator-(const Vector3& p)                                                     
;

Function is currently defined inline.


Back to the top of Vector3


friend real operator*(const Vector3& p1, const Vector3& p2) ;

Returns dot product of two Vector3s.

  friend real operator*(const Vector3& p1, const Vector3& p2)                                                                  
;

Function is currently defined inline.


Back to the top of Vector3


friend Vector3 operator*(const Vector3& p, const real& m) ;

Returns vector multiplied by scalar m.

  friend Vector3 operator*(const Vector3& p, const real& m)                                                        
;

Function is currently defined inline.


Back to the top of Vector3


friend Vector3 operator*(const real& m, const Vector3& p) ;

Returns vector multiplied by scalar m.

  friend Vector3 operator*(const real& m, const Vector3& p)                                                        
;

Function is currently defined inline.


Back to the top of Vector3


friend Vector3 operator/(const Vector3& p, const real& m) ;

Returns vector divided by scalar m.

  friend Vector3 operator/(const Vector3& p, const real& m)                                                        
;

Function is currently defined inline.


Back to the top of Vector3


friend Vector3 operator&(const Vector3& p1, const Vector3& p2) ;

Returns vector that is vertical to both vectors.

  friend Vector3 operator&(const Vector3& p1, const Vector3& p2)                                                                                                                                       
;

Function is currently defined inline.


Back to the top of Vector3


friend real operator|(const Vector3& p1, const Vector3& p2) ;

Returns distance between 2 Vector3s (similar to dist).

  friend real operator|(const Vector3& p1, const Vector3& p2)                              
;

Function is currently defined inline.


Back to the top of Vector3


friend real operator^(const Vector3& p1, const Vector3& p2) ;

Returns angle between p1 and p2 in radians.

  friend real operator^(const Vector3& p1, const Vector3& p2)                                                                                                                                                 
;

Function is currently defined inline.


Back to the top of Vector3


Vector3& operator+=(const Vector3& p) ;

Vector3 addition of another Vector3's coordinates.

  Vector3& operator+=(const Vector3& p)                                                                        
;

Function is currently defined inline.


Back to the top of Vector3


Vector3& operator-=(const Vector3& p) ;

Vector3 subtraction of another Vector3's coordinates.

  Vector3& operator-=(const Vector3& p)                                                                        
;

Function is currently defined inline.


Back to the top of Vector3


Vector3& operator*=(const real& m) ;

Multiplies coordinates by scalar m.

  Vector3& operator*=(const real& m)                                                         
;

Function is currently defined inline.


Back to the top of Vector3


Vector3& operator/=(const real& m) ;

Divides coordinates by scalar m.

  Vector3& operator/=(const real& m)                                                         
;

Function is currently defined inline.


Back to the top of Vector3


friend ostream& operator<<(ostream& s, const Vector3& v) ;

Outputs coordinates delimited by single space.

  friend ostream& operator<<(ostream& s, const Vector3& v)                                                                
;

Function is currently defined inline.


Back to the top of Vector3


friend istream& operator>>(istream& s, Vector3& v) ;

Inputs coordinates delimited by single space.

  friend istream& operator>>(istream& s, Vector3& v)                                                  
;

Function is currently defined inline.


Back to the top of Vector3


void output(FILE* outputFile) const ;

Outputs the vector's coordinates delimited by a single space.
Author: Oranit Dror (oranit@tau.ac.il)

  void output(FILE* outputFile) const                                                             
;

Function is currently defined inline.


Back to the top of Vector3


All Members

public:
// define real type.
typedef float real;
// Inspection.
Vector3 position() const ;
real x() const ;
real x(const unsigned short coord) const ;
bool isZero() const ;
real norm() const ;
real norm2() const ;
real dist(const Vector3& p) const ;
real dist2(const Vector3& p) const ;
const real& operator[](const unsigned short coord) const ;
Vector3 getPerpendicularVector() const ;
Vector3 getUnitVector() const ;
// Operators.
bool operator==(const Vector3& v) const ;
friend Vector3 operator+(const Vector3& p1, const Vector3& p2) ;
friend Vector3 operator-(const Vector3& p1, const Vector3& p2) ;
friend Vector3 operator-(const Vector3& p) ;
friend real operator*(const Vector3& p1, const Vector3& p2) ;
friend Vector3 operator*(const Vector3& p, const real& m) ;
friend Vector3 operator*(const real& m, const Vector3& p) ;
friend Vector3 operator/(const Vector3& p, const real& m) ;
friend Vector3 operator&(const Vector3& p1, const Vector3& p2) ;
friend real operator|(const Vector3& p1, const Vector3& p2) ;
friend real operator^(const Vector3& p1, const Vector3& p2) ;
Vector3& operator+=(const Vector3& p) ;
Vector3& operator-=(const Vector3& p) ;
Vector3& operator*=(const real& m) ;
Vector3& operator/=(const real& m) ;
friend ostream& operator<<(ostream& s, const Vector3& v) ;
friend istream& operator>>(istream& s, Vector3& v) ;
void output(FILE* outputFile) const ;
protected:

Back to the top of Vector3


Ancestors

Class does not inherit from any other class.

Back to the top of Vector3


Descendants

Back to the top of Vector3


Generated from source by the Cocoon utilities on Sun Nov 15 13:35:26 2009 .

Report problems to jkotula@unimax.com