Public Member Functions | Public Attributes | Related Functions
vgl_vector_3d< T > Class Template Reference

Direction vector in Euclidean 3D space, templated by type of element. More...

#include <vgl_vector_3d.h>

Inheritance diagram for vgl_vector_3d< T >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

x () const
y () const
z () const
 vgl_vector_3d ()
 Creates the vector (0,0,0) of zero length.
 vgl_vector_3d (T vx, T vy, T vz)
 Creates the vector (vx,vy,vz).
 vgl_vector_3d (const T v[3])
 Creates the vector (vx,vy,vz).
void set (T vx, T vy, T vz)
 Assignment.
void set (T const v[3])
 Set x, y and z.
bool operator== (vgl_vector_3d< T >const &v) const
 Comparison.
bool operator!= (vgl_vector_3d< T >const &v) const
double length () const
 Return the length of this vector.
sqr_length () const
 Return the squared length of this vector.
vgl_vector_3d< T > orthogonal_vectors (double s) const
 One-parameter family of unit vectors that are orthogonal to *this, v(s).

Public Attributes

x_
y_
z_

Related Functions

(Note that these are not member functions.)

vcl_istream & read (vcl_istream &is)
 Read from stream, possibly with formatting.
template<class T >
vcl_ostream & operator<< (vcl_ostream &s, v const &p)
 Write "<vgl_vector_3d x,y,z> " to stream.
template<class T >
vcl_istream & operator>> (vcl_istream &s, v &p)
 Read from stream, possibly with formatting.
template<class T >
double length (v const &a)
 Return the length of a vector.
template<class T >
sqr_length (v const &a)
 Return the squared length of a vector.
template<class T >
operator+ (v const &a, v const &b)
 c=a+b: add two vectors.
template<class T >
operator- (v const &a, v const &b)
 c=a-b: subtract two vectors.
template<class T >
v & operator+= (v &a, v const &b)
 a+=b: add b to a and return a.
template<class T >
v & operator-= (v &a, v const &b)
 a-=b: subtract b from a and return a.
template<class T >
operator+ (v const &b)
 +b: unary plus operator (no-op).
template<class T >
operator- (v const &b)
template<class T >
operator* (double s, v const &b)
 c=f*b: return a scaled version of the vector.
template<class T >
operator* (v const &a, double s)
 c=a*f: return a scaled version of the vector.
template<class T >
operator/ (v const &a, double s)
 c=b/f: return an inversely scaled version of the vector (scale must be nonzero).
template<class T >
v & operator*= (v &a, double s)
 a*=f: scale the vector.
template<class T >
v & operator/= (v &a, double s)
 a/=f: inversely scale the vector (scale must be nonzero).
template<class T >
dot_product (v const &a, v const &b)
 dot product or inner product of two vectors.
template<class T >
inner_product (v const &a, v const &b)
 dot product or inner product of two vectors.
template<class T >
cross_product (v const &a, v const &b)
 cross product of two vectors (is orthogonal to both).
template<class T >
double cos_angle (v const &a, v const &b)
 cosine of the angle between two vectors.
template<class T >
double angle (v const &a, v const &b)
 smallest angle between two vectors (in radians, between 0 and Pi).
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?.
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?.
template<class T >
double operator/ (v const &a, v const &b)
 f=a/b: return the ratio of two vectors, if they are parallel.
template<class T >
v & normalize (v &a)
 Normalise by dividing through by the length, thus returning a length 1 vector.
template<class T >
normalized (v const &a)
 Return a normalised version of a.
template<class T >
vcl_istream & operator>> (vcl_istream &is, vgl_vector_3d< T > &p)
 Read from stream, possibly with formatting.

Detailed Description

template<class T>
class vgl_vector_3d< T >

Direction vector in Euclidean 3D space, templated by type of element.

(typically float or double). A vgl_vector_3d<T> represents the difference (or connecting vector) between two vgl_point_3d<T>s.

Use this class to do arithmetic (adding and scaling) in 3d geometric space.

Definition at line 30 of file vgl_vector_3d.h.


Constructor & Destructor Documentation

template<class T>
vgl_vector_3d< T >::vgl_vector_3d ( ) [inline]

Creates the vector (0,0,0) of zero length.

Definition at line 41 of file vgl_vector_3d.h.

template<class T>
vgl_vector_3d< T >::vgl_vector_3d ( vx,
vy,
vz 
) [inline]

Creates the vector (vx,vy,vz).

Definition at line 44 of file vgl_vector_3d.h.

template<class T>
vgl_vector_3d< T >::vgl_vector_3d ( const T  v[3]) [inline]

Creates the vector (vx,vy,vz).

Definition at line 47 of file vgl_vector_3d.h.


Member Function Documentation

template<class T >
double vgl_vector_3d< T >::length ( ) const

Return the length of this vector.

Definition at line 16 of file vgl_vector_3d.txx.

template<class T>
bool vgl_vector_3d< T >::operator!= ( vgl_vector_3d< T >const &  v) const [inline]

Definition at line 68 of file vgl_vector_3d.h.

template<class T>
bool vgl_vector_3d< T >::operator== ( vgl_vector_3d< T >const &  v) const [inline]

Comparison.

Definition at line 66 of file vgl_vector_3d.h.

template<class T >
vgl_vector_3d< T > vgl_vector_3d< T >::orthogonal_vectors ( double  s) const

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

The one-parameter family of unit vectors that are orthogonal to *this, 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.
Deprecated:
Use global function orthogonal_vectors(vgl_vector_3d<T > const& a, double s) instead.

The parameterization is such that 0<=s<1, v(0)==v(1)

Definition at line 24 of file vgl_vector_3d.txx.

template<class T>
void vgl_vector_3d< T >::set ( vx,
vy,
vz 
) [inline]

Assignment.

Definition at line 60 of file vgl_vector_3d.h.

template<class T>
void vgl_vector_3d< T >::set ( T const  v[3]) [inline]

Set x, y and z.

Definition at line 63 of file vgl_vector_3d.h.

template<class T>
T vgl_vector_3d< T >::sqr_length ( ) const [inline]

Return the squared length of this vector.

Definition at line 74 of file vgl_vector_3d.h.

template<class T>
T vgl_vector_3d< T >::x ( ) const [inline]

Definition at line 36 of file vgl_vector_3d.h.

template<class T>
T vgl_vector_3d< T >::y ( ) const [inline]

Definition at line 37 of file vgl_vector_3d.h.

template<class T>
T vgl_vector_3d< T >::z ( ) const [inline]

Definition at line 38 of file vgl_vector_3d.h.


Friends And Related Function Documentation

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

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

template<class T >
double cos_angle ( v const &  a,
v const &  b 
) [related]

cosine of the angle between two vectors.

Definition at line 182 of file vgl_vector_3d.h.

template<class T >
v cross_product ( v const &  a,
v const &  b 
) [related]

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

Definition at line 177 of file vgl_vector_3d.h.

template<class T >
T dot_product ( v const &  a,
v const &  b 
) [related]

dot product or inner product of two vectors.

Definition at line 169 of file vgl_vector_3d.h.

template<class T >
T inner_product ( v const &  a,
v const &  b 
) [related]

dot product or inner product of two vectors.

Definition at line 173 of file vgl_vector_3d.h.

template<class T >
double length ( v const &  a) [related]

Return the length of a vector.

Definition at line 115 of file vgl_vector_3d.h.

template<class T >
v & normalize ( v &  a) [related]

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.

template<class T >
v normalized ( v const &  a) [related]

Return a normalised version of a.

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

Definition at line 216 of file vgl_vector_3d.h.

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

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

Definition at line 147 of file vgl_vector_3d.h.

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

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

Definition at line 151 of file vgl_vector_3d.h.

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

a*=f: scale the vector.

Definition at line 161 of file vgl_vector_3d.h.

template<class T >
v operator+ ( v const &  a,
v const &  b 
) [related]

c=a+b: add two vectors.

Definition at line 123 of file vgl_vector_3d.h.

template<class T >
v operator+ ( v const &  b) [related]

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

Definition at line 139 of file vgl_vector_3d.h.

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

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

Definition at line 131 of file vgl_vector_3d.h.

template<class T >
v operator- ( v const &  a,
v const &  b 
) [related]

c=a-b: subtract two vectors.

Definition at line 127 of file vgl_vector_3d.h.

template<class T >
v operator- ( v const &  b) [related]

-a: unary minus operator (additive inverse).

Definition at line 143 of file vgl_vector_3d.h.

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

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

Definition at line 135 of file vgl_vector_3d.h.

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

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.

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

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.

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

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

Definition at line 165 of file vgl_vector_3d.h.

template<class T >
vcl_ostream & operator<< ( vcl_ostream &  s,
v const &  p 
) [related]

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

template<class T >
vcl_istream & operator>> ( vcl_istream &  s,
v &  p 
) [related]

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)"

template<class T >
vcl_istream & operator>> ( vcl_istream &  is,
vgl_vector_3d< T > &  p 
) [related]

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)"

Definition at line 161 of file vgl_vector_3d.txx.

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

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.

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

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.

template<class T >
vcl_istream & read ( vcl_istream &  is) [related]

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)"

Definition at line 131 of file vgl_vector_3d.txx.

template<class T >
T sqr_length ( v const &  a) [related]

Return the squared length of a vector.

Definition at line 119 of file vgl_vector_3d.h.


Member Data Documentation

template<class T>
T vgl_vector_3d< T >::x_

Definition at line 33 of file vgl_vector_3d.h.

template<class T>
T vgl_vector_3d< T >::y_

Definition at line 34 of file vgl_vector_3d.h.

template<class T>
T vgl_vector_3d< T >::z_

Definition at line 35 of file vgl_vector_3d.h.


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