2 #ifndef vgl_vector_2d_h_ 3 #define vgl_vector_2d_h_ 18 # include <vcl_msvc_warnings.h> 35 inline T
x()
const {
return x_; }
36 inline T
y()
const {
return y_; }
44 #if 0 // The defaults do exactly what they should do... 49 x_=
v.x();
y_=
v.y();
return *
this; }
55 inline void set(T vx, T vy) {
x_=vx;
y_=vy; }
71 std::istream&
read(std::istream& is);
74 #define v vgl_vector_2d<T> 80 template <
class T> std::ostream&
operator<<(std::ostream& s,
v const& p);
87 template <
class T> std::istream&
operator>>(std::istream& s,
v& p);
94 template <
class T>
inline double length(
v const& a) {
return a.length(); }
98 template <
class T>
inline T
sqr_length(
v const& a) {
return a.sqr_length(); }
102 template <
class T>
inline v operator+(
v const& a,
v const& b) {
return v(a.x()+b.x(), a.y()+b.y()); }
106 template <
class T>
inline v operator-(
v const& a,
v const& b) {
return v(a.x()-b.x(), a.y()-b.y()); }
110 template <
class T>
inline v&
operator+=(
v& a,
v const& b) { a.x_+=b.x_; a.y_+=b.y_;
return a; }
114 template <
class T>
inline v&
operator-=(
v& a,
v const& b) { a.x_-=b.x_; a.y_-=b.y_;
return a; }
122 template <
class T>
inline v operator-(
v const& b) {
return v(-b.x(), -b.y()); }
126 template <
class T>
inline v operator*(
double s,
v const& b) {
return v(T(s*b.x()), T(s*b.y())); }
130 template <
class T>
inline v operator*(
v const& a,
double s) {
return v(T(a.x()*s), T(a.y()*s)); }
136 template <
class T>
inline v operator/(
v const& a,
double s) {
return v(T(a.x()/s), T(a.y()/s)); }
140 template <
class T>
inline v&
operator*=(
v& a,
double s) { a.set(T(a.x()*s), T(a.y()*s));
return a; }
144 template <
class T>
inline v&
operator/=(
v& a,
double s) { a.set(T(a.x()/s), T(a.y()/s));
return a; }
148 template <
class T>
inline T
dot_product(
v const& a,
v const& b) {
return a.x()*b.x()+a.y()*b.y(); }
152 template <
class T>
inline T
inner_product(
v const& a,
v const& b) {
return a.x()*b.x()+a.y()*b.y(); }
156 template <
class T>
inline T
cross_product(
v const& a,
v const& b) {
return a.x()*b.y()-a.y()*b.x(); }
164 template <
class T>
double angle(
v const& a,
v const& b);
175 template <
class T>
bool orthogonal(
v const& a,
v const& b,
double eps=0.0);
181 template <
class T>
bool parallel(
v const& a,
v const& b,
double eps=0.0);
188 template <
class T>
inline double operator/(
v const& a,
v const& b)
194 template <
class T>
inline v&
normalize(
v& a) {
double l=a.length();
return l?a/=
l:a; }
199 template <
class T>
inline v normalized(
v const& a) {
double l=a.length();
return l?a/
l:a; }
207 #define VGL_VECTOR_2D_INSTANTIATE(T) extern "please include vgl/vgl_vector_2d.hxx first" 209 #endif // vgl_vector_2d_h_ std::istream & read(std::istream &is)
Read from stream, possibly with formatting.
v normalized(v const &a)
Return a normalised version of a.
T dot_product(v const &a, v const &b)
dot product or inner product of two vectors.
T inner_product(v const &a, v const &b)
dot product or inner product of two vectors.
v & operator/=(v &a, double s)
a/=f: inversely scale the vector (scale must be nonzero).
Direction vector in Euclidean 2D space, templated by type of element.
v & normalize(v &a)
Normalise by dividing through by the length, thus returning a length 1 vector.
vgl_homg_point_1d< T > & operator-=(vgl_homg_point_1d< T > &p, T v)
Subtracting a number from a point is the same as adding the inverse number.
v & operator *=(v &a, double s)
a*=f: scale the vector.
T sqr_length() const
Return the squared length of this vector.
vgl_homg_point_1d< T > & operator+=(vgl_homg_point_1d< T > &p, T v)
Adding a number to a 1-D point translates that point.
bool orthogonal(v const &a, v const &b, double eps=0.0)
are two vectors orthogonal, i.e., is their dot product zero?.
double length() const
Return the length of this vector.
std::ostream & operator<<(std::ostream &s, vgl_orient_box_3d< Type > const &p)
Write box to stream.
vgl_vector_2d(T vx, T vy)
Creates the vector (x,y).
v rotated(v const &a, double angle)
Return a CCW rotated version of a (angle in radian).
void set(T vx, T vy)
Assignment.
double length(v const &a)
Return the length of a vector.
vgl_vector_2d()
Creates the vector (0,0) of zero length.
T cross_product(v const &a, v const &b)
cross product of two vectors (area of enclosed parallellogram).
v operator/(v const &a, double s)
c=b/f: return an inversely scaled version of the vector (scale must be nonzero).
vgl_homg_point_1d< T > operator+(vgl_homg_point_1d< T > const &p, T v)
Adding a number to a 1-D point translates that point.
double signed_angle(v const &a, v const &b)
signed angle between two vectors (in radians, between -Pi and Pi).
bool operator==(vgl_vector_2d< T >const &v) const
Comparison.
std::istream & operator>>(std::istream &is, vgl_orient_box_3d< Type > &p)
Read box from stream.
T sqr_length(v const &a)
Return the squared length of a vector.
double angle(v const &a, v const &b)
smallest angle between two vectors (in radians, between 0 and Pi).
vgl_homg_point_1d< T > operator *(vnl_matrix_fixed< T, 2, 2 > const &m, vgl_homg_point_1d< T > const &p)
Transform a point through a 2x2 projective transformation matrix.
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?.
bool operator!=(vgl_vector_2d< T >const &v) const
double cos_angle(v const &a, v const &b)
cosine of the angle between two vectors.
T operator-(vgl_homg_point_1d< T > const &p1, vgl_homg_point_1d< T > const &p2)
The difference of two points is the distance between the two.