Go to the documentation of this file. 1 #ifndef GEOLIB_MATH_TYPES_H_
2 #define GEOLIB_MATH_TYPES_H_
32 Vec2T(
const T* values) { memcpy(
m, values, 2 *
sizeof(T)); }
49 return (
x == v.
x &&
y == v.
y);
109 out <<
"[ " << v.
x <<
" " << v.
y <<
" ]";
130 Vec3T(
const T* values) { memcpy(
m, values, 3 *
sizeof(T)); }
148 return (
x == v.x &&
y == v.y &&
z == v.z);
152 return !(*
this == v);
156 T
dot(
const Vec3T& v)
const {
return x * v.x +
y * v.y +
z * v.z; }
212 out <<
"[ " << v.x <<
" " << v.y <<
" " << v.z <<
" ]";
251 return (
xx ==
m.xx &&
xy ==
m.xy &&
252 yx ==
m.yx &&
yy ==
m.yy );
256 return !(*
this ==
m);
307 out <<
"[ " <<
m[0] <<
" " <<
m[1] <<
" ; "
308 <<
m[2] <<
" " <<
m[3] <<
" " <<
" ]";
348 return (
x == q.
x &&
y == q.
y &&
z == q.
z &&
w == q.
w);
352 return !(*
this == q);
386 out <<
"[ " << q.
x <<
" " << q.
y <<
" " << q.
z <<
" " << q.
w <<
" ]";
406 Mat3T(T xx_, T xy_, T xz_, T yx_, T yy_, T yz_, T zx_, T zy_, T zz_)
411 Mat3T(
const T* values) { memcpy(
m, values, 9 *
sizeof(T)); }
432 return (
xx ==
m.xx &&
xy ==
m.xy &&
xz ==
m.xz &&
433 yx ==
m.yx &&
yy ==
m.yy &&
yz ==
m.yz &&
438 return !(*
this ==
m);
453 yx * v.x +
yy * v.y +
yz * v.z,
454 zx * v.x +
zy * v.y +
zz * v.z); }
465 zx * s,
zy * s,
zz * s); }
470 zx / s,
zy / s,
zz / s); }
482 m.yx * s,
m.yy * s,
m.yz * s,
483 m.zx * s,
m.zy * s,
m.zz * s); }
511 m[0] = cj * ch;
m[1] = sj * sc - cs;
m[2] = sj * cc + ss;
512 m[3] = cj * sh;
m[4] = sj * ss + cc,
m[5] = sj * cs - sc;
513 m[6] = -sj;
m[7] = cj * si;
m[8] = cj * ci ;
517 return Mat3T(1, 0, 0, 0, 1, 0, 0, 0, 1);
524 T s = sqrt(trace + 1);
528 q.
m[0]=((
zy -
yz) * s);
529 q.
m[1]=((
xz -
zx) * s);
530 q.
m[2]=((
yx -
xy) * s);
532 int i =
xx <
yy ? (
yy <
zz ? 2 : 1) : (
xx <
zz ? 2 : 0);
536 T s = sqrt(
m[i*4] -
m[j*4] -
m[k*4] + 1);
540 q.
m[3] = (
m[k*3+j] -
m[j*3+k]) * s;
541 q.
m[j] = (
m[j*3+i] +
m[i*3+j]) * s;
542 q.
m[k] = (
m[k*3+i] +
m[i*3+k]) * s;
549 T xs = q.
x * s, ys = q.
y * s, zs = q.
z * s;
550 T wx = q.
w * xs, wy = q.
w * ys, wz = q.
w * zs;
551 T
xx = q.
x * xs,
xy = q.
x * ys,
xz = q.
x * zs;
552 T
yy = q.
y * ys,
yz = q.
y * zs,
zz = q.
z * zs;
554 m[0] = 1 - (
yy +
zz);
m[1] =
xy - wz;
m[2] =
xz + wy;
555 m[3] =
xy + wz;
m[4] = 1 - (
xx +
zz);
m[5] =
yz - wx;
556 m[6] =
xz - wy;
m[7] =
yz + wx;
m[8] = 1 - (
xx +
yy);
569 out <<
"[ " <<
m[0] <<
" " <<
m[1] <<
" " <<
m[2] <<
" ; "
570 <<
m[3] <<
" " <<
m[4] <<
" " <<
m[5] <<
" ; "
571 <<
m[6] <<
" " <<
m[7] <<
" " <<
m[8] <<
" ]";
584 xx /= len_x;
xy /= len_y;
xz /= len_z;
yx /= len_x;
yy /= len_y;
yz /= len_z;
zx /= len_x;
zy /= len_y;
zz /= len_z;
591 return Mat3T<T>(x.normalized(), y.normalized(), z.normalized());
660 return atan2(
R.yx ,
R.xx);
674 out <<
"t: " <<
t.t <<
"\tR: " <<
t.R;
693 Transform3T(T x, T y, T z, T roll = 0, T pitch = 0, T yaw = 0) :
t(x, y, z) {
710 return (
R == tr.
R &&
t == tr.
t);
714 return !(*
this == tr);
752 void setRPY(
double roll,
double pitch,
double yaw) {
753 R.setRPY(roll, pitch, yaw);
756 void getRPY(
double& roll,
double& pitch,
double& yaw)
const {
757 double epsilon = 1e-12;
758 pitch = atan2(-
R.zx, sqrt(
R.zy*
R.zy +
R.zz*
R.zz));
762 yaw = atan2(-
R.xy,
R.yy);
767 roll = atan2(
R.zy,
R.zz);
768 yaw = atan2(
R.yx,
R.xx);
773 double roll, pitch, yaw;
789 out <<
"t: " <<
t.t <<
"\tR: " <<
t.R;
T length2() const
Returns the squared length of the vector.
T & operator()(int i, int j)
friend Vec2T operator*(T s, const Vec2T &v)
multiplies vector with a scalar
void normalize()
Normalizes the vector.
QuaternionT(T x_, T y_, T z_, T w_)
Mat2T< T > projectTo2d() const
Drops the rotation of the 3rd coordinate.
void setRotation(const QuaternionT< T > &q)
T & operator()(int i, int j)
friend Vec2T operator-(const Vec2T &v)
Vec2T & operator+=(const Vec2T &v)
friend std::ostream & operator<<(std::ostream &out, const QuaternionT &q)
const T & operator()(int i, int j) const
T & operator[](const uint i)
void getRotation(QuaternionT< T > &q) const
bool operator!=(const Mat3T &m) const
Vec3T & operator+=(const Vec3T &v)
friend Vec3T operator-(const Vec3T &v)
bool operator==(const Vec2T &v) const
Mat3T(T xx_, T xy_, T xz_, T yx_, T yy_, T yz_, T zx_, T zy_, T zz_)
bool operator!=(const Vec3T &v) const
void normalize()
Normalizes the vector.
T dot(const Vec2T &v) const
returns dot product
bool operator!=(const Vec2T &v) const
Transform2T< int > Transform2i
bool operator==(const QuaternionT &q) const
Mat3T operator-(const Mat3T &m) const
returns this minus m
Vec3T operator-(const Vec3T &v) const
returns this minus v
Mat2T(T xx_, T xy_, T yx_, T yy_)
Transform2T< unsigned int > Transform2u
bool operator==(const Vec3T &v) const
Vec2T & operator/=(const Vec2T &v)
friend Vec3T operator*(T s, const Vec3T &v)
multiplies vector with a scalar
Vec3T operator+(const Vec3T &v) const
returns addition with v
const T & operator[](const uint i) const
Vec3T operator*(T s) const
multiplies vector with a scalar
T & operator[](const uint i)
Vec3T & operator/=(const Vec3T &v)
Mat2T operator-(const Mat2T &m) const
returns this minus m
Vec2T & operator*=(const Vec2T &v)
Vec3T< T > getRow(int i) const
Mat3T(Vec3T< T > x, Vec3T< T > y, Vec3T< T > z)
const T & operator[](const uint i) const
Vec3T< T > projectTo3d() const
Expand vector with a zero 3rd coordinate.
friend std::ostream & operator<<(std::ostream &out, const Mat2T &m)
Vec2T operator+(const Vec2T &v) const
returns addition of this and v
const T & operator[](const uint i) const
Mat2T operator+(const Mat2T &m) const
returns addition with v
Mat3T operator*(T s) const
multiplies vector with a scalar
Mat2T operator*(const Mat2T &m) const
return this multiplied by m
friend std::ostream & operator<<(std::ostream &out, const Vec3T &v)
QuaternionT operator-(const QuaternionT &q) const
returns this minus q
T cross(const Vec2T &v) const
returns cross product
T & operator[](const uint i)
const T & operator[](const uint i) const
Vec3T< T > operator*(const Vec3T< T > &v) const
void normalize()
Normalizes the quaternion.
Mat2T operator/(T s) const
divides matrix by scalar
Transform2T< float > Transform2f
T & operator[](const uint i)
Transform2T< real > Transform2
T length() const
Returns the length of the vector.
T length2() const
Returns the squared length of the vector.
Vec3T< unsigned int > Vec3u
Vec3T cross(const Vec3T &v) const
returns cross product
const T & operator()(int i, int j) const
QuaternionT & operator=(const QuaternionT &q)
Vec2T operator-(const Vec2T &v) const
returns this minus v
Transform3T< real > Transform3
T & operator[](const uint i)
Vec3T & operator=(const Vec3T &v)
Mat2T operator*(T s) const
multiplies vector with a scalar
QuaternionT normalized() const
Returns the normalized version of the vector.
Mat3T operator/(T s) const
divides matrix by scalar
Mat3T< T > projectTo3d() const
Expand rotation matrix into 3D, with zero rotation around the 3rd axis.
Vec2T operator*(T s) const
multiplies vector with a scalar
Vec2T & operator=(const Vec2T &v)
bool operator==(const Mat2T &m) const
T length2() const
Returns the squared length of the vector.
Vec2T< unsigned int > Vec2u
Transform3T< int > Transform3i
Vec2T operator/(T s) const
divides vector by scalar
Vec3T operator/(T s) const
divides vector by scalar
bool operator!=(const Mat2T &m) const
Transform3T< unsigned int > Transform3u
Transform3T< float > Transform3f
friend std::ostream & operator<<(std::ostream &out, const Mat3T &m)
Mat3T< unsigned int > Mat3u
Vec3T normalized() const
Returns the normalized version of the vector.
Transform3T< double > Transform3d
Vec2T< T > operator*(const Vec2T< T > &v) const
friend Mat2T operator*(T s, const Mat2T &m)
multiplies vector with a scalar
const T & operator[](const uint i) const
Transform2T< double > Transform2d
Vec2T< T > projectTo2d() const
Drop the displacement of the 3rd coordinate.
QuaternionT operator+(const QuaternionT &q) const
returns addition with q
Vec3T< T > getColumn(int i) const
T dot(const Vec3T &v) const
returns dot product
T length() const
Returns the length of the vector.
Vec3T & operator*=(const Vec3T &v)
friend Mat3T operator*(T s, const Mat3T &m)
multiplies vector with a scalar
Mat2T< unsigned int > Mat2u
Mat2T & operator=(const Mat2T &v)
Vec2T & operator-=(const Vec2T &v)
T dot(const QuaternionT &q) const
returns dot product
friend std::ostream & operator<<(std::ostream &out, const Vec2T &v)
Mat3T & operator=(const Mat3T &m)
void setRPY(T roll, T pitch, T yaw)
bool operator!=(const QuaternionT &q) const
Mat3T operator*(const Mat3T &m) const
friend QuaternionT operator*(T s, const QuaternionT &q)
Mat3T operator+(const Mat3T &m) const
returns addition with v
T length() const
Returns the length of the vector.
Vec3T & operator-=(const Vec3T &v)
QuaternionT operator*(T s) const
Vec2T normalized() const
Returns the normalized version of the vector.
bool operator==(const Mat3T &m) const