4 #include <QGLViewer/vec.h>
8 namespace margait_contrib
13 extern double operator*(
const Vec3f& v,
const Vec3f& w);
14 extern Vec3f operator*(
const double scalar,
const Vec3f& v);
15 extern Vec3f operator*(
const Vec3f& v,
const double scalar);
16 extern Vec3f operator/(
const Vec3f& v,
const double scalar);
25 Vec3f(
const double xx,
const double yy,
const double zz){x=xx; y=yy; z=zz;}
26 Vec3f(
const qglviewer::Vec& other){x=other.x; y=other.y; z=other.z;}
27 Vec3f & operator=(
const qglviewer::Vec& other) {x=other.x; y=other.y; z=other.z;
return *
this;}
29 inline Vec3f operator+(
const Vec3f& v)
const {
return Vec3f(x+v.x, y+v.y, z+v.z);}
30 inline Vec3f operator-()
const {
return Vec3f(-x, -y, -z);}
31 inline Vec3f operator-(
const Vec3f& v)
const {
return Vec3f(x-v.x, y-v.y, z-v.z);}
32 inline Vec3f operator%(
const Vec3f& v)
const {
return Vec3f(x*v.x, y*v.y, z*v.z);}
33 inline Vec3f operator%=(
const Vec3f& v)
const {
return Vec3f(x*v.x, y*v.y, z*v.z);}
34 inline bool operator==(
const Vec3f& v)
const {
return (x==v.x) && (y==v.y) && (z==v.z);}
35 inline bool operator!=(
const Vec3f& v)
const {
return (x!=v.x) || (y!=v.y) || (z!=v.z);}
36 inline Vec3f operator/(
const Vec3f& v)
const {
return Vec3f(x/v.x, y/v.y, z/v.z);}
38 inline Vec3f& operator=(
const Vec3f& v){ x=v.x; y=v.y; z=v.z;
return *
this;}
39 inline Vec3f& operator*=(
const double scalar){ x*=scalar;y*=scalar; z*=scalar;
return *
this;}
40 inline Vec3f& operator/=(
const double scalar){ x/=scalar;y/=scalar; z/=scalar;
return *
this;}
41 inline Vec3f& operator+=(
const Vec3f& v){ x+=v.x; y+=v.y; z+=v.z;
return *
this;}
42 inline Vec3f& operator-=(
const Vec3f& v){ x-=v.x; y-=v.y; z-= v.z;
return *
this;}
44 operator const double*()
const {
return &x;}
47 inline double norm()
const {
return sqrt(x*x+y*y+z*z);}
50 inline double norm2()
const {
return x*x+y*y+z*z;}
53 inline double normp(
double p)
const {
return pow( pow(fabs(x), p) + pow(fabs(y), p) + pow(fabs(z), p), 1/p); }
55 inline Vec3f& normalize()
61 x /= n; y /= n; z/= n;
66 x = 0.f; y = 0.f; z= 0.f;
71 inline Vec3f getNormalized()
const
75 return Vec3f(x / n, y / n, z/n);
80 inline void normiereAuf(
const double length)
85 inline Vec3f normiertAuf(
const double length)
88 res.normiereAuf(length);
92 inline double dist(
const Vec3f& v)
const {
return (*
this-v).norm();}
94 inline double dist2(
const Vec3f& v)
const {
return (*
this-v).norm2();}
97 inline void rotate(
double angle)
101 x = x_ * cos(angle) + y_ * -sin(angle);
102 y = x_ * sin(angle) + y_ * cos(angle);
105 inline bool operator<(
const Vec3f& v )
const
107 return norm2() < v.norm2();
110 inline Vec3f absComponents()
const
112 return Vec3f(fabsf(x), fabsf(y), fabsf(z));
115 double maxComponent()
117 if (fabsf(x)>fabsf(y))
118 if(fabsf(x)>fabsf(z))
123 if(fabsf(y)>fabsf(z))
129 double minComponent()
131 if (fabsf(x)>fabsf(y))
132 if(fabsf(y)>fabsf(z))
137 if(fabsf(x)>fabsf(z))
144 QDebug operator<<(QDebug dbg,
const Vec3f &v);