| 1 |
< |
/* |
| 1 |
> |
/* |
| 2 |
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
| 3 |
|
* |
| 4 |
|
* The University of Notre Dame grants you ("Licensee") a |
| 45 |
|
* @date 10/11/2004 |
| 46 |
|
* @version 1.0 |
| 47 |
|
*/ |
| 48 |
< |
#ifndef MATH_SQUAREMATRIX3_HPP |
| 48 |
> |
#ifndef MATH_SQUAREMATRIX3_HPP |
| 49 |
|
#define MATH_SQUAREMATRIX3_HPP |
| 50 |
|
|
| 51 |
|
#include "Quaternion.hpp" |
| 52 |
|
#include "SquareMatrix.hpp" |
| 53 |
|
#include "Vector3.hpp" |
| 54 |
< |
|
| 54 |
> |
#include "utils/NumericConstant.hpp" |
| 55 |
|
namespace oopse { |
| 56 |
|
|
| 57 |
< |
template<typename Real> |
| 58 |
< |
class SquareMatrix3 : public SquareMatrix<Real, 3> { |
| 59 |
< |
public: |
| 57 |
> |
template<typename Real> |
| 58 |
> |
class SquareMatrix3 : public SquareMatrix<Real, 3> { |
| 59 |
> |
public: |
| 60 |
|
|
| 61 |
< |
typedef Real ElemType; |
| 62 |
< |
typedef Real* ElemPoinerType; |
| 61 |
> |
typedef Real ElemType; |
| 62 |
> |
typedef Real* ElemPoinerType; |
| 63 |
|
|
| 64 |
< |
/** default constructor */ |
| 65 |
< |
SquareMatrix3() : SquareMatrix<Real, 3>() { |
| 66 |
< |
} |
| 64 |
> |
/** default constructor */ |
| 65 |
> |
SquareMatrix3() : SquareMatrix<Real, 3>() { |
| 66 |
> |
} |
| 67 |
|
|
| 68 |
< |
/** Constructs and initializes every element of this matrix to a scalar */ |
| 69 |
< |
SquareMatrix3(Real s) : SquareMatrix<Real,3>(s){ |
| 70 |
< |
} |
| 68 |
> |
/** Constructs and initializes every element of this matrix to a scalar */ |
| 69 |
> |
SquareMatrix3(Real s) : SquareMatrix<Real,3>(s){ |
| 70 |
> |
} |
| 71 |
|
|
| 72 |
< |
/** Constructs and initializes from an array */ |
| 73 |
< |
SquareMatrix3(Real* array) : SquareMatrix<Real,3>(array){ |
| 74 |
< |
} |
| 72 |
> |
/** Constructs and initializes from an array */ |
| 73 |
> |
SquareMatrix3(Real* array) : SquareMatrix<Real,3>(array){ |
| 74 |
> |
} |
| 75 |
|
|
| 76 |
|
|
| 77 |
< |
/** copy constructor */ |
| 78 |
< |
SquareMatrix3(const SquareMatrix<Real, 3>& m) : SquareMatrix<Real, 3>(m) { |
| 79 |
< |
} |
| 77 |
> |
/** copy constructor */ |
| 78 |
> |
SquareMatrix3(const SquareMatrix<Real, 3>& m) : SquareMatrix<Real, 3>(m) { |
| 79 |
> |
} |
| 80 |
|
|
| 81 |
< |
SquareMatrix3( const Vector3<Real>& eulerAngles) { |
| 82 |
< |
setupRotMat(eulerAngles); |
| 83 |
< |
} |
| 81 |
> |
SquareMatrix3( const Vector3<Real>& eulerAngles) { |
| 82 |
> |
setupRotMat(eulerAngles); |
| 83 |
> |
} |
| 84 |
|
|
| 85 |
< |
SquareMatrix3(Real phi, Real theta, Real psi) { |
| 86 |
< |
setupRotMat(phi, theta, psi); |
| 87 |
< |
} |
| 85 |
> |
SquareMatrix3(Real phi, Real theta, Real psi) { |
| 86 |
> |
setupRotMat(phi, theta, psi); |
| 87 |
> |
} |
| 88 |
|
|
| 89 |
< |
SquareMatrix3(const Quaternion<Real>& q) { |
| 90 |
< |
setupRotMat(q); |
| 89 |
> |
SquareMatrix3(const Quaternion<Real>& q) { |
| 90 |
> |
setupRotMat(q); |
| 91 |
|
|
| 92 |
< |
} |
| 92 |
> |
} |
| 93 |
|
|
| 94 |
< |
SquareMatrix3(Real w, Real x, Real y, Real z) { |
| 95 |
< |
setupRotMat(w, x, y, z); |
| 96 |
< |
} |
| 94 |
> |
SquareMatrix3(Real w, Real x, Real y, Real z) { |
| 95 |
> |
setupRotMat(w, x, y, z); |
| 96 |
> |
} |
| 97 |
|
|
| 98 |
< |
/** copy assignment operator */ |
| 99 |
< |
SquareMatrix3<Real>& operator =(const SquareMatrix<Real, 3>& m) { |
| 100 |
< |
if (this == &m) |
| 101 |
< |
return *this; |
| 102 |
< |
SquareMatrix<Real, 3>::operator=(m); |
| 103 |
< |
return *this; |
| 104 |
< |
} |
| 98 |
> |
/** copy assignment operator */ |
| 99 |
> |
SquareMatrix3<Real>& operator =(const SquareMatrix<Real, 3>& m) { |
| 100 |
> |
if (this == &m) |
| 101 |
> |
return *this; |
| 102 |
> |
SquareMatrix<Real, 3>::operator=(m); |
| 103 |
> |
return *this; |
| 104 |
> |
} |
| 105 |
|
|
| 106 |
|
|
| 107 |
< |
SquareMatrix3<Real>& operator =(const Quaternion<Real>& q) { |
| 108 |
< |
this->setupRotMat(q); |
| 109 |
< |
return *this; |
| 110 |
< |
} |
| 107 |
> |
SquareMatrix3<Real>& operator =(const Quaternion<Real>& q) { |
| 108 |
> |
this->setupRotMat(q); |
| 109 |
> |
return *this; |
| 110 |
> |
} |
| 111 |
|
|
| 112 |
< |
/** |
| 113 |
< |
* Sets this matrix to a rotation matrix by three euler angles |
| 114 |
< |
* @ param euler |
| 115 |
< |
*/ |
| 116 |
< |
void setupRotMat(const Vector3<Real>& eulerAngles) { |
| 117 |
< |
setupRotMat(eulerAngles[0], eulerAngles[1], eulerAngles[2]); |
| 118 |
< |
} |
| 112 |
> |
/** |
| 113 |
> |
* Sets this matrix to a rotation matrix by three euler angles |
| 114 |
> |
* @ param euler |
| 115 |
> |
*/ |
| 116 |
> |
void setupRotMat(const Vector3<Real>& eulerAngles) { |
| 117 |
> |
setupRotMat(eulerAngles[0], eulerAngles[1], eulerAngles[2]); |
| 118 |
> |
} |
| 119 |
|
|
| 120 |
< |
/** |
| 121 |
< |
* Sets this matrix to a rotation matrix by three euler angles |
| 122 |
< |
* @param phi |
| 123 |
< |
* @param theta |
| 124 |
< |
* @psi theta |
| 125 |
< |
*/ |
| 126 |
< |
void setupRotMat(Real phi, Real theta, Real psi) { |
| 127 |
< |
Real sphi, stheta, spsi; |
| 128 |
< |
Real cphi, ctheta, cpsi; |
| 120 |
> |
/** |
| 121 |
> |
* Sets this matrix to a rotation matrix by three euler angles |
| 122 |
> |
* @param phi |
| 123 |
> |
* @param theta |
| 124 |
> |
* @psi theta |
| 125 |
> |
*/ |
| 126 |
> |
void setupRotMat(Real phi, Real theta, Real psi) { |
| 127 |
> |
Real sphi, stheta, spsi; |
| 128 |
> |
Real cphi, ctheta, cpsi; |
| 129 |
|
|
| 130 |
< |
sphi = sin(phi); |
| 131 |
< |
stheta = sin(theta); |
| 132 |
< |
spsi = sin(psi); |
| 133 |
< |
cphi = cos(phi); |
| 134 |
< |
ctheta = cos(theta); |
| 135 |
< |
cpsi = cos(psi); |
| 130 |
> |
sphi = sin(phi); |
| 131 |
> |
stheta = sin(theta); |
| 132 |
> |
spsi = sin(psi); |
| 133 |
> |
cphi = cos(phi); |
| 134 |
> |
ctheta = cos(theta); |
| 135 |
> |
cpsi = cos(psi); |
| 136 |
|
|
| 137 |
< |
data_[0][0] = cpsi * cphi - ctheta * sphi * spsi; |
| 138 |
< |
data_[0][1] = cpsi * sphi + ctheta * cphi * spsi; |
| 139 |
< |
data_[0][2] = spsi * stheta; |
| 137 |
> |
this->data_[0][0] = cpsi * cphi - ctheta * sphi * spsi; |
| 138 |
> |
this->data_[0][1] = cpsi * sphi + ctheta * cphi * spsi; |
| 139 |
> |
this->data_[0][2] = spsi * stheta; |
| 140 |
|
|
| 141 |
< |
data_[1][0] = -spsi * ctheta - ctheta * sphi * cpsi; |
| 142 |
< |
data_[1][1] = -spsi * stheta + ctheta * cphi * cpsi; |
| 143 |
< |
data_[1][2] = cpsi * stheta; |
| 141 |
> |
this->data_[1][0] = -spsi * ctheta - ctheta * sphi * cpsi; |
| 142 |
> |
this->data_[1][1] = -spsi * stheta + ctheta * cphi * cpsi; |
| 143 |
> |
this->data_[1][2] = cpsi * stheta; |
| 144 |
|
|
| 145 |
< |
data_[2][0] = stheta * sphi; |
| 146 |
< |
data_[2][1] = -stheta * cphi; |
| 147 |
< |
data_[2][2] = ctheta; |
| 148 |
< |
} |
| 145 |
> |
this->data_[2][0] = stheta * sphi; |
| 146 |
> |
this->data_[2][1] = -stheta * cphi; |
| 147 |
> |
this->data_[2][2] = ctheta; |
| 148 |
> |
} |
| 149 |
|
|
| 150 |
|
|
| 151 |
< |
/** |
| 152 |
< |
* Sets this matrix to a rotation matrix by quaternion |
| 153 |
< |
* @param quat |
| 154 |
< |
*/ |
| 155 |
< |
void setupRotMat(const Quaternion<Real>& quat) { |
| 156 |
< |
setupRotMat(quat.w(), quat.x(), quat.y(), quat.z()); |
| 157 |
< |
} |
| 151 |
> |
/** |
| 152 |
> |
* Sets this matrix to a rotation matrix by quaternion |
| 153 |
> |
* @param quat |
| 154 |
> |
*/ |
| 155 |
> |
void setupRotMat(const Quaternion<Real>& quat) { |
| 156 |
> |
setupRotMat(quat.w(), quat.x(), quat.y(), quat.z()); |
| 157 |
> |
} |
| 158 |
|
|
| 159 |
< |
/** |
| 160 |
< |
* Sets this matrix to a rotation matrix by quaternion |
| 161 |
< |
* @param w the first element |
| 162 |
< |
* @param x the second element |
| 163 |
< |
* @param y the third element |
| 164 |
< |
* @param z the fourth element |
| 165 |
< |
*/ |
| 166 |
< |
void setupRotMat(Real w, Real x, Real y, Real z) { |
| 167 |
< |
Quaternion<Real> q(w, x, y, z); |
| 168 |
< |
*this = q.toRotationMatrix3(); |
| 169 |
< |
} |
| 159 |
> |
/** |
| 160 |
> |
* Sets this matrix to a rotation matrix by quaternion |
| 161 |
> |
* @param w the first element |
| 162 |
> |
* @param x the second element |
| 163 |
> |
* @param y the third element |
| 164 |
> |
* @param z the fourth element |
| 165 |
> |
*/ |
| 166 |
> |
void setupRotMat(Real w, Real x, Real y, Real z) { |
| 167 |
> |
Quaternion<Real> q(w, x, y, z); |
| 168 |
> |
*this = q.toRotationMatrix3(); |
| 169 |
> |
} |
| 170 |
|
|
| 171 |
< |
/** |
| 172 |
< |
* Returns the quaternion from this rotation matrix |
| 173 |
< |
* @return the quaternion from this rotation matrix |
| 174 |
< |
* @exception invalid rotation matrix |
| 175 |
< |
*/ |
| 176 |
< |
Quaternion<Real> toQuaternion() { |
| 177 |
< |
Quaternion<Real> q; |
| 178 |
< |
Real t, s; |
| 179 |
< |
Real ad1, ad2, ad3; |
| 180 |
< |
t = data_[0][0] + data_[1][1] + data_[2][2] + 1.0; |
| 171 |
> |
void setupSkewMat(Vector3<Real> v) { |
| 172 |
> |
setupSkewMat(v[0], v[1], v[2]); |
| 173 |
> |
} |
| 174 |
|
|
| 175 |
< |
if( t > 0.0 ){ |
| 175 |
> |
void setupSkewMat(Real v1, Real v2, Real v3) { |
| 176 |
> |
this->data_[0][0] = 0; |
| 177 |
> |
this->data_[0][1] = -v3; |
| 178 |
> |
this->data_[0][2] = v2; |
| 179 |
> |
this->data_[1][0] = v3; |
| 180 |
> |
this->data_[1][1] = 0; |
| 181 |
> |
this->data_[1][2] = -v1; |
| 182 |
> |
this->data_[2][0] = -v2; |
| 183 |
> |
this->data_[2][1] = v1; |
| 184 |
> |
this->data_[2][2] = 0; |
| 185 |
> |
|
| 186 |
> |
|
| 187 |
> |
} |
| 188 |
|
|
| 184 |
– |
s = 0.5 / sqrt( t ); |
| 185 |
– |
q[0] = 0.25 / s; |
| 186 |
– |
q[1] = (data_[1][2] - data_[2][1]) * s; |
| 187 |
– |
q[2] = (data_[2][0] - data_[0][2]) * s; |
| 188 |
– |
q[3] = (data_[0][1] - data_[1][0]) * s; |
| 189 |
– |
} else { |
| 189 |
|
|
| 191 |
– |
ad1 = fabs( data_[0][0] ); |
| 192 |
– |
ad2 = fabs( data_[1][1] ); |
| 193 |
– |
ad3 = fabs( data_[2][2] ); |
| 190 |
|
|
| 191 |
< |
if( ad1 >= ad2 && ad1 >= ad3 ){ |
| 191 |
> |
/** |
| 192 |
> |
* Returns the quaternion from this rotation matrix |
| 193 |
> |
* @return the quaternion from this rotation matrix |
| 194 |
> |
* @exception invalid rotation matrix |
| 195 |
> |
*/ |
| 196 |
> |
Quaternion<Real> toQuaternion() { |
| 197 |
> |
Quaternion<Real> q; |
| 198 |
> |
Real t, s; |
| 199 |
> |
Real ad1, ad2, ad3; |
| 200 |
> |
t = this->data_[0][0] + this->data_[1][1] + this->data_[2][2] + 1.0; |
| 201 |
|
|
| 202 |
< |
s = 2.0 * sqrt( 1.0 + data_[0][0] - data_[1][1] - data_[2][2] ); |
| 198 |
< |
q[0] = (data_[1][2] + data_[2][1]) / s; |
| 199 |
< |
q[1] = 0.5 / s; |
| 200 |
< |
q[2] = (data_[0][1] + data_[1][0]) / s; |
| 201 |
< |
q[3] = (data_[0][2] + data_[2][0]) / s; |
| 202 |
< |
} else if ( ad2 >= ad1 && ad2 >= ad3 ) { |
| 203 |
< |
s = sqrt( 1.0 + data_[1][1] - data_[0][0] - data_[2][2] ) * 2.0; |
| 204 |
< |
q[0] = (data_[0][2] + data_[2][0]) / s; |
| 205 |
< |
q[1] = (data_[0][1] + data_[1][0]) / s; |
| 206 |
< |
q[2] = 0.5 / s; |
| 207 |
< |
q[3] = (data_[1][2] + data_[2][1]) / s; |
| 208 |
< |
} else { |
| 202 |
> |
if( t > NumericConstant::epsilon ){ |
| 203 |
|
|
| 204 |
< |
s = sqrt( 1.0 + data_[2][2] - data_[0][0] - data_[1][1] ) * 2.0; |
| 205 |
< |
q[0] = (data_[0][1] + data_[1][0]) / s; |
| 206 |
< |
q[1] = (data_[0][2] + data_[2][0]) / s; |
| 207 |
< |
q[2] = (data_[1][2] + data_[2][1]) / s; |
| 208 |
< |
q[3] = 0.5 / s; |
| 209 |
< |
} |
| 216 |
< |
} |
| 204 |
> |
s = 0.5 / sqrt( t ); |
| 205 |
> |
q[0] = 0.25 / s; |
| 206 |
> |
q[1] = (this->data_[1][2] - this->data_[2][1]) * s; |
| 207 |
> |
q[2] = (this->data_[2][0] - this->data_[0][2]) * s; |
| 208 |
> |
q[3] = (this->data_[0][1] - this->data_[1][0]) * s; |
| 209 |
> |
} else { |
| 210 |
|
|
| 211 |
< |
return q; |
| 211 |
> |
ad1 = this->data_[0][0]; |
| 212 |
> |
ad2 = this->data_[1][1]; |
| 213 |
> |
ad3 = this->data_[2][2]; |
| 214 |
> |
|
| 215 |
> |
if( ad1 >= ad2 && ad1 >= ad3 ){ |
| 216 |
> |
|
| 217 |
> |
s = 0.5 / sqrt( 1.0 + this->data_[0][0] - this->data_[1][1] - this->data_[2][2] ); |
| 218 |
> |
q[0] = (this->data_[1][2] - this->data_[2][1]) * s; |
| 219 |
> |
q[1] = 0.25 / s; |
| 220 |
> |
q[2] = (this->data_[0][1] + this->data_[1][0]) * s; |
| 221 |
> |
q[3] = (this->data_[0][2] + this->data_[2][0]) * s; |
| 222 |
> |
} else if ( ad2 >= ad1 && ad2 >= ad3 ) { |
| 223 |
> |
s = 0.5 / sqrt( 1.0 + this->data_[1][1] - this->data_[0][0] - this->data_[2][2] ); |
| 224 |
> |
q[0] = (this->data_[2][0] - this->data_[0][2] ) * s; |
| 225 |
> |
q[1] = (this->data_[0][1] + this->data_[1][0]) * s; |
| 226 |
> |
q[2] = 0.25 / s; |
| 227 |
> |
q[3] = (this->data_[1][2] + this->data_[2][1]) * s; |
| 228 |
> |
} else { |
| 229 |
> |
|
| 230 |
> |
s = 0.5 / sqrt( 1.0 + this->data_[2][2] - this->data_[0][0] - this->data_[1][1] ); |
| 231 |
> |
q[0] = (this->data_[0][1] - this->data_[1][0]) * s; |
| 232 |
> |
q[1] = (this->data_[0][2] + this->data_[2][0]) * s; |
| 233 |
> |
q[2] = (this->data_[1][2] + this->data_[2][1]) * s; |
| 234 |
> |
q[3] = 0.25 / s; |
| 235 |
> |
} |
| 236 |
> |
} |
| 237 |
> |
|
| 238 |
> |
return q; |
| 239 |
|
|
| 240 |
< |
} |
| 240 |
> |
} |
| 241 |
|
|
| 242 |
< |
/** |
| 243 |
< |
* Returns the euler angles from this rotation matrix |
| 244 |
< |
* @return the euler angles in a vector |
| 245 |
< |
* @exception invalid rotation matrix |
| 246 |
< |
* We use so-called "x-convention", which is the most common definition. |
| 247 |
< |
* In this convention, the rotation given by Euler angles (phi, theta, psi), where the first |
| 248 |
< |
* rotation is by an angle phi about the z-axis, the second is by an angle |
| 249 |
< |
* theta (0 <= theta <= 180)about the x-axis, and thethird is by an angle psi about the |
| 250 |
< |
* z-axis (again). |
| 251 |
< |
*/ |
| 252 |
< |
Vector3<Real> toEulerAngles() { |
| 253 |
< |
Vector3<Real> myEuler; |
| 254 |
< |
Real phi; |
| 255 |
< |
Real theta; |
| 256 |
< |
Real psi; |
| 257 |
< |
Real ctheta; |
| 258 |
< |
Real stheta; |
| 242 |
> |
/** |
| 243 |
> |
* Returns the euler angles from this rotation matrix |
| 244 |
> |
* @return the euler angles in a vector |
| 245 |
> |
* @exception invalid rotation matrix |
| 246 |
> |
* We use so-called "x-convention", which is the most common definition. |
| 247 |
> |
* In this convention, the rotation given by Euler angles (phi, theta, psi), where the first |
| 248 |
> |
* rotation is by an angle phi about the z-axis, the second is by an angle |
| 249 |
> |
* theta (0 <= theta <= 180)about the x-axis, and thethird is by an angle psi about the |
| 250 |
> |
* z-axis (again). |
| 251 |
> |
*/ |
| 252 |
> |
Vector3<Real> toEulerAngles() { |
| 253 |
> |
Vector3<Real> myEuler; |
| 254 |
> |
Real phi; |
| 255 |
> |
Real theta; |
| 256 |
> |
Real psi; |
| 257 |
> |
Real ctheta; |
| 258 |
> |
Real stheta; |
| 259 |
|
|
| 260 |
< |
// set the tolerance for Euler angles and rotation elements |
| 260 |
> |
// set the tolerance for Euler angles and rotation elements |
| 261 |
|
|
| 262 |
< |
theta = acos(std::min(1.0, std::max(-1.0,data_[2][2]))); |
| 263 |
< |
ctheta = data_[2][2]; |
| 264 |
< |
stheta = sqrt(1.0 - ctheta * ctheta); |
| 262 |
> |
theta = acos(std::min(1.0, std::max(-1.0,this->data_[2][2]))); |
| 263 |
> |
ctheta = this->data_[2][2]; |
| 264 |
> |
stheta = sqrt(1.0 - ctheta * ctheta); |
| 265 |
|
|
| 266 |
< |
// when sin(theta) is close to 0, we need to consider singularity |
| 267 |
< |
// In this case, we can assign an arbitary value to phi (or psi), and then determine |
| 268 |
< |
// the psi (or phi) or vice-versa. We'll assume that phi always gets the rotation, and psi is 0 |
| 269 |
< |
// in cases of singularity. |
| 270 |
< |
// we use atan2 instead of atan, since atan2 will give us -Pi to Pi. |
| 271 |
< |
// Since 0 <= theta <= 180, sin(theta) will be always non-negative. Therefore, it never |
| 272 |
< |
// change the sign of both of the parameters passed to atan2. |
| 266 |
> |
// when sin(theta) is close to 0, we need to consider singularity |
| 267 |
> |
// In this case, we can assign an arbitary value to phi (or psi), and then determine |
| 268 |
> |
// the psi (or phi) or vice-versa. We'll assume that phi always gets the rotation, and psi is 0 |
| 269 |
> |
// in cases of singularity. |
| 270 |
> |
// we use atan2 instead of atan, since atan2 will give us -Pi to Pi. |
| 271 |
> |
// Since 0 <= theta <= 180, sin(theta) will be always non-negative. Therefore, it never |
| 272 |
> |
// change the sign of both of the parameters passed to atan2. |
| 273 |
|
|
| 274 |
< |
if (fabs(stheta) <= oopse::epsilon){ |
| 275 |
< |
psi = 0.0; |
| 276 |
< |
phi = atan2(-data_[1][0], data_[0][0]); |
| 277 |
< |
} |
| 278 |
< |
// we only have one unique solution |
| 279 |
< |
else{ |
| 280 |
< |
phi = atan2(data_[2][0], -data_[2][1]); |
| 281 |
< |
psi = atan2(data_[0][2], data_[1][2]); |
| 282 |
< |
} |
| 274 |
> |
if (fabs(stheta) <= oopse::epsilon){ |
| 275 |
> |
psi = 0.0; |
| 276 |
> |
phi = atan2(-this->data_[1][0], this->data_[0][0]); |
| 277 |
> |
} |
| 278 |
> |
// we only have one unique solution |
| 279 |
> |
else{ |
| 280 |
> |
phi = atan2(this->data_[2][0], -this->data_[2][1]); |
| 281 |
> |
psi = atan2(this->data_[0][2], this->data_[1][2]); |
| 282 |
> |
} |
| 283 |
|
|
| 284 |
< |
//wrap phi and psi, make sure they are in the range from 0 to 2*Pi |
| 285 |
< |
if (phi < 0) |
| 286 |
< |
phi += M_PI; |
| 284 |
> |
//wrap phi and psi, make sure they are in the range from 0 to 2*Pi |
| 285 |
> |
if (phi < 0) |
| 286 |
> |
phi += M_PI; |
| 287 |
|
|
| 288 |
< |
if (psi < 0) |
| 289 |
< |
psi += M_PI; |
| 288 |
> |
if (psi < 0) |
| 289 |
> |
psi += M_PI; |
| 290 |
|
|
| 291 |
< |
myEuler[0] = phi; |
| 292 |
< |
myEuler[1] = theta; |
| 293 |
< |
myEuler[2] = psi; |
| 291 |
> |
myEuler[0] = phi; |
| 292 |
> |
myEuler[1] = theta; |
| 293 |
> |
myEuler[2] = psi; |
| 294 |
|
|
| 295 |
< |
return myEuler; |
| 296 |
< |
} |
| 295 |
> |
return myEuler; |
| 296 |
> |
} |
| 297 |
|
|
| 298 |
< |
/** Returns the determinant of this matrix. */ |
| 299 |
< |
Real determinant() const { |
| 300 |
< |
Real x,y,z; |
| 298 |
> |
/** Returns the determinant of this matrix. */ |
| 299 |
> |
Real determinant() const { |
| 300 |
> |
Real x,y,z; |
| 301 |
|
|
| 302 |
< |
x = data_[0][0] * (data_[1][1] * data_[2][2] - data_[1][2] * data_[2][1]); |
| 303 |
< |
y = data_[0][1] * (data_[1][2] * data_[2][0] - data_[1][0] * data_[2][2]); |
| 304 |
< |
z = data_[0][2] * (data_[1][0] * data_[2][1] - data_[1][1] * data_[2][0]); |
| 302 |
> |
x = this->data_[0][0] * (this->data_[1][1] * this->data_[2][2] - this->data_[1][2] * this->data_[2][1]); |
| 303 |
> |
y = this->data_[0][1] * (this->data_[1][2] * this->data_[2][0] - this->data_[1][0] * this->data_[2][2]); |
| 304 |
> |
z = this->data_[0][2] * (this->data_[1][0] * this->data_[2][1] - this->data_[1][1] * this->data_[2][0]); |
| 305 |
|
|
| 306 |
< |
return(x + y + z); |
| 307 |
< |
} |
| 306 |
> |
return(x + y + z); |
| 307 |
> |
} |
| 308 |
|
|
| 309 |
< |
/** Returns the trace of this matrix. */ |
| 310 |
< |
Real trace() const { |
| 311 |
< |
return data_[0][0] + data_[1][1] + data_[2][2]; |
| 312 |
< |
} |
| 309 |
> |
/** Returns the trace of this matrix. */ |
| 310 |
> |
Real trace() const { |
| 311 |
> |
return this->data_[0][0] + this->data_[1][1] + this->data_[2][2]; |
| 312 |
> |
} |
| 313 |
|
|
| 314 |
< |
/** |
| 315 |
< |
* Sets the value of this matrix to the inversion of itself. |
| 316 |
< |
* @note since simple algorithm can be applied to inverse the 3 by 3 matrix, we hide the |
| 317 |
< |
* implementation of inverse in SquareMatrix class |
| 318 |
< |
*/ |
| 319 |
< |
SquareMatrix3<Real> inverse() const { |
| 320 |
< |
SquareMatrix3<Real> m; |
| 321 |
< |
double det = determinant(); |
| 322 |
< |
if (fabs(det) <= oopse::epsilon) { |
| 323 |
< |
//"The method was called on a matrix with |determinant| <= 1e-6.", |
| 324 |
< |
//"This is a runtime or a programming error in your application."); |
| 325 |
< |
} |
| 314 |
> |
/** |
| 315 |
> |
* Sets the value of this matrix to the inversion of itself. |
| 316 |
> |
* @note since simple algorithm can be applied to inverse the 3 by 3 matrix, we hide the |
| 317 |
> |
* implementation of inverse in SquareMatrix class |
| 318 |
> |
*/ |
| 319 |
> |
SquareMatrix3<Real> inverse() const { |
| 320 |
> |
SquareMatrix3<Real> m; |
| 321 |
> |
double det = determinant(); |
| 322 |
> |
if (fabs(det) <= oopse::epsilon) { |
| 323 |
> |
//"The method was called on a matrix with |determinant| <= 1e-6.", |
| 324 |
> |
//"This is a runtime or a programming error in your application."); |
| 325 |
> |
} |
| 326 |
|
|
| 327 |
< |
m(0, 0) = data_[1][1]*data_[2][2] - data_[1][2]*data_[2][1]; |
| 328 |
< |
m(1, 0) = data_[1][2]*data_[2][0] - data_[1][0]*data_[2][2]; |
| 329 |
< |
m(2, 0) = data_[1][0]*data_[2][1] - data_[1][1]*data_[2][0]; |
| 330 |
< |
m(0, 1) = data_[2][1]*data_[0][2] - data_[2][2]*data_[0][1]; |
| 331 |
< |
m(1, 1) = data_[2][2]*data_[0][0] - data_[2][0]*data_[0][2]; |
| 332 |
< |
m(2, 1) = data_[2][0]*data_[0][1] - data_[2][1]*data_[0][0]; |
| 333 |
< |
m(0, 2) = data_[0][1]*data_[1][2] - data_[0][2]*data_[1][1]; |
| 334 |
< |
m(1, 2) = data_[0][2]*data_[1][0] - data_[0][0]*data_[1][2]; |
| 335 |
< |
m(2, 2) = data_[0][0]*data_[1][1] - data_[0][1]*data_[1][0]; |
| 327 |
> |
m(0, 0) = this->data_[1][1]*this->data_[2][2] - this->data_[1][2]*this->data_[2][1]; |
| 328 |
> |
m(1, 0) = this->data_[1][2]*this->data_[2][0] - this->data_[1][0]*this->data_[2][2]; |
| 329 |
> |
m(2, 0) = this->data_[1][0]*this->data_[2][1] - this->data_[1][1]*this->data_[2][0]; |
| 330 |
> |
m(0, 1) = this->data_[2][1]*this->data_[0][2] - this->data_[2][2]*this->data_[0][1]; |
| 331 |
> |
m(1, 1) = this->data_[2][2]*this->data_[0][0] - this->data_[2][0]*this->data_[0][2]; |
| 332 |
> |
m(2, 1) = this->data_[2][0]*this->data_[0][1] - this->data_[2][1]*this->data_[0][0]; |
| 333 |
> |
m(0, 2) = this->data_[0][1]*this->data_[1][2] - this->data_[0][2]*this->data_[1][1]; |
| 334 |
> |
m(1, 2) = this->data_[0][2]*this->data_[1][0] - this->data_[0][0]*this->data_[1][2]; |
| 335 |
> |
m(2, 2) = this->data_[0][0]*this->data_[1][1] - this->data_[0][1]*this->data_[1][0]; |
| 336 |
|
|
| 337 |
< |
m /= det; |
| 338 |
< |
return m; |
| 339 |
< |
} |
| 320 |
< |
/** |
| 321 |
< |
* Extract the eigenvalues and eigenvectors from a 3x3 matrix. |
| 322 |
< |
* The eigenvectors (the columns of V) will be normalized. |
| 323 |
< |
* The eigenvectors are aligned optimally with the x, y, and z |
| 324 |
< |
* axes respectively. |
| 325 |
< |
* @param a symmetric matrix whose eigenvectors are to be computed. On return, the matrix is |
| 326 |
< |
* overwritten |
| 327 |
< |
* @param w will contain the eigenvalues of the matrix On return of this function |
| 328 |
< |
* @param v the columns of this matrix will contain the eigenvectors. The eigenvectors are |
| 329 |
< |
* normalized and mutually orthogonal. |
| 330 |
< |
* @warning a will be overwritten |
| 331 |
< |
*/ |
| 332 |
< |
static void diagonalize(SquareMatrix3<Real>& a, Vector3<Real>& w, SquareMatrix3<Real>& v); |
| 333 |
< |
}; |
| 334 |
< |
/*========================================================================= |
| 337 |
> |
m /= det; |
| 338 |
> |
return m; |
| 339 |
> |
} |
| 340 |
|
|
| 341 |
+ |
SquareMatrix3<Real> transpose() const{ |
| 342 |
+ |
SquareMatrix3<Real> result; |
| 343 |
+ |
|
| 344 |
+ |
for (unsigned int i = 0; i < 3; i++) |
| 345 |
+ |
for (unsigned int j = 0; j < 3; j++) |
| 346 |
+ |
result(j, i) = this->data_[i][j]; |
| 347 |
+ |
|
| 348 |
+ |
return result; |
| 349 |
+ |
} |
| 350 |
+ |
/** |
| 351 |
+ |
* Extract the eigenvalues and eigenvectors from a 3x3 matrix. |
| 352 |
+ |
* The eigenvectors (the columns of V) will be normalized. |
| 353 |
+ |
* The eigenvectors are aligned optimally with the x, y, and z |
| 354 |
+ |
* axes respectively. |
| 355 |
+ |
* @param a symmetric matrix whose eigenvectors are to be computed. On return, the matrix is |
| 356 |
+ |
* overwritten |
| 357 |
+ |
* @param w will contain the eigenvalues of the matrix On return of this function |
| 358 |
+ |
* @param v the columns of this matrix will contain the eigenvectors. The eigenvectors are |
| 359 |
+ |
* normalized and mutually orthogonal. |
| 360 |
+ |
* @warning a will be overwritten |
| 361 |
+ |
*/ |
| 362 |
+ |
static void diagonalize(SquareMatrix3<Real>& a, Vector3<Real>& w, SquareMatrix3<Real>& v); |
| 363 |
+ |
}; |
| 364 |
+ |
/*========================================================================= |
| 365 |
+ |
|
| 366 |
|
Program: Visualization Toolkit |
| 367 |
|
Module: $RCSfile: SquareMatrix3.hpp,v $ |
| 368 |
|
|
| 370 |
|
All rights reserved. |
| 371 |
|
See Copyright.txt or http://www.kitware.com/Copyright.htm for details. |
| 372 |
|
|
| 373 |
< |
This software is distributed WITHOUT ANY WARRANTY; without even |
| 374 |
< |
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 375 |
< |
PURPOSE. See the above copyright notice for more information. |
| 373 |
> |
This software is distributed WITHOUT ANY WARRANTY; without even |
| 374 |
> |
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 375 |
> |
PURPOSE. See the above copyright notice for more information. |
| 376 |
|
|
| 377 |
< |
=========================================================================*/ |
| 378 |
< |
template<typename Real> |
| 379 |
< |
void SquareMatrix3<Real>::diagonalize(SquareMatrix3<Real>& a, Vector3<Real>& w, |
| 380 |
< |
SquareMatrix3<Real>& v) { |
| 381 |
< |
int i,j,k,maxI; |
| 382 |
< |
Real tmp, maxVal; |
| 383 |
< |
Vector3<Real> v_maxI, v_k, v_j; |
| 377 |
> |
=========================================================================*/ |
| 378 |
> |
template<typename Real> |
| 379 |
> |
void SquareMatrix3<Real>::diagonalize(SquareMatrix3<Real>& a, Vector3<Real>& w, |
| 380 |
> |
SquareMatrix3<Real>& v) { |
| 381 |
> |
int i,j,k,maxI; |
| 382 |
> |
Real tmp, maxVal; |
| 383 |
> |
Vector3<Real> v_maxI, v_k, v_j; |
| 384 |
|
|
| 385 |
< |
// diagonalize using Jacobi |
| 386 |
< |
jacobi(a, w, v); |
| 387 |
< |
// if all the eigenvalues are the same, return identity matrix |
| 388 |
< |
if (w[0] == w[1] && w[0] == w[2] ) { |
| 389 |
< |
v = SquareMatrix3<Real>::identity(); |
| 390 |
< |
return; |
| 391 |
< |
} |
| 385 |
> |
// diagonalize using Jacobi |
| 386 |
> |
jacobi(a, w, v); |
| 387 |
> |
// if all the eigenvalues are the same, return identity matrix |
| 388 |
> |
if (w[0] == w[1] && w[0] == w[2] ) { |
| 389 |
> |
v = SquareMatrix3<Real>::identity(); |
| 390 |
> |
return; |
| 391 |
> |
} |
| 392 |
|
|
| 393 |
< |
// transpose temporarily, it makes it easier to sort the eigenvectors |
| 394 |
< |
v = v.transpose(); |
| 393 |
> |
// transpose temporarily, it makes it easier to sort the eigenvectors |
| 394 |
> |
v = v.transpose(); |
| 395 |
|
|
| 396 |
< |
// if two eigenvalues are the same, re-orthogonalize to optimally line |
| 397 |
< |
// up the eigenvectors with the x, y, and z axes |
| 398 |
< |
for (i = 0; i < 3; i++) { |
| 399 |
< |
if (w((i+1)%3) == w((i+2)%3)) {// two eigenvalues are the same |
| 400 |
< |
// find maximum element of the independant eigenvector |
| 401 |
< |
maxVal = fabs(v(i, 0)); |
| 402 |
< |
maxI = 0; |
| 403 |
< |
for (j = 1; j < 3; j++) { |
| 404 |
< |
if (maxVal < (tmp = fabs(v(i, j)))){ |
| 405 |
< |
maxVal = tmp; |
| 406 |
< |
maxI = j; |
| 407 |
< |
} |
| 408 |
< |
} |
| 396 |
> |
// if two eigenvalues are the same, re-orthogonalize to optimally line |
| 397 |
> |
// up the eigenvectors with the x, y, and z axes |
| 398 |
> |
for (i = 0; i < 3; i++) { |
| 399 |
> |
if (w((i+1)%3) == w((i+2)%3)) {// two eigenvalues are the same |
| 400 |
> |
// find maximum element of the independant eigenvector |
| 401 |
> |
maxVal = fabs(v(i, 0)); |
| 402 |
> |
maxI = 0; |
| 403 |
> |
for (j = 1; j < 3; j++) { |
| 404 |
> |
if (maxVal < (tmp = fabs(v(i, j)))){ |
| 405 |
> |
maxVal = tmp; |
| 406 |
> |
maxI = j; |
| 407 |
> |
} |
| 408 |
> |
} |
| 409 |
|
|
| 410 |
< |
// swap the eigenvector into its proper position |
| 411 |
< |
if (maxI != i) { |
| 412 |
< |
tmp = w(maxI); |
| 413 |
< |
w(maxI) = w(i); |
| 414 |
< |
w(i) = tmp; |
| 410 |
> |
// swap the eigenvector into its proper position |
| 411 |
> |
if (maxI != i) { |
| 412 |
> |
tmp = w(maxI); |
| 413 |
> |
w(maxI) = w(i); |
| 414 |
> |
w(i) = tmp; |
| 415 |
|
|
| 416 |
< |
v.swapRow(i, maxI); |
| 417 |
< |
} |
| 418 |
< |
// maximum element of eigenvector should be positive |
| 419 |
< |
if (v(maxI, maxI) < 0) { |
| 420 |
< |
v(maxI, 0) = -v(maxI, 0); |
| 421 |
< |
v(maxI, 1) = -v(maxI, 1); |
| 422 |
< |
v(maxI, 2) = -v(maxI, 2); |
| 423 |
< |
} |
| 416 |
> |
v.swapRow(i, maxI); |
| 417 |
> |
} |
| 418 |
> |
// maximum element of eigenvector should be positive |
| 419 |
> |
if (v(maxI, maxI) < 0) { |
| 420 |
> |
v(maxI, 0) = -v(maxI, 0); |
| 421 |
> |
v(maxI, 1) = -v(maxI, 1); |
| 422 |
> |
v(maxI, 2) = -v(maxI, 2); |
| 423 |
> |
} |
| 424 |
|
|
| 425 |
< |
// re-orthogonalize the other two eigenvectors |
| 426 |
< |
j = (maxI+1)%3; |
| 427 |
< |
k = (maxI+2)%3; |
| 425 |
> |
// re-orthogonalize the other two eigenvectors |
| 426 |
> |
j = (maxI+1)%3; |
| 427 |
> |
k = (maxI+2)%3; |
| 428 |
|
|
| 429 |
< |
v(j, 0) = 0.0; |
| 430 |
< |
v(j, 1) = 0.0; |
| 431 |
< |
v(j, 2) = 0.0; |
| 432 |
< |
v(j, j) = 1.0; |
| 429 |
> |
v(j, 0) = 0.0; |
| 430 |
> |
v(j, 1) = 0.0; |
| 431 |
> |
v(j, 2) = 0.0; |
| 432 |
> |
v(j, j) = 1.0; |
| 433 |
|
|
| 434 |
< |
/** @todo */ |
| 435 |
< |
v_maxI = v.getRow(maxI); |
| 436 |
< |
v_j = v.getRow(j); |
| 437 |
< |
v_k = cross(v_maxI, v_j); |
| 438 |
< |
v_k.normalize(); |
| 439 |
< |
v_j = cross(v_k, v_maxI); |
| 440 |
< |
v.setRow(j, v_j); |
| 441 |
< |
v.setRow(k, v_k); |
| 434 |
> |
/** @todo */ |
| 435 |
> |
v_maxI = v.getRow(maxI); |
| 436 |
> |
v_j = v.getRow(j); |
| 437 |
> |
v_k = cross(v_maxI, v_j); |
| 438 |
> |
v_k.normalize(); |
| 439 |
> |
v_j = cross(v_k, v_maxI); |
| 440 |
> |
v.setRow(j, v_j); |
| 441 |
> |
v.setRow(k, v_k); |
| 442 |
|
|
| 443 |
|
|
| 444 |
< |
// transpose vectors back to columns |
| 445 |
< |
v = v.transpose(); |
| 446 |
< |
return; |
| 447 |
< |
} |
| 448 |
< |
} |
| 444 |
> |
// transpose vectors back to columns |
| 445 |
> |
v = v.transpose(); |
| 446 |
> |
return; |
| 447 |
> |
} |
| 448 |
> |
} |
| 449 |
|
|
| 450 |
< |
// the three eigenvalues are different, just sort the eigenvectors |
| 451 |
< |
// to align them with the x, y, and z axes |
| 450 |
> |
// the three eigenvalues are different, just sort the eigenvectors |
| 451 |
> |
// to align them with the x, y, and z axes |
| 452 |
|
|
| 453 |
< |
// find the vector with the largest x element, make that vector |
| 454 |
< |
// the first vector |
| 455 |
< |
maxVal = fabs(v(0, 0)); |
| 456 |
< |
maxI = 0; |
| 457 |
< |
for (i = 1; i < 3; i++) { |
| 458 |
< |
if (maxVal < (tmp = fabs(v(i, 0)))) { |
| 459 |
< |
maxVal = tmp; |
| 460 |
< |
maxI = i; |
| 461 |
< |
} |
| 462 |
< |
} |
| 453 |
> |
// find the vector with the largest x element, make that vector |
| 454 |
> |
// the first vector |
| 455 |
> |
maxVal = fabs(v(0, 0)); |
| 456 |
> |
maxI = 0; |
| 457 |
> |
for (i = 1; i < 3; i++) { |
| 458 |
> |
if (maxVal < (tmp = fabs(v(i, 0)))) { |
| 459 |
> |
maxVal = tmp; |
| 460 |
> |
maxI = i; |
| 461 |
> |
} |
| 462 |
> |
} |
| 463 |
|
|
| 464 |
< |
// swap eigenvalue and eigenvector |
| 465 |
< |
if (maxI != 0) { |
| 466 |
< |
tmp = w(maxI); |
| 467 |
< |
w(maxI) = w(0); |
| 468 |
< |
w(0) = tmp; |
| 469 |
< |
v.swapRow(maxI, 0); |
| 470 |
< |
} |
| 471 |
< |
// do the same for the y element |
| 472 |
< |
if (fabs(v(1, 1)) < fabs(v(2, 1))) { |
| 473 |
< |
tmp = w(2); |
| 474 |
< |
w(2) = w(1); |
| 475 |
< |
w(1) = tmp; |
| 476 |
< |
v.swapRow(2, 1); |
| 477 |
< |
} |
| 464 |
> |
// swap eigenvalue and eigenvector |
| 465 |
> |
if (maxI != 0) { |
| 466 |
> |
tmp = w(maxI); |
| 467 |
> |
w(maxI) = w(0); |
| 468 |
> |
w(0) = tmp; |
| 469 |
> |
v.swapRow(maxI, 0); |
| 470 |
> |
} |
| 471 |
> |
// do the same for the y element |
| 472 |
> |
if (fabs(v(1, 1)) < fabs(v(2, 1))) { |
| 473 |
> |
tmp = w(2); |
| 474 |
> |
w(2) = w(1); |
| 475 |
> |
w(1) = tmp; |
| 476 |
> |
v.swapRow(2, 1); |
| 477 |
> |
} |
| 478 |
|
|
| 479 |
< |
// ensure that the sign of the eigenvectors is correct |
| 480 |
< |
for (i = 0; i < 2; i++) { |
| 481 |
< |
if (v(i, i) < 0) { |
| 482 |
< |
v(i, 0) = -v(i, 0); |
| 483 |
< |
v(i, 1) = -v(i, 1); |
| 484 |
< |
v(i, 2) = -v(i, 2); |
| 485 |
< |
} |
| 486 |
< |
} |
| 479 |
> |
// ensure that the sign of the eigenvectors is correct |
| 480 |
> |
for (i = 0; i < 2; i++) { |
| 481 |
> |
if (v(i, i) < 0) { |
| 482 |
> |
v(i, 0) = -v(i, 0); |
| 483 |
> |
v(i, 1) = -v(i, 1); |
| 484 |
> |
v(i, 2) = -v(i, 2); |
| 485 |
> |
} |
| 486 |
> |
} |
| 487 |
|
|
| 488 |
< |
// set sign of final eigenvector to ensure that determinant is positive |
| 489 |
< |
if (v.determinant() < 0) { |
| 490 |
< |
v(2, 0) = -v(2, 0); |
| 491 |
< |
v(2, 1) = -v(2, 1); |
| 492 |
< |
v(2, 2) = -v(2, 2); |
| 463 |
< |
} |
| 464 |
< |
|
| 465 |
< |
// transpose the eigenvectors back again |
| 466 |
< |
v = v.transpose(); |
| 467 |
< |
return ; |
| 488 |
> |
// set sign of final eigenvector to ensure that determinant is positive |
| 489 |
> |
if (v.determinant() < 0) { |
| 490 |
> |
v(2, 0) = -v(2, 0); |
| 491 |
> |
v(2, 1) = -v(2, 1); |
| 492 |
> |
v(2, 2) = -v(2, 2); |
| 493 |
|
} |
| 494 |
|
|
| 495 |
< |
/** |
| 496 |
< |
* Return the multiplication of two matrixes (m1 * m2). |
| 497 |
< |
* @return the multiplication of two matrixes |
| 498 |
< |
* @param m1 the first matrix |
| 474 |
< |
* @param m2 the second matrix |
| 475 |
< |
*/ |
| 476 |
< |
template<typename Real> |
| 477 |
< |
inline SquareMatrix3<Real> operator *(const SquareMatrix3<Real>& m1, const SquareMatrix3<Real>& m2) { |
| 478 |
< |
SquareMatrix3<Real> result; |
| 495 |
> |
// transpose the eigenvectors back again |
| 496 |
> |
v = v.transpose(); |
| 497 |
> |
return ; |
| 498 |
> |
} |
| 499 |
|
|
| 500 |
< |
for (unsigned int i = 0; i < 3; i++) |
| 501 |
< |
for (unsigned int j = 0; j < 3; j++) |
| 502 |
< |
for (unsigned int k = 0; k < 3; k++) |
| 503 |
< |
result(i, j) += m1(i, k) * m2(k, j); |
| 500 |
> |
/** |
| 501 |
> |
* Return the multiplication of two matrixes (m1 * m2). |
| 502 |
> |
* @return the multiplication of two matrixes |
| 503 |
> |
* @param m1 the first matrix |
| 504 |
> |
* @param m2 the second matrix |
| 505 |
> |
*/ |
| 506 |
> |
template<typename Real> |
| 507 |
> |
inline SquareMatrix3<Real> operator *(const SquareMatrix3<Real>& m1, const SquareMatrix3<Real>& m2) { |
| 508 |
> |
SquareMatrix3<Real> result; |
| 509 |
|
|
| 510 |
< |
return result; |
| 511 |
< |
} |
| 510 |
> |
for (unsigned int i = 0; i < 3; i++) |
| 511 |
> |
for (unsigned int j = 0; j < 3; j++) |
| 512 |
> |
for (unsigned int k = 0; k < 3; k++) |
| 513 |
> |
result(i, j) += m1(i, k) * m2(k, j); |
| 514 |
|
|
| 515 |
< |
template<typename Real> |
| 516 |
< |
inline SquareMatrix3<Real> outProduct(const Vector3<Real>& v1, const Vector3<Real>& v2) { |
| 490 |
< |
SquareMatrix3<Real> result; |
| 515 |
> |
return result; |
| 516 |
> |
} |
| 517 |
|
|
| 518 |
< |
for (unsigned int i = 0; i < 3; i++) { |
| 519 |
< |
for (unsigned int j = 0; j < 3; j++) { |
| 520 |
< |
result(i, j) = v1[i] * v2[j]; |
| 521 |
< |
} |
| 522 |
< |
} |
| 523 |
< |
|
| 524 |
< |
return result; |
| 518 |
> |
template<typename Real> |
| 519 |
> |
inline SquareMatrix3<Real> outProduct(const Vector3<Real>& v1, const Vector3<Real>& v2) { |
| 520 |
> |
SquareMatrix3<Real> result; |
| 521 |
> |
|
| 522 |
> |
for (unsigned int i = 0; i < 3; i++) { |
| 523 |
> |
for (unsigned int j = 0; j < 3; j++) { |
| 524 |
> |
result(i, j) = v1[i] * v2[j]; |
| 525 |
> |
} |
| 526 |
|
} |
| 527 |
+ |
|
| 528 |
+ |
return result; |
| 529 |
+ |
} |
| 530 |
|
|
| 531 |
|
|
| 532 |
< |
typedef SquareMatrix3<double> Mat3x3d; |
| 533 |
< |
typedef SquareMatrix3<double> RotMat3x3d; |
| 532 |
> |
typedef SquareMatrix3<double> Mat3x3d; |
| 533 |
> |
typedef SquareMatrix3<double> RotMat3x3d; |
| 534 |
|
|
| 535 |
|
} //namespace oopse |
| 536 |
|
#endif // MATH_SQUAREMATRIX_HPP |