Direction vector in Euclidean 2D space, templated by type of element. More...
#include <vgl_vector_2d.h>
Public Member Functions | |
T | x () const |
T | y () const |
vgl_vector_2d () | |
Creates the vector (0,0) of zero length. | |
vgl_vector_2d (T vx, T vy) | |
Creates the vector (x,y). | |
void | set (T vx, T vy) |
Assignment. | |
bool | operator== (vgl_vector_2d< T >const &v) const |
Comparison. | |
bool | operator!= (vgl_vector_2d< T >const &v) const |
double | length () const |
Return the length of this vector. | |
T | sqr_length () const |
Return the squared length of this vector. | |
vcl_istream & | read (vcl_istream &is) |
Read from stream, possibly with formatting. | |
Public Attributes | |
T | x_ |
T | y_ |
Related Functions | |
(Note that these are not member functions.) | |
template<class T > | |
vcl_ostream & | operator<< (vcl_ostream &s, v const &p) |
Write "<vgl_vector_2d x,y> " 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 > | |
T | sqr_length (v const &a) |
Return the squared length of a vector. | |
template<class T > | |
v | operator+ (v const &a, v const &b) |
c=a+b: add two vectors. | |
template<class T > | |
v | 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 > | |
v | operator+ (v const &b) |
+b: unary plus operator (no-op). | |
template<class T > | |
v | operator- (v const &b) |
template<class T > | |
v | operator* (double s, v const &b) |
c=f*b: return a scaled version of the vector. | |
template<class T > | |
v | operator* (v const &a, double s) |
c=a*f: return a scaled version of the vector. | |
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). | |
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 > | |
T | dot_product (v const &a, v const &b) |
dot product or inner product of two vectors. | |
template<class T > | |
T | inner_product (v const &a, v const &b) |
dot product or inner product of two vectors. | |
template<class T > | |
T | cross_product (v const &a, v const &b) |
cross product of two vectors (area of enclosed parallellogram). | |
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 > | |
double | signed_angle (v const &a, v const &b) |
signed angle between two vectors (in radians, between -Pi 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 > | |
v | normalized (v const &a) |
Return a normalised version of a. | |
template<class T > | |
v | rotated (v const &a, double angle) |
Return a CCW rotated version of a (angle in radian). |
Direction vector in Euclidean 2D space, templated by type of element.
(typically float or double). A vgl_vector_2d<T> represents the difference (or connecting vector) between two vgl_point_2d<T>s.
Use this class to do arithmetic (adding and scaling) in 2d geometric space.
Definition at line 30 of file vgl_vector_2d.h.
vgl_vector_2d< T >::vgl_vector_2d | ( | ) | [inline] |
Creates the vector (0,0) of zero length.
Definition at line 39 of file vgl_vector_2d.h.
vgl_vector_2d< T >::vgl_vector_2d | ( | T | vx, |
T | vy | ||
) | [inline] |
Creates the vector (x,y).
Definition at line 42 of file vgl_vector_2d.h.
double vgl_vector_2d< T >::length | ( | ) | const |
Return the length of this vector.
Definition at line 13 of file vgl_vector_2d.txx.
bool vgl_vector_2d< T >::operator!= | ( | vgl_vector_2d< T >const & | v | ) | const [inline] |
Definition at line 59 of file vgl_vector_2d.h.
bool vgl_vector_2d< T >::operator== | ( | vgl_vector_2d< T >const & | v | ) | const [inline] |
Comparison.
Definition at line 58 of file vgl_vector_2d.h.
vcl_istream & vgl_vector_2d< T >::read | ( | vcl_istream & | is | ) |
Read from stream, possibly with formatting.
Either just reads two blank-separated numbers, or reads two comma-separated numbers, or reads two numbers in parenthesized form "(123, 321)"
Definition at line 72 of file vgl_vector_2d.txx.
void vgl_vector_2d< T >::set | ( | T | vx, |
T | vy | ||
) | [inline] |
Assignment.
Definition at line 55 of file vgl_vector_2d.h.
T vgl_vector_2d< T >::sqr_length | ( | ) | const [inline] |
Return the squared length of this vector.
Definition at line 65 of file vgl_vector_2d.h.
T vgl_vector_2d< T >::x | ( | ) | const [inline] |
Definition at line 35 of file vgl_vector_2d.h.
T vgl_vector_2d< T >::y | ( | ) | const [inline] |
Definition at line 36 of file vgl_vector_2d.h.
double angle | ( | v const & | a, |
v const & | b | ||
) | [related] |
smallest angle between two vectors (in radians, between 0 and Pi).
double cos_angle | ( | v const & | a, |
v const & | b | ||
) | [related] |
cosine of the angle between two vectors.
Definition at line 160 of file vgl_vector_2d.h.
T cross_product | ( | v const & | a, |
v const & | b | ||
) | [related] |
cross product of two vectors (area of enclosed parallellogram).
Definition at line 156 of file vgl_vector_2d.h.
T dot_product | ( | v const & | a, |
v const & | b | ||
) | [related] |
dot product or inner product of two vectors.
Definition at line 148 of file vgl_vector_2d.h.
T inner_product | ( | v const & | a, |
v const & | b | ||
) | [related] |
dot product or inner product of two vectors.
Definition at line 152 of file vgl_vector_2d.h.
double length | ( | v const & | a | ) | [related] |
Return the length of a vector.
Definition at line 94 of file vgl_vector_2d.h.
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 194 of file vgl_vector_2d.h.
v normalized | ( | v const & | a | ) | [related] |
Return a normalised version of a.
If a is zero length, return (0,0).
Definition at line 199 of file vgl_vector_2d.h.
v operator* | ( | double | s, |
v const & | b | ||
) | [related] |
c=f*b: return a scaled version of the vector.
Definition at line 126 of file vgl_vector_2d.h.
v operator* | ( | v const & | a, |
double | s | ||
) | [related] |
c=a*f: return a scaled version of the vector.
Definition at line 130 of file vgl_vector_2d.h.
v & operator*= | ( | v & | a, |
double | s | ||
) | [related] |
a*=f: scale the vector.
Definition at line 140 of file vgl_vector_2d.h.
v operator+ | ( | v const & | a, |
v const & | b | ||
) | [related] |
c=a+b: add two vectors.
Definition at line 102 of file vgl_vector_2d.h.
v operator+ | ( | v const & | b | ) | [related] |
+b: unary plus operator (no-op).
Definition at line 118 of file vgl_vector_2d.h.
v & operator+= | ( | v & | a, |
v const & | b | ||
) | [related] |
a+=b: add b to a and return a.
Definition at line 110 of file vgl_vector_2d.h.
v operator- | ( | v const & | a, |
v const & | b | ||
) | [related] |
c=a-b: subtract two vectors.
Definition at line 106 of file vgl_vector_2d.h.
v operator- | ( | v const & | b | ) | [related] |
-a: unary minus operator (additive inverse).
Definition at line 122 of file vgl_vector_2d.h.
v & operator-= | ( | v & | a, |
v const & | b | ||
) | [related] |
a-=b: subtract b from a and return a.
Definition at line 114 of file vgl_vector_2d.h.
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 136 of file vgl_vector_2d.h.
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_2d<int> need not be an int.
Definition at line 188 of file vgl_vector_2d.h.
v & operator/= | ( | v & | a, |
double | s | ||
) | [related] |
a/=f: inversely scale the vector (scale must be nonzero).
Definition at line 144 of file vgl_vector_2d.h.
vcl_ostream & operator<< | ( | vcl_ostream & | s, |
v const & | p | ||
) | [related] |
Write "<vgl_vector_2d x,y> " to stream.
vcl_istream & operator>> | ( | vcl_istream & | s, |
v & | p | ||
) | [related] |
Read from stream, possibly with formatting.
Either just reads two blank-separated numbers, or reads two comma-separated numbers, or reads two numbers in parenthesized form "(123, 321)"
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.
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.
v rotated | ( | v const & | a, |
double | angle | ||
) | [related] |
Return a CCW rotated version of a (angle in radian).
double signed_angle | ( | v const & | a, |
v const & | b | ||
) | [related] |
signed angle between two vectors (in radians, between -Pi and Pi).
return the rotation angle to go from `a' to `b'
T sqr_length | ( | v const & | a | ) | [related] |
Return the squared length of a vector.
Definition at line 98 of file vgl_vector_2d.h.
T vgl_vector_2d< T >::x_ |
Definition at line 33 of file vgl_vector_2d.h.
T vgl_vector_2d< T >::y_ |
Definition at line 34 of file vgl_vector_2d.h.