46 const Mat3x3 Eye3(1., 0., 0., 0., 1., 0., 0., 0., 1.);
135 ASSERT(
fabs(d) > std::numeric_limits<doublereal>::epsilon());
142 (p[
M13]*p[M32]-p[
M12]*p[M33])/d,
143 (p[
M11]*p[M33]-p[
M13]*p[M31])/d,
144 (p[
M12]*p[M31]-p[
M11]*p[M32])/d,
155 if (
fabs(d) < std::numeric_limits<doublereal>::epsilon()) {
156 silent_cerr(
"matrix is singular" << std::endl);
171 ASSERT(
fabs(d) > std::numeric_limits<doublereal>::epsilon());
179 (pv[
V1]*(p[
M21]*p[M32] - p[M22]*p[M31])
180 +pv[
V2]*(p[
M12]*p[M31] - p[
M11]*p[M32])
190 if (
fabs(d) < std::numeric_limits<doublereal>::epsilon()) {
191 silent_cerr(
"matrix is singular" << std::endl);
201 doublereal d1, d2, d3, l21 = 0., l31 = 0., l32 = 0.;
205 if (d1 > std::numeric_limits<doublereal>::epsilon()) {
212 if (d2 > std::numeric_limits<doublereal>::epsilon()) {
216 d3 =
pdMat[
M33] - l31*l31*d1 - l32*l32*d2;
229 if (d1 > std::numeric_limits<doublereal>::epsilon()) {
235 if (d2 > std::numeric_limits<doublereal>::epsilon()) {
241 if (d3 > std::numeric_limits<doublereal>::epsilon()) {
249 z1 -= l21*z2 + l31*z3;
251 return Vec3(z1, z2, z3);
259 return EigSym(EigenValues, EigenVectors);
266 const Mat3x3& Hints)
const
270 if (!
EigSym(EigenValues, Tmp)) {
288 if (!
IsSymmetric(std::numeric_limits<doublereal>::epsilon())) {
292 if (
IsDiag(std::numeric_limits<doublereal>::epsilon())) {
309 if (
fabs(J2) < std::numeric_limits<doublereal>::epsilon()) {
327 }
else if (dmy > 1.) {
336 if (alpha <
M_PI/6.) {
344 EigenValues(idx1) = eta1 + trA_3;
380 }
else if (irmax == 3) {
390 Vec3 t2 = r2 - s1*(s1*r2);
392 Vec3 t3 = r3 - s1*(s1*r3);
403 EigenVectors.
PutVec(idx1, v1);
406 0., s1*(AA*s1), s2*(AA*s1),
407 0., s1*(AA*s2), s2*(AA*s2));
409 int idx2 = idx1%3 + 1;
410 int idx3 = (idx1 + 1)%3 + 1;
417 EigenValues(idx2) = eta2 + trA_3;
418 EigenValues(idx3) = eta3 + trA_3;
420 Vec3 u1 = AA*s1 - s1*eta2;
422 Vec3 u2 = AA*s2 - s2*eta2;
434 EigenVectors.
PutVec(idx2, v2);
435 EigenVectors.
PutVec(idx3, v1.Cross(v2));
674 const char sForm[] =
"%15.6e%15.6e%15.6e%15.6e%15.6e%15.6e%15.6e%15.6e%15.6e";
685 << pd[
M11] << sDefFill << pd[
M12] << sDefFill << pd[
M13] << sDefFill
686 << pd[
M21] << sDefFill << pd[
M22] << sDefFill << pd[
M23] << sDefFill
687 << pd[
M31] << sDefFill << pd[
M32] << sDefFill << pd[
M33];
694 Write(std::ostream& out,
const Mat3x3& m,
const char* s,
const char* s2)
696 return m.
Write(out, s, s2);
707 out << pd[0] << sDefFill << pd[1] << sDefFill << pd[2];
716 return v.
Write(out, s);
722 Mat3x3::Write(std::ostream& out,
const char* sFill,
const char* sFill2)
const
724 char* sF2 = (
char*)sFill2;
725 if (sFill2 == NULL) {
761 if (
fabs(d) < std::numeric_limits<doublereal>::epsilon()) {
762 silent_cerr(
"MatR2gparam(): divide by zero, "
763 "probably due to singularity in rotation parameters" << std::endl);
767 return m.
Ax()*(4./d);
780 unsigned short int ib,
const Vec3& vb)
782 ASSERT(ia >= 1 && ia <= 3);
783 ASSERT(ib >= 1 && ib <= 3);
787 DEBUGCOUT(
"MatR2vec: ia = " << ia <<
" (" << va <<
"),"
788 <<
" ib = " << ib <<
" (" << vb <<
")" << std::endl);
790 if (ia < 1 || ia > 3) {
791 silent_cerr(
"MatR2vec: first index is illegal"
800 if (ib == (ia%3)+1) {
802 if (d <= std::numeric_limits<doublereal>::epsilon()) {
803 silent_cerr(
"MatR2vec: first vector must be non-null" << std::endl );
808 if (d <= std::numeric_limits<doublereal>::epsilon()) {
809 silent_cerr(
"MatR2vec: second vector must be non-null" << std::endl );
812 r[i3] = r[i1].
Cross(vb);
814 if (d <= std::numeric_limits<doublereal>::epsilon()) {
815 silent_cerr(
"MatR2vec: vectors must be distinct"
821 r[i2] = r[i3].
Cross(r[i1]);
825 return Mat3x3(r[0], r[1], r[2]);
826 }
else if (ib == ((ia+1)%3+1)) {
828 if (d <= std::numeric_limits<doublereal>::epsilon()) {
829 silent_cerr(
"MatR2vec: first vector must be non-null" << std::endl );
834 if (d <= std::numeric_limits<doublereal>::epsilon()) {
835 silent_cerr(
"MatR2vec: second vector must be non-null" << std::endl );
838 r[i2] = vb.
Cross(r[i1]);
840 if (d <= std::numeric_limits<doublereal>::epsilon()) {
841 silent_cerr(
"MatR2vec: vectors must be distinct"
847 r[i3] = r[i1].
Cross(r[i2]);
851 return Mat3x3(r[0], r[1], r[2]);
853 silent_cerr(
"MatR2vec: second index is illegal" << std::endl);
901 dCosAlpha*
R(3, 3) - dSinAlpha*
R(2, 3)),
902 atan2(dCosAlpha*
R(2, 1) + dSinAlpha*
R(3, 1),
903 dCosAlpha*
R(2, 2) + dSinAlpha*
R(3, 2)));
934 atan2(dSinAlpha*
R(1, 3) - dCosAlpha*
R(2, 3),
936 atan2(-dCosAlpha*
R(1, 2) - dSinAlpha*
R(2, 2),
937 dCosAlpha*
R(1, 1) + dSinAlpha*
R(2, 1)));
949 dCosAlpha*
R(1, 1) + dSinAlpha*
R(2, 1)),
950 atan2(dSinAlpha*
R(1, 3) - dCosAlpha*
R(2, 3),
951 -dSinAlpha*
R(1, 2) + dCosAlpha*
R(2, 2)));
959 T[1] = 1. - t + 2.*R.
dGet(1, 1);
960 T[2] = 1. - t + 2.*R.
dGet(2, 2);
961 T[3] = 1. - t + 2.*R.
dGet(3, 3);
964 for (
int i = 1; i <= 3; i++) {
980 e0 = (R.
dGet(3, 2) - R.
dGet(2, 3))/(4.*e1);
989 e0 = (R.
dGet(1, 3) - R.
dGet(3, 1))/(4.*e2);
998 e0 = (R.
dGet(2, 1) - R.
dGet(1, 2))/(4.*e3);
1028 dCosAlpha*dSinGamma + dSinAlpha*dSinBeta*dCosGamma,
1029 dSinAlpha*dSinGamma - dCosAlpha*dSinBeta*dCosGamma,
1030 -dCosBeta*dSinGamma,
1031 dCosAlpha*dCosGamma - dSinAlpha*dSinBeta*dSinGamma,
1032 dSinAlpha*dCosGamma + dCosAlpha*dSinBeta*dSinGamma,
1034 -dSinAlpha*dCosBeta,
1035 dCosAlpha*dCosBeta);
1052 dCosAlpha*dCosGamma - dSinAlpha*dCosBeta*dSinGamma,
1053 dSinAlpha*dCosGamma + dCosAlpha*dCosBeta*dSinGamma,
1055 -dCosAlpha*dSinGamma - dSinAlpha*dCosBeta*dCosGamma,
1056 -dSinAlpha*dSinGamma + dCosAlpha*dCosBeta*dCosGamma,
1059 -dCosAlpha*dSinBeta,
1080 -dSinAlpha*dCosGamma + dCosAlpha*dSinBeta*dSinGamma,
1081 dCosAlpha*dCosGamma + dSinAlpha*dSinBeta*dSinGamma,
1083 dSinAlpha*dSinGamma + dCosAlpha*dSinBeta*dCosGamma,
1084 -dCosAlpha*dSinGamma + dSinAlpha*dSinBeta*dCosGamma,
1085 dCosBeta*dCosGamma);
1094 if (dThetaPrev > std::numeric_limits<doublereal>::epsilon()) {
1103 while (dTheta - dThetaPrev >
M_PI) {
1108 while (dThetaPrev - dTheta >
M_PI) {
1114 return v*(dTheta/dThetaOld);
1140 return fabs(d1 - d2) <= dTol;
1164 return R*m.
MulMT(R);
const MatGm1_Manip MatGm1
Mat3x3 MultRMRt(const Mat3x3 &m, const Mat3x3 &R)
Mat3x3 MatR2vec(unsigned short int ia, const Vec3 &va, unsigned short int ib, const Vec3 &vb)
Mat3x3 MultRM(const Mat3x3 &m, const Mat3x3 &R)
const Vec3 Zero3(0., 0., 0.)
Vec3 Cross(const Vec3 &v) const
std::ostream & Write(std::ostream &out, const char *sFill=" ") const
Vec3 MultRV(const Vec3 &v, const Mat3x3 &R)
const doublereal & dGet(unsigned short int iRow, unsigned short int iCol) const
#define MBDYN_EXCEPT_ARGS
GradientExpression< UnaryExpr< FuncSin, Expr > > sin(const GradientExpression< Expr > &u)
Mat3x3 MultMRt(const Mat3x3 &m, const Mat3x3 &R)
const MatCross_Manip MatCross
Mat3x3 MulTMT(const Mat3x3 &m) const
doublereal Norm(void) const
bool IsNull(const doublereal &d)
doublereal Tr(void) const
doublereal Dot(const Vec3 &v) const
const Mat3x3 Eye3(1., 0., 0., 0., 1., 0., 0., 0., 1.)
bool IsSame(const doublereal &d1, const doublereal &d2, const doublereal &dTol)
Mat3x3 EulerAngles313_2MatR(const Vec3 &v)
GradientExpression< UnaryExpr< FuncFabs, Expr > > fabs(const GradientExpression< Expr > &u)
Vec3 GetVec(unsigned short int i) const
const Mat3x3DEye_Manip Mat3x3DEye
const doublereal Zero1(0.)
const Mat3x3Zero_Manip Mat3x3Zero
std::ostream & Write(std::ostream &out, const Mat3x3 &m, const char *s, const char *s2)
Vec3 MulTV(const Vec3 &v) const
const Mat3x3 Zero3x3(0., 0., 0., 0., 0., 0., 0., 0., 0.)
Vec3 MatR2gparam(const Mat3x3 &m)
Mat3x3 EulerAngles123_2MatR(const Vec3 &v)
void PutVec(unsigned short int i, const Vec3 &v)
doublereal Trace(void) const
Vec3 operator-(const Vec3 &v)
doublereal dDet(void) const
Vec3 MatR2EulerAngles313(const Mat3x3 &R)
Vec3 operator*(const doublereal &d) const
Mat3x3 MulTVCross(const Vec3 &v) const
doublereal copysign(doublereal x, doublereal y)
Vec3 MatR2EulerAngles123(const Mat3x3 &R)
Vec3 Solve(const Vec3 &v) const
bool EigSym(Vec3 &EigenValues) const
#define ASSERT(expression)
Mat3x3 EulerAngles321_2MatR(const Vec3 &v)
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Mat3x3 MulTM(const Mat3x3 &m) const
Vec3 MatR2EulerAngles(const Mat3x3 &R)
Vec3 LDLSolve(const Vec3 &v) const
bool IsSymmetric(void) const
Mat3x3 MulVCross(const Vec3 &v) const
Vec3 Unwrap(const Vec3 &vPrev, const Vec3 &v)
Vec3 MatR2LinParam(const Mat3x3 &m)
Mat3x3 EulerAngles2MatR(const Vec3 &v)
const MatCrossCross_Manip MatCrossCross
const doublereal * pGetMat(void) const
const Mat3x3Diag_Manip Mat3x3Diag
const doublereal * pGetVec(void) const
Vec3 MatR2EulerAngles321(const Mat3x3 &R)
GradientExpression< UnaryExpr< FuncAcos, Expr > > acos(const GradientExpression< Expr > &u)
std::ostream & operator<<(std::ostream &out, const Mat3x3 &m)
GradientExpression< UnaryExpr< FuncCos, Expr > > cos(const GradientExpression< Expr > &u)
Mat3x3 MulMT(const Mat3x3 &m) const
GradientExpression< BinaryExpr< FuncAtan2, LhsExpr, RhsExpr > > atan2(const GradientExpression< LhsExpr > &u, const GradientExpression< RhsExpr > &v)
std::ostream & Write(std::ostream &out, const char *sFill=" ", const char *sFill2=NULL) const
void MatR2EulerParams(const Mat3x3 &R, doublereal &e0, Vec3 &e)
bool IsExactlySame(const doublereal &d1, const doublereal &d2)