Classes | Macros | Functions
vgl_vector_3d.h File Reference

direction vector in Euclidean 3D space More...

#include <iosfwd>

Go to the source code of this file.

Classes

class  vgl_vector_3d< T >
 Direction vector in Euclidean 3D space, templated by type of element. More...
 

Macros

#define v   vgl_vector_3d<T>
 
#define VGL_VECTOR_3D_INSTANTIATE(T)   extern "please include vgl/vgl_vector_3d.hxx first"
 

Functions

template<class T >
std::ostream & operator<< (std::ostream &s, v const &p)
 Write "<vgl_vector_3d x,y,z> " to stream. More...
 
template<class T >
std::istream & operator>> (std::istream &s, v &p)
 Read from stream, possibly with formatting. More...
 
template<class T >
double length (v const &a)
 Return the length of a vector. More...
 
template<class T >
sqr_length (v const &a)
 Return the squared length of a vector. More...
 
template<class T >
v operator+ (v const &a, v const &b)
 c=a+b: add two vectors. More...
 
template<class T >
v operator- (v const &a, v const &b)
 c=a-b: subtract two vectors. More...
 
template<class T >
voperator+= (v &a, v const &b)
 a+=b: add b to a and return a. More...
 
template<class T >
voperator-= (v &a, v const &b)
 a-=b: subtract b from a and return a. More...
 
template<class T >
v operator+ (v const &b)
 +b: unary plus operator (no-op). More...
 
template<class T >
v operator- (v const &b)
 -a: unary minus operator (additive inverse). More...
 
template<class T >
v operator * (double s, v const &b)
 c=f*b: return a scaled version of the vector. More...
 
template<class T >
v operator * (v const &a, double s)
 c=a*f: return a scaled version of the vector. More...
 
template<class T >
v operator/ (v const &a, double s)
 c=b/f: return an inversely scaled version of the vector (scale must be nonzero). More...
 
template<class T >
voperator *= (v &a, double s)
 a*=f: scale the vector. More...
 
template<class T >
voperator/= (v &a, double s)
 a/=f: inversely scale the vector (scale must be nonzero). More...
 
template<class T >
dot_product (v const &a, v const &b)
 dot product or inner product of two vectors. More...
 
template<class T >
inner_product (v const &a, v const &b)
 dot product or inner product of two vectors. More...
 
template<class T >
v cross_product (v const &a, v const &b)
 cross product of two vectors (is orthogonal to both). More...
 
template<class T >
double cos_angle (v const &a, v const &b)
 cosine of the angle between two vectors. More...
 
template<class T >
double angle (v const &a, v const &b)
 smallest angle between two vectors (in radians, between 0 and Pi). More...
 
template<class T >
bool orthogonal (v const &a, v const &b, double eps=0.0)
 are two vectors orthogonal, i.e., is their dot product zero?. More...
 
template<class T >
bool parallel (v const &a, v const &b, double eps=0.0)
 are two vectors parallel, i.e., is one a scalar multiple of the other?. More...
 
template<class T >
double operator/ (v const &a, v const &b)
 f=a/b: return the ratio of two vectors, if they are parallel. More...
 
template<class T >
vnormalize (v &a)
 Normalise by dividing through by the length, thus returning a length 1 vector. More...
 
template<class T >
v normalized (v const &a)
 Return a normalised version of a. More...
 
template<class T >
v orthogonal_vectors (v const &a, double s)
 One-parameter family of unit vectors that are orthogonal to a, v(s). More...
 

Detailed Description

direction vector in Euclidean 3D space

Author
Peter Vanroose
Date
27 June, 2001
 Modifications
 2001-07-05 Peter Vanroose  Added orthogonal(); operator* now accepts double
 2009-05-21 Peter Vanroose  istream operator>> re-implemented

Definition in file vgl_vector_3d.h.

Macro Definition Documentation

◆ v

#define v   vgl_vector_3d<T>

Definition at line 95 of file vgl_vector_3d.h.

◆ VGL_VECTOR_3D_INSTANTIATE

#define VGL_VECTOR_3D_INSTANTIATE (   T)    extern "please include vgl/vgl_vector_3d.hxx first"

Definition at line 229 of file vgl_vector_3d.h.

Function Documentation

◆ angle()

template<class T >
double angle ( v const &  a,
v const &  b 
)

smallest angle between two vectors (in radians, between 0 and Pi).

◆ cos_angle()

template<class T >
double cos_angle ( v const &  a,
v const &  b 
)
inline

cosine of the angle between two vectors.

Definition at line 182 of file vgl_vector_3d.h.

◆ cross_product()

template<class T >
v cross_product ( v const &  a,
v const &  b 
)
inline

cross product of two vectors (is orthogonal to both).

Definition at line 177 of file vgl_vector_3d.h.

◆ dot_product()

template<class T >
T dot_product ( v const &  a,
v const &  b 
)
inline

dot product or inner product of two vectors.

Definition at line 169 of file vgl_vector_3d.h.

◆ inner_product()

template<class T >
T inner_product ( v const &  a,
v const &  b 
)
inline

dot product or inner product of two vectors.

Definition at line 173 of file vgl_vector_3d.h.

◆ length()

template<class T >
double length ( v const &  a)
inline

Return the length of a vector.

Definition at line 115 of file vgl_vector_3d.h.

◆ normalize()

template<class T >
v& normalize ( v a)
inline

Normalise by dividing through by the length, thus returning a length 1 vector.

If a is zero length, return (0,0).

Definition at line 211 of file vgl_vector_3d.h.

◆ normalized()

template<class T >
v normalized ( v const &  a)
inline

Return a normalised version of a.

If a is zero length, return (0,0).

Definition at line 216 of file vgl_vector_3d.h.

◆ operator *() [1/2]

template<class T >
v operator * ( double  s,
v const &  b 
)
inline

c=f*b: return a scaled version of the vector.

Definition at line 147 of file vgl_vector_3d.h.

◆ operator *() [2/2]

template<class T >
v operator * ( v const &  a,
double  s 
)
inline

c=a*f: return a scaled version of the vector.

Definition at line 151 of file vgl_vector_3d.h.

◆ operator *=()

template<class T >
v& operator *= ( v a,
double  s 
)
inline

a*=f: scale the vector.

Definition at line 161 of file vgl_vector_3d.h.

◆ operator+() [1/2]

template<class T >
v operator+ ( v const &  a,
v const &  b 
)
inline

c=a+b: add two vectors.

Definition at line 123 of file vgl_vector_3d.h.

◆ operator+() [2/2]

template<class T >
v operator+ ( v const &  b)
inline

+b: unary plus operator (no-op).

Definition at line 139 of file vgl_vector_3d.h.

◆ operator+=()

template<class T >
v& operator+= ( v a,
v const &  b 
)
inline

a+=b: add b to a and return a.

Definition at line 131 of file vgl_vector_3d.h.

◆ operator-() [1/2]

template<class T >
v operator- ( v const &  a,
v const &  b 
)
inline

c=a-b: subtract two vectors.

Definition at line 127 of file vgl_vector_3d.h.

◆ operator-() [2/2]

template<class T >
v operator- ( v const &  b)
inline

-a: unary minus operator (additive inverse).

Definition at line 143 of file vgl_vector_3d.h.

◆ operator-=()

template<class T >
v& operator-= ( v a,
v const &  b 
)
inline

a-=b: subtract b from a and return a.

Definition at line 135 of file vgl_vector_3d.h.

◆ operator/() [1/2]

template<class T >
v operator/ ( v const &  a,
double  s 
)
inline

c=b/f: return an inversely scaled version of the vector (scale must be nonzero).

Note that the argument type is double, not T, to avoid rounding errors when type T has no multiplicative inverses (like T=int).

Definition at line 157 of file vgl_vector_3d.h.

◆ operator/() [2/2]

template<class T >
double operator/ ( v const &  a,
v const &  b 
)
inline

f=a/b: return the ratio of two vectors, if they are parallel.

(If not, return a "least squares" approximation.) Note that the return type is double, not T, since the ratio of e.g. two vgl_vector_3d<int> need not be an int.

Definition at line 205 of file vgl_vector_3d.h.

◆ operator/=()

template<class T >
v& operator/= ( v a,
double  s 
)
inline

a/=f: inversely scale the vector (scale must be nonzero).

Definition at line 165 of file vgl_vector_3d.h.

◆ operator<<()

template<class T >
std::ostream& operator<< ( std::ostream &  s,
v const &  p 
)

Write "<vgl_vector_3d x,y,z> " to stream.

◆ operator>>()

template<class T >
std::istream& operator>> ( std::istream &  s,
v p 
)

Read from stream, possibly with formatting.

Either just reads three blank-separated numbers, or reads three comma-separated numbers, or reads three numbers in parenthesized form "(123, 321, 567)"

◆ orthogonal()

template<class T >
bool orthogonal ( v const &  a,
v const &  b,
double  eps = 0.0 
)

are two vectors orthogonal, i.e., is their dot product zero?.

If the third argument is specified, it is taken as the "tolerance", i.e. in that case this function returns true if the vectors are almost orthogonal.

◆ orthogonal_vectors()

template<class T >
v orthogonal_vectors ( v const &  a,
double  s 
)

One-parameter family of unit vectors that are orthogonal to a, v(s).

To get two orthogonal vectors call this function twice with s=0 and s=0.25 for example.

Parameters
s0<=s<=1, v(0)==v(1)
Note
This function is not continuous near z==0. (Under the Hairy Ball theorem no such smooth function can exist.)
This vector need not be normalized but it should have non-zero length.

◆ parallel()

template<class T >
bool parallel ( v const &  a,
v const &  b,
double  eps = 0.0 
)

are two vectors parallel, i.e., is one a scalar multiple of the other?.

If the third argument is specified, it is taken as the "tolerance", i.e. in that case this function returns true if the vectors are almost parallel.

◆ sqr_length()

template<class T >
T sqr_length ( v const &  a)
inline

Return the squared length of a vector.

Definition at line 119 of file vgl_vector_3d.h.