2 #ifndef vgl_vector_3d_h_ 3 #define vgl_vector_3d_h_ 18 # include <vcl_msvc_warnings.h> 36 inline T
x()
const {
return x_; }
37 inline T
y()
const {
return y_; }
38 inline T
z()
const {
return z_; }
49 #if 0 // The defaults do exactly what they should do... 54 x_=
v.x();
y_=
v.y();
z_=
v.z();
return *
this; }
60 inline void set(T vx, T vy, T vz) {
x_=vx;
y_=vy;
z_=vz; }
67 return x_==
v.x() &&
y_==
v.y() &&
z_==
v.z(); }
92 std::istream&
read(std::istream& is);
95 #define v vgl_vector_3d<T> 101 template <
class T> std::ostream&
operator<<(std::ostream& s,
v const& p);
108 template <
class T> std::istream&
operator>>(std::istream& s,
v& p);
115 template <
class T>
inline double length(
v const& a) {
return a.length(); }
119 template <
class T>
inline T
sqr_length(
v const& a) {
return a.sqr_length(); }
123 template <
class T>
inline v operator+(
v const& a,
v const& b) {
return v(a.x()+b.x(), a.y()+b.y(), a.z()+b.z()); }
127 template <
class T>
inline v operator-(
v const& a,
v const& b) {
return v(a.x()-b.x(), a.y()-b.y(), a.z()-b.z()); }
131 template <
class T>
inline v&
operator+=(
v& a,
v const& b) { a.x_+=b.x_; a.y_+=b.y_; a.z_+=b.z_;
return a; }
135 template <
class T>
inline v&
operator-=(
v& a,
v const& b) { a.x_-=b.x_; a.y_-=b.y_; a.z_-=b.z_;
return a; }
143 template <
class T>
inline v operator-(
v const& b) {
return v(-b.x(), -b.y(), -b.z()); }
147 template <
class T>
inline v operator*(
double s,
v const& b) {
return v(T(s*b.x()), T(s*b.y()), T(s*b.z())); }
151 template <
class T>
inline v operator*(
v const& a,
double s) {
return v(T(a.x()*s), T(a.y()*s), T(a.z()*s)); }
157 template <
class T>
inline v operator/(
v const& a,
double s) {
return v(T(a.x()/s), T(a.y()/s), T(a.z()/s)); }
161 template <
class T>
inline v&
operator*=(
v& a,
double s) { a.set(T(a.x()*s), T(a.y()*s), T(a.z()*s));
return a; }
165 template <
class T>
inline v&
operator/=(
v& a,
double s) { a.set(T(a.x()/s), T(a.y()/s), T(a.z()/s));
return a; }
169 template <
class T>
inline T
dot_product(
v const& a,
v const& b) {
return a.x()*b.x()+a.y()*b.y()+a.z()*b.z(); }
173 template <
class T>
inline T
inner_product(
v const& a,
v const& b) {
return a.x()*b.x()+a.y()*b.y()+a.z()*b.z(); }
178 {
return v(a.y()*b.z()-a.z()*b.y(), a.z()*b.x()-a.x()*b.z(), a.x()*b.y()-a.y()*b.x()); }
186 template <
class T>
double angle(
v const& a,
v const& b);
192 template <
class T>
bool orthogonal(
v const& a,
v const& b,
double eps=0.0);
198 template <
class T>
bool parallel(
v const& a,
v const& b,
double eps=0.0);
205 template <
class T>
inline double operator/(
v const& a,
v const& b)
211 template <
class T>
inline v&
normalize(
v& a) {
double l=a.length();
return l?a/=
l:a; }
216 template <
class T>
inline v normalized(
v const& a) {
double l=a.length();
return l?a/
l:a; }
229 #define VGL_VECTOR_3D_INSTANTIATE(T) extern "please include vgl/vgl_vector_3d.hxx first" 231 #endif // vgl_vector_3d_h_ v normalized(v const &a)
Return a normalised version of a.
vgl_vector_3d()
Creates the vector (0,0,0) of zero length.
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).
v orthogonal_vectors(v const &a, double s)
One-parameter family of unit vectors that are orthogonal to a, v(s).
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.
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?.
std::ostream & operator<<(std::ostream &s, vgl_orient_box_3d< Type > const &p)
Write box to stream.
vgl_vector_3d(T vx, T vy, T vz)
Creates the vector (vx,vy,vz).
double length(v const &a)
Return the length of a vector.
vgl_vector_3d< T > orthogonal_vectors(double s) const
One-parameter family of unit vectors that are orthogonal to *this, v(s).
double length() const
Return the length of this vector.
T cross_product(v const &a, v const &b)
cross product of two vectors (area of enclosed parallellogram).
vgl_vector_3d(const T v[3])
Creates the vector (vx,vy,vz).
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.
T sqr_length() const
Return the squared length of this vector.
bool operator==(vgl_vector_3d< T >const &v) const
Comparison.
Direction vector in Euclidean 3D space, templated by type of element.
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.
void set(T vx, T vy, T vz)
Assignment.
double angle(v const &a, v const &b)
smallest angle between two vectors (in radians, between 0 and Pi).
std::istream & read(std::istream &is)
Read from stream, possibly with formatting.
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.
void set(T const v[3])
Set x, y and z.
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_3d< 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.