Simbody 3.9
Loading...
Searching...
No Matches
Rotation.h
Go to the documentation of this file.
1#ifndef SimTK_SimTKCOMMON_ROTATION_H_
2#define SimTK_SimTKCOMMON_ROTATION_H_
3
4/* -------------------------------------------------------------------------- *
5 * Simbody(tm): SimTKcommon *
6 * -------------------------------------------------------------------------- *
7 * This is part of the SimTK biosimulation toolkit originating from *
8 * Simbios, the NIH National Center for Physics-Based Simulation of *
9 * Biological Structures at Stanford, funded under the NIH Roadmap for *
10 * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. *
11 * *
12 * Portions copyright (c) 2005-14 Stanford University and the Authors. *
13 * Authors: Paul Mitiguy, Michael Sherman *
14 * Contributors: *
15 * *
16 * Licensed under the Apache License, Version 2.0 (the "License"); you may *
17 * not use this file except in compliance with the License. You may obtain a *
18 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
19 * *
20 * Unless required by applicable law or agreed to in writing, software *
21 * distributed under the License is distributed on an "AS IS" BASIS, *
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
23 * See the License for the specific language governing permissions and *
24 * limitations under the License. *
25 * -------------------------------------------------------------------------- */
26
27//------------------------------------------------------------------------------
28
33
34//------------------------------------------------------------------------------
35#include <iosfwd> // Forward declaration of iostream
36//------------------------------------------------------------------------------
37
38//------------------------------------------------------------------------------
39namespace SimTK {
40
41
43
44//------------------------------------------------------------------------------
45// Forward declarations
46template <class P> class Rotation_;
47template <class P> class InverseRotation_;
48
52
56
57//------------------------------------------------------------------------------
109//------------------------------------------------------------------------------
110template <class P> // templatized by precision
111class Rotation_ : public Mat<3,3,P> {
112public:
113typedef P RealP;
122typedef UnitVec<P,1> UnitVec3P; // stride is 1 here, length is always 3
125
132
133//------------------------------------------------------------------------------
138
140Rotation_( const Rotation_& R ) : Mat33P(R) {}
144
147{ Mat33P::operator=( R.asMat33() ); return *this; }
150
153{ Mat33P::setToNaN(); return *this; }
154
158
169
181{ Mat33P& R = *this; R[0][0] = 1; R[0][1] = R[0][2] = R[1][0] = R[2][0] = 0;
182 R[1][1] = R[2][2] = cosAngle; R[1][2] = -(R[2][1] = sinAngle);
183 return *this; }
184
196{ Mat33P& R = *this; R[1][1] = 1; R[0][1] = R[1][0] = R[1][2] = R[2][1] = 0;
197 R[0][0] = R[2][2] = cosAngle; R[2][0] = -(R[0][2] = sinAngle);
198 return *this; }
199
211{ Mat33P& R = *this; R[2][2] = 1; R[0][2] = R[1][2] = R[2][0] = R[2][1] = 0;
212 R[0][0] = R[1][1] = cosAngle; R[0][1] = -(R[1][0] = sinAngle);
213 return *this; }
214
223
230Rotation_&
233
246
262
268
276
279Rotation_(const Mat33P& m, bool) : Mat33P(m) {}
283{ Mat33P& R = *this; R=m; return *this; }
287{ Mat33P& R = *this; R(colj)=uvecj.asVec3(); return *this; }
291 (const UnitVec3P& colA, const UnitVec3P& colB, const UnitVec3P& colC)
292{ Mat33P& R = *this; R(0)=colA.asVec3(); R(1)=colB.asVec3(); R(2)=colC.asVec3();
293 return *this; }
294
303
322
330
343 Mat33P& R = *this;
344 const RealP s0s1=s[0]*s[1], s2c0=s[2]*c[0], c0c2=c[0]*c[2], nc1= -c[1];
345
346 R = Mat33P( c[1]*c[2] , s[2]*nc1 , s[1] ,
347 s2c0 + s0s1*c[2] , c0c2 - s0s1*s[2] , s[0]*nc1 ,
348 s[0]*s[2] - s[1]*c0c2 , s[0]*c[2] + s[1]*s2c0 , c[0]*c[1] );
349}
351
352//------------------------------------------------------------------------------
357const InverseRotation_<P>& operator~() const { return invert(); }
361
365const InverseRotation_<P>& transpose() const { return invert(); }
370
374{ return *reinterpret_cast<const InverseRotation_<P>*>(this); }
377{ return *reinterpret_cast<InverseRotation_<P>*>(this); }
378
387 const int k = axis;
388 Mat33P R = asMat33();
389 // Element (i,j) is scaled by s[i]*s[j], so this negates the row and column
390 // for the mirrored axis k. The sign of the diagonal element (k,k) remains
391 // unchanged.
392 for (int i = 0; i < 3; ++i)
393 if (i != k) { R(k,i) = -R(k,i); R(i,k) = -R(i,k); }
394 return Rotation_(R, true);
395}
396
401
406
414 const Vec2P& sinxy,
416 const Vec3P& w_PB)
417{
418 const RealP s0 = sinxy[0], c0 = cosxy[0];
419 const RealP s1 = sinxy[1];
420 const RealP w0 = w_PB[0], w1 = w_PB[1], w2 = w_PB[2];
421
422 const RealP t = (s0*w1-c0*w2)*oocosy;
423 return Vec3P( w0 + t*s1, c0*w1 + s0*w2, -t ); // qdot
424}
425
430 const Vec2P& sinxy,
432 const Vec3P& q)
433{
434 const RealP s0 = sinxy[0], c0 = cosxy[0];
435 const RealP s1 = sinxy[1];
436 const RealP q0 = q[0], q1 = q[1], q2 = q[2];
437
438 const RealP t = (q0*s1-q2) * oocosy;
439 return Vec3P( q0, c0*q1 + t*s0, s0*q1 - t*c0 ); // v_P
440}
441
445 const Vec2P& sinxy,
446 const Vec3P& qdot)
447{
448 const RealP s0 = sinxy[0], c0 = cosxy[0];
449 const RealP s1 = sinxy[1], c1 = cosxy[1];
450 const RealP q0 = qdot[0], q1 = qdot[1], q2 = qdot[2];
451 const RealP c1q2 = c1*q2;
452
453 return Vec3P( q0 + s1*q2, // w_PB
454 c0*q1 - s0*c1q2,
455 s0*q1 + c0*c1q2 );
456}
457
461 const Vec2P& sinxy,
462 const Vec3P& v_P)
463{
464 const RealP s0 = sinxy[0], c0 = cosxy[0];
465 const RealP s1 = sinxy[1], c1 = cosxy[1];
466 const RealP w0 = v_P[0], w1 = v_P[1], w2 = v_P[2];
467
468 return Vec3P( w0, // qdot-like
469 c0*w1 + s0*w2,
470 s1*w0 - s0*c1*w1 + c0*c1*w2);
471}
473
474//------------------------------------------------------------------------------
479const RowType& row( int i ) const
480{ return reinterpret_cast<const RowType&>(asMat33()[i]); }
482const RowType& operator[]( int i ) const { return row(i); }
483
486const ColType& col( int j ) const
487{ return reinterpret_cast<const ColType&>(asMat33()(j)); }
489const ColType& operator()( int j ) const { return col(j); }
490
492const ColType& x() const { return col(0); }
494const ColType& y() const { return col(1); }
496const ColType& z() const { return col(2); }
497
503{ return col(axis); }
504
510 const ColType& axDir = getAxisUnitVec(dir.getAxis());
511 return dir.getDirection() > 0 ? UnitVec<P,1>( axDir)
512 : UnitVec<P,1>(-axDir); // cheap
513}
515
516//------------------------------------------------------------------------------
530 // Note: q[0] is not referenced so we won't waste time calculating
531 // its cosine and sine here.
533 (Vec3P(0, std::cos(q[1]), std::cos(q[2])),
534 Vec3P(0, std::sin(q[1]), std::sin(q[2])));
535}
536
543 const RealP s1 = sq[1], c1 = cq[1];
544 const RealP s2 = sq[2], c2 = cq[2];
545 const RealP ooc1 = 1/c1;
546 const RealP s2oc1 = s2*ooc1, c2oc1 = c2*ooc1;
547
548 return Mat33P( c2oc1 , -s2oc1 , 0,
549 s2 , c2 , 0,
550 -s1*c2oc1 , s1*s2oc1, 1 );
551}
552
564 // Note: q[2] is not referenced so we won't waste time calculating
565 // its cosine and sine here.
567 (Vec3P(std::cos(q[0]), std::cos(q[1]), 0),
568 Vec3P(std::sin(q[0]), std::sin(q[1]), 0));
569}
570
578 const RealP s0 = sq[0], c0 = cq[0];
579 const RealP s1 = sq[1], c1 = cq[1];
580 const RealP ooc1 = 1/c1;
581 const RealP s0oc1 = s0*ooc1, c0oc1 = c0*ooc1;
582
583 return Mat33P( 1 , s1*s0oc1 , -s1*c0oc1,
584 0 , c0 , s0,
585 0 , -s0oc1 , c0oc1 );
586}
587
598 (const Vec3P& q, const Vec3P& qdot) {
599 // Note: q[0] is not referenced so we won't waste time calculating
600 // its cosine and sine here.
602 (Vec3P(0, std::cos(q[1]), std::cos(q[2])),
603 Vec3P(0, std::sin(q[1]), std::sin(q[2])),
604 qdot);
605}
606
613 (const Vec3P& cq, const Vec3P& sq, const Vec3P& qdot)
614{
615 const RealP s1 = sq[1], c1 = cq[1];
616 const RealP s2 = sq[2], c2 = cq[2];
617 const RealP ooc1 = 1/c1;
618 const RealP s2oc1 = s2*ooc1, c2oc1 = c2*ooc1;
619
620 const RealP t = qdot[1]*s1*ooc1;
621 const RealP a = t*s2oc1 + qdot[2]*c2oc1; // d/dt s2oc1
622 const RealP b = t*c2oc1 - qdot[2]*s2oc1; // d/dt c2oc1
623
624 return Mat33P( b , -a , 0,
625 qdot[2]*c2 , -qdot[2]*s2 , 0,
626 -(s1*b + qdot[1]*c2) , s1*a + qdot[1]*s2 , 0 );
627}
628
639 (const Vec3P& q, const Vec3P& qdot) {
640 // Note: q[2] is not referenced so we won't waste time calculating
641 // its cosine and sine here.
642 const RealP cy = std::cos(q[1]); // cos(y)
644 (Vec2P(std::cos(q[0]), cy),
645 Vec2P(std::sin(q[0]), std::sin(q[1])),
646 1/cy, qdot);
647}
648
653 (const Vec2P& cq, const Vec2P& sq, RealP ooc1, const Vec3P& qdot) {
654 const RealP s0 = sq[0], c0 = cq[0];
655 const RealP s1 = sq[1];
656 const RealP s0oc1 = s0*ooc1, c0oc1 = c0*ooc1;
657
658 const RealP t = qdot[1]*s1*ooc1;
659 const RealP a = t*s0oc1 + qdot[0]*c0oc1; // d/dt s0oc1
660 const RealP b = t*c0oc1 - qdot[0]*s0oc1; // d/dt c0oc1
661
662 return Mat33P( 0, s1*a + qdot[1]*s0, -(s1*b + qdot[1]*c0),
663 0, -qdot[0]*s0 , qdot[0]*c0 ,
664 0, -a , b );
665}
666
676 // Note: q[0] is not referenced so we won't waste time calculating
677 // its cosine and sine here.
679 (Vec3P(0, std::cos(q[1]), std::cos(q[2])),
680 Vec3P(0, std::sin(q[1]), std::sin(q[2])));
681}
682
688 (const Vec3P& cq, const Vec3P& sq) {
689 const RealP s1 = sq[1], c1 = cq[1];
690 const RealP s2 = sq[2], c2 = cq[2];
691
692 return Mat33P( c1*c2 , s2 , 0 ,
693 -c1*s2 , c2 , 0 ,
694 s1 , 0 , 1 );
695}
696
705 // Note: q[0] is not referenced so we won't waste time calculating
706 // its cosine and sine here.
708 (Vec3P(std::cos(q[0]), std::cos(q[1]), 0),
709 Vec3P(std::sin(q[0]), std::sin(q[1]), 0));
710}
711
717 (const Vec3P& cq, const Vec3P& sq) {
718 const RealP s0 = sq[0], c0 = cq[0];
719 const RealP s1 = sq[1], c1 = cq[1];
720
721 return Mat33P( 1 , 0 , s1 ,
722 0 , c0 , -s0*c1 ,
723 0 , s0 , c0*c1 );
724}
725
731 const Vec4P e = q/2;
732 const RealP ne1 = -e[1], ne2 = -e[2], ne3 = -e[3];
733 return Mat43P( ne1, ne2, ne3,
734 e[0], e[3], ne2,
735 ne3, e[0], e[1],
736 e[2], ne1, e[0]);
737}
738
745 const Vec4P ed = qdot/2;
746 const RealP ned1 = -ed[1], ned2 = -ed[2], ned3 = -ed[3];
747 return Mat43P( ned1, ned2, ned3,
748 ed[0], ed[3], ned2,
749 ned3, ed[0], ed[1],
750 ed[2], ned1, ed[0]);
751}
752
761 const Vec4P e = 2*q;
762 const RealP ne1 = -e[1], ne2 = -e[2], ne3 = -e[3];
763 return Mat34P(ne1, e[0], ne3, e[2],
764 ne2, e[3], e[0], ne1,
765 ne3, ne2, e[1], e[0]);
766}
768
769//------------------------------------------------------------------------------
775const Mat33P& asMat33() const { return *static_cast<const Mat33P*>(this); }
779Mat33P toMat33() const { return asMat33(); }
780
791
792// Converts rotation matrix to one or two or three orientation angles.
793// Note: The result is most meaningful if the Rotation_ matrix is one that can
794// be produced by such a sequence.
795// Use1: someRotation.convertOneAxisRotationToOneAngle( XAxis );
796// Use2: someRotation.convertTwoAxesRotationToTwoAngles
797// (SpaceRotationSequence, YAxis, ZAxis );
798// Use3: someRotation.convertThreeAxesRotationToThreeAngles
799// (SpaceRotationSequence, ZAxis, YAxis, XAxis );
800// Use4: someRotation.convertRotationToAngleAxis();
801// Return: [angleInRadians, unitVectorX, unitVectorY, unitVectorZ].
802
808
814 const CoordinateAxis& axis1,
815 const CoordinateAxis& axis2) const;
816
823 const CoordinateAxis& axis2, const CoordinateAxis& axis3 ) const;
824
836
856
864
870 const RealP s1 = std::sin(q[1]), c1 = std::cos(q[1]);
871 const RealP s2 = std::sin(q[2]), c2 = std::cos(q[2]);
872 const RealP ooc1 = RealP(1)/c1;
873 const RealP s2oc1 = s2*ooc1, c2oc1 = c2*ooc1;
874
875 const Mat33P E( 0, s2oc1 , c2oc1 ,
876 0, c2 , -s2 ,
877 1, s1*s2oc1 , s1*c2oc1 );
878 return E * w_PB_B;
879}
880
884 const RealP s1 = std::sin(q[1]), c1 = std::cos(q[1]);
885 const RealP s2 = std::sin(q[2]), c2 = std::cos(q[2]);
886
887 const Mat33P Einv( -s1 , 0 , 1 ,
888 c1*s2 , c2 , 0 ,
889 c1*c2 , -s2 , 0 );
890 return Einv*qd;
891}
892
893// TODO: sherm: is this right? Warning: everything is measured in the
894// *PARENT* frame, but angular velocities and accelerations are
895// expressed in the *BODY* frame.
896// TODO: this is not an efficient way to do this computation.
899 (const Vec3P& q, const Vec3P& w_PB_B, const Vec3P& wdot_PB_B)
900{
901 const RealP s1 = std::sin(q[1]), c1 = std::cos(q[1]);
902 const RealP s2 = std::sin(q[2]), c2 = std::cos(q[2]);
903 const RealP ooc1 = 1/c1;
904 const RealP s2oc1 = s2*ooc1, c2oc1 = c2*ooc1, s1oc1 = s1*ooc1;
905
906 const Mat33P E( 0 , s2oc1 , c2oc1 ,
907 0 , c2 , -s2 ,
908 1 , s1*s2oc1 , s1*c2oc1 );
909 const Vec3P qdot = E * w_PB_B;
910
911 const RealP t = qdot[1]*s1oc1;
912 const RealP a = t*s2oc1 + qdot[2]*c2oc1; // d/dt s2oc1
913 const RealP b = t*c2oc1 - qdot[2]*s2oc1; // d/dt c2oc1
914
915 const Mat33P Edot( 0 , a , b ,
916 0 , -qdot[2]*s2 , -qdot[2]*c2 ,
917 0 , s1*a + qdot[1]*s2 , s1*b + qdot[1]*c2 );
918
919 return E*wdot_PB_B + Edot*w_PB_B;
920}
921
931 (const Vec3P& q, const Vec3P& w_PB_B) {
933 (Vec3P(0, std::cos(q[1]), std::cos(q[2])),
934 Vec3P(0, std::sin(q[1]), std::sin(q[2])),
935 w_PB_B);
936}
937
943//TODO: reimplement
947
954 (const Vec3P& q, const Vec3P& qdot) {
956 (Vec3P(0, std::cos(q[1]), std::cos(q[2])),
957 Vec3P(0, std::sin(q[1]), std::sin(q[2])),
958 qdot);
959}
960
966// TODO: reimplement
970
971// TODO: sherm: is this right?
978 (const Vec3P& q, const Vec3P& w_PB_B, const Vec3P& wdot_PB_B)
979{
980 // Note: q[0] is not referenced so we won't waste time calculating
981 // its cosine and sine here.
983 (Vec3P(0, std::cos(q[1]), std::cos(q[2])),
984 Vec3P(0, std::sin(q[1]), std::sin(q[2])),
986}
987
993// TODO: reimplement
995 (const Vec3P& cq, const Vec3P& sq,
996 const Vec3P& w_PB_B, const Vec3P& wdot_PB_B)
997{
998 const Mat33P N = calcNForBodyXYZInBodyFrame(cq,sq); // ~12 flops
999 const Vec3P qdot = N * w_PB_B; // 15 flops
1000 const Mat33P NDot = calcNDotForBodyXYZInBodyFrame(cq,sq,qdot); // ~30 flops
1001
1002 return N*wdot_PB_B + NDot*w_PB_B; // 33 flops
1003}
1004
1011
1017
1025 (const Vec4P& q, const Vec3P& w_PB, const Vec3P& b_PB)
1026{
1027 const Mat43P N = calcUnnormalizedNForQuaternion(q); // 7 flops
1028 const Vec4P Nb = N*b_PB; // 20 flops
1029 const Vec4P NDotw = RealP(-.25)*w_PB.normSqr()*q; // 10 flops
1030 return Nb + NDotw; // 4 flops
1031}
1032
1040 (const Vec2P& cosxy,
1041 const Vec2P& sinxy,
1042 RealP oocosy,
1043 const Vec3P& w_PB)
1044{
1046}
1047
1060 (const Vec2P& cosxy,
1061 const Vec2P& sinxy,
1062 RealP oocosy,
1063 const Vec3P& qdot,
1064 const Vec3P& b_PB)
1065{
1066 const RealP s1 = sinxy[1], c1 = cosxy[1];
1067 const RealP q0 = qdot[0], q1 = qdot[1], q2 = qdot[2];
1068
1069 // 10 flops
1071
1072 const RealP q1oc1 = q1*oocosy;
1073 const Vec3P NDotw((q0*s1-q2)*q1oc1, // NDot_P*w_PB
1074 q0*q2*c1, // = NDot_P*(NInv_P*qdot)
1075 (q2*s1-q0)*q1oc1 ); // (9 flops)
1076
1077 return Nb + NDotw; // 3 flops
1078}
1080
1081//------------------------------------------------------------------------------
1088 const;
1089
1094
1098 const Mat33P& A=asMat33(); const Mat33P& B=R.asMat33(); RealP maxDiff=0;
1099 for( int i=0; i<=2; i++ ) for( int j=0; j<=2; j++ ) {
1100 const RealP absDiff = std::abs(A[i][j] - B[i][j]);
1101 if( absDiff > maxDiff ) maxDiff = absDiff;
1102 }
1103 return maxDiff;
1104}
1105
1110
1116
1117
1118private:
1119// This is only for the most trustworthy of callers, that is, methods of
1120// the Rotation_ class. There are a lot of ways for this NOT to be a
1121// legitimate rotation matrix -- be careful!!
1122// Note that these are supplied in rows.
1123Rotation_( const RealP& xx, const RealP& xy, const RealP& xz,
1124 const RealP& yx, const RealP& yy, const RealP& yz,
1125 const RealP& zx, const RealP& zy, const RealP& zz )
1126: Mat33P( xx,xy,xz, yx,yy,yz, zx,zy,zz ) {}
1127
1128// These next methods are highly-efficient power-user methods. Read the
1129// code to understand them.
1131setTwoAngleTwoAxesBodyFixedForwardCyclicalRotation
1132 (RealP cosAngle1, RealP sinAngle1, const CoordinateAxis& axis1,
1133 RealP cosAngle2, RealP sinAngle2, const CoordinateAxis& axis2 );
1135setThreeAngleTwoAxesBodyFixedForwardCyclicalRotation
1136 (RealP cosAngle1, RealP sinAngle1, const CoordinateAxis& axis1,
1137 RealP cosAngle2, RealP sinAngle2, const CoordinateAxis& axis2,
1140setThreeAngleThreeAxesBodyFixedForwardCyclicalRotation
1141 (RealP cosAngle1, RealP sinAngle1, const CoordinateAxis& axis1,
1142 RealP cosAngle2, RealP sinAngle2, const CoordinateAxis& axis2,
1143 RealP cosAngle3, RealP sinAngle3, const CoordinateAxis& axis3 );
1144
1145// These next methods are highly-efficient power-user methods to convert
1146// Rotation matrices to orientation angles. Read the code to understand them.
1148convertTwoAxesBodyFixedRotationToTwoAngles
1149 (const CoordinateAxis& axis1, const CoordinateAxis& axis2 ) const;
1151convertTwoAxesBodyFixedRotationToThreeAngles
1152 (const CoordinateAxis& axis1, const CoordinateAxis& axis2 ) const;
1154convertThreeAxesBodyFixedRotationToThreeAngles
1155 (const CoordinateAxis& axis1, const CoordinateAxis& axis2,
1156 const CoordinateAxis& axis3 ) const;
1157
1158//------------------------------------------------------------------------------
1159// These are obsolete names from a previous release, listed here so that
1160// users will get a decipherable compilation error. (sherm 091101)
1161//------------------------------------------------------------------------------
1162private:
1163// REPLACED BY: calcNForBodyXYZInBodyFrame()
1164static Mat33P calcQBlockForBodyXYZInBodyFrame(const Vec3P& a)
1165{ return calcNForBodyXYZInBodyFrame(a); }
1166// REPLACED BY: calcNInvForBodyXYZInBodyFrame()
1167static Mat33P calcQInvBlockForBodyXYZInBodyFrame(const Vec3P& a)
1168{ return calcNInvForBodyXYZInBodyFrame(a); }
1169// REPLACED BY: calcUnnormalizedNForQuaternion()
1170static Mat<4,3,P> calcUnnormalizedQBlockForQuaternion(const Vec4P& q)
1172// REPLACED BY: calcUnnormalizedNInvForQuaternion()
1173static Mat<3,4,P> calcUnnormalizedQInvBlockForQuaternion(const Vec4P& q)
1175// REPLACED BY: convertAngVelInBodyFrameToBodyXYZDot
1176static Vec3P convertAngVelToBodyFixed123Dot(const Vec3P& q, const Vec3P& w_PB_B)
1178// REPLACED BY: convertBodyXYZDotToAngVelInBodyFrame
1179static Vec3P convertBodyFixed123DotToAngVel(const Vec3P& q, const Vec3P& qdot)
1181// REPLACED BY: convertAngVelDotInBodyFrameToBodyXYZDotDot
1182static Vec3P convertAngVelDotToBodyFixed123DotDot
1183 (const Vec3P& q, const Vec3P& w_PB_B, const Vec3P& wdot_PB_B)
1185
1186//------------------------------------------------------------------------------
1187// The following code is obsolete - it is here temporarily for backward
1188// compatibility (Mitiguy 9/5/2007)
1189//------------------------------------------------------------------------------
1190private:
1191// These static methods are like constructors with friendlier names.
1192static Rotation_ zero() { return Rotation_(); }
1193static Rotation_ NaN() { Rotation_ r; r.setRotationToNaN(); return r; }
1194
1196Rotation_& setToZero() { return setRotationToIdentityMatrix(); }
1197Rotation_& setToIdentityMatrix() { return setRotationToIdentityMatrix(); }
1198Rotation_& setToNaN() { return setRotationToNaN(); }
1199static Rotation_ trustMe( const Mat33P& m ) { return Rotation_(m,true); }
1200
1201// One-angle rotations.
1202static Rotation_ aboutX( const RealP& angleInRad )
1203{ return Rotation_( angleInRad, XAxis ); }
1204static Rotation_ aboutY( const RealP& angleInRad )
1205{ return Rotation_( angleInRad, YAxis ); }
1206static Rotation_ aboutZ( const RealP& angleInRad )
1207{ return Rotation_( angleInRad, ZAxis ); }
1208static Rotation_ aboutAxis( const RealP& angleInRad, const UnitVec3P& axis )
1209{ return Rotation_(angleInRad,axis); }
1210static Rotation_ aboutAxis( const RealP& angleInRad, const Vec3P& axis )
1211{ return Rotation_(angleInRad,axis); }
1212void setToRotationAboutZ( const RealP& q ) { setRotationFromAngleAboutZ( q ); }
1213
1214// Two-angle space-fixed rotations.
1215static Rotation_ aboutXThenOldY(const RealP& xInRad, const RealP& yInRad)
1217static Rotation_ aboutYThenOldX(const RealP& yInRad, const RealP& xInRad)
1219static Rotation_ aboutXThenOldZ(const RealP& xInRad, const RealP& zInRad)
1221static Rotation_ aboutZThenOldX(const RealP& zInRad, const RealP& xInRad)
1223static Rotation_ aboutYThenOldZ(const RealP& yInRad, const RealP& zInRad)
1225static Rotation_ aboutZThenOldY(const RealP& zInRad, const RealP& yInRad)
1227
1228// Two-angle body fixed rotations (reversed space-fixed ones).
1229static Rotation_ aboutXThenNewY(const RealP& xInRad, const RealP& yInRad)
1231static Rotation_ aboutYThenNewX(const RealP& yInRad, const RealP& xInRad)
1232{ return aboutXThenOldY(xInRad, yInRad); }
1233static Rotation_ aboutXThenNewZ(const RealP& xInRad, const RealP& zInRad)
1234{ return aboutZThenOldX(zInRad, xInRad); }
1235static Rotation_ aboutZThenNewX(const RealP& zInRad, const RealP& xInRad)
1236{ return aboutXThenOldZ(xInRad, zInRad); }
1237static Rotation_ aboutYThenNewZ(const RealP& yInRad, const RealP& zInRad)
1238{ return aboutZThenOldY(zInRad, yInRad); }
1239static Rotation_ aboutZThenNewY(const RealP& zInRad, const RealP& yInRad)
1240{ return aboutYThenOldZ(yInRad, zInRad); }
1241
1242// Create a Rotation_ matrix by specifying only its z axis.
1243// This will work for any stride UnitVec because there is always an implicit
1244// conversion available to the packed form used as the argument.
1245explicit Rotation_( const UnitVec3P& uvecZ )
1247
1248// Create a Rotation_ matrix by specifying its x axis, and a "y like" axis.
1249// We will take x seriously after normalizing, but use the y only to create
1250// z = normalize(x X y), then y = z X x. Bad things happen if x and y are
1251// aligned but we may not catch it.
1252Rotation_( const Vec3P& x, const Vec3P& yish )
1254
1255// Set this Rotation_ to represent the same rotation as the passed-in quaternion.
1256void setToQuaternion( const QuaternionP& q ) { setRotationFromQuaternion(q); }
1257
1258// Set this Rotation_ to represent a rotation of +q0 about body frame's Z axis,
1259// followed by a rotation of +q1 about the body frame's NEW Y axis,
1260// followed by a rotation of +q3 about the body frame's NEW X axis.
1261// See Kane, Spacecraft Dynamics, pg. 423, body-three: 3-2-1.
1262// Similarly for BodyFixed123.
1263void setToBodyFixed321( const Vec3P& v)
1265 v[0], ZAxis, v[1], YAxis, v[2], XAxis ); }
1266void setToBodyFixed123( const Vec3P& v)
1268
1269// Convert this Rotation_ matrix to an equivalent (angle,axis) representation:
1270// Returned Vec4P is [angleInRadians, unitVectorX, unitVectorY, unitVectorZ].
1271Vec4P convertToAngleAxis() const
1272{ return convertRotationToAngleAxis(); }
1273
1274// Convert this Rotation_ matrix to equivalent quaternion representation.
1275QuaternionP convertToQuaternion() const
1276{ return convertRotationToQuaternion(); }
1277
1278// Set this Rotation_ to represent a rotation of +q0 about base frame's X axis,
1279// followed by a rotation of +q1 about the base frame's (unchanged) Y axis.
1280void setToSpaceFixed12( const Vec2P& q )
1282
1283// Convert this Rotation_ matrix to the equivalent 1-2-3 body fixed Euler angle
1284// sequence. Similarly, convert Rotation_ matrix to the equivalent 1-2 body
1285// fixed Euler angle sequence. Similarly, convert Rotation_ matrix to the
1286// equivalent 1-2 space fixed Euler angle sequence.
1287Vec3P convertToBodyFixed123() const
1289Vec2P convertToBodyFixed12() const
1290{ return convertRotationToBodyFixedXY(); }
1291Vec2P convertToSpaceFixed12() const
1293};
1294
1295
1296//-----------------------------------------------------------------------------
1299//-----------------------------------------------------------------------------
1300template <class P>
1301class InverseRotation_ : public Mat<3,3,P>::TransposeType {
1302typedef Mat<3,3,P> Mat33P; // not the base type!
1303typedef Mat<2,2,P> Mat22P;
1304typedef Mat<3,2,P> Mat32P;
1305typedef Vec<2,P> Vec2P;
1306typedef Vec<3,P> Vec3P;
1307typedef Vec<4,P> Vec4P;
1309public:
1313
1322
1327
1332{ BaseMat::operator=(R.asMat33()); return *this; }
1333
1342
1346const Rotation_<P>& invert() const
1347{return *reinterpret_cast<const Rotation_<P>*>(this);}
1348Rotation_<P>& updInvert() {return *reinterpret_cast<Rotation_<P>*>(this);}
1350
1354const Rotation_<P>& transpose() const { return invert(); }
1355const Rotation_<P>& operator~() const { return invert(); }
1359
1366const RowType& row( int i ) const
1367{ return reinterpret_cast<const RowType&>(asMat33()[i]); }
1368const RowType& operator[]( int i ) const { return row(i); }
1369const ColType& col( int j ) const
1370{ return reinterpret_cast<const ColType&>(asMat33()(j)); }
1371const ColType& operator()( int j ) const { return col(j); }
1372const ColType& x() const { return col(0); }
1373const ColType& y() const { return col(1); }
1374const ColType& z() const { return col(2); }
1376
1377
1383{ return col(axis); }
1384
1390 const ColType& axDir = getAxisUnitVec(dir.getAxis());
1391 return dir.getDirection() > 0 ? UnitVec<P,1>( axDir)
1392 : UnitVec<P,1>(-axDir); // cheap
1393}
1394
1399const BaseMat& asMat33() const { return *static_cast<const BaseMat*>(this); }
1400BaseMat toMat33() const { return asMat33(); }
1402};
1403
1406template <class P> SimTK_SimTKCOMMON_EXPORT std::ostream&
1407operator<<(std::ostream&, const Rotation_<P>&);
1410template <class P> SimTK_SimTKCOMMON_EXPORT std::ostream&
1411operator<<(std::ostream&, const InverseRotation_<P>&);
1412
1417template <class P, int S> inline UnitVec<P,1>
1419{return UnitVec<P,1>(R.asMat33()* v.asVec3(), true);}
1420template <class P, int S> inline UnitRow<P,1>
1422{return UnitRow<P,1>(r.asRow3() * R.asMat33(), true);}
1423template <class P, int S> inline UnitVec<P,1>
1425{return UnitVec<P,1>(R.asMat33()* v.asVec3(), true);}
1426template <class P, int S> inline UnitRow<P,1>
1428{return UnitRow<P,1>(r.asRow3() * R.asMat33(), true);}
1430
1431// Couldn't implement these Rotation_ methods until InverseRotation_ was defined.
1432template <class P> inline
1434: Mat<3,3,P>( R.asMat33() ) {}
1435
1436template <class P> inline Rotation_<P>&
1438{static_cast<Mat<3,3,P>&>(*this) = R.asMat33(); return *this;}
1439template <class P> inline Rotation_<P>&
1441{static_cast<Mat<3,3,P>&>(*this) *= R.asMat33(); return *this;}
1442template <class P> inline Rotation_<P>&
1444{static_cast<Mat<3,3,P>&>(*this) *= (~R).asMat33(); return *this;}
1445template <class P> inline Rotation_<P>&
1447{static_cast<Mat<3,3,P>&>(*this) *= R.asMat33(); return *this;}
1448template <class P> inline Rotation_<P>&
1450{static_cast<Mat<3,3,P>&>(*this) *= (~R).asMat33(); return *this;}
1451
1453
1454template <class P> inline Rotation_<P>
1456{return Rotation_<P>(R1) *= R2;}
1457template <class P> inline Rotation_<P>
1459{return Rotation_<P>(R1) *= R2;}
1460template <class P> inline Rotation_<P>
1462{return Rotation_<P>(R1) *= R2;}
1463template <class P> inline Rotation_<P>
1465{return Rotation_<P>(R1) *= R2;}
1467
1470
1471template <class P> inline Rotation_<P>
1472operator/( const Rotation_<P>& R1, const Rotation_<P>& R2 )
1473{return Rotation_<P>(R1) /= R2;}
1474template <class P> inline Rotation_<P>
1476{return Rotation_<P>(R1) /= R2;}
1477template <class P> inline Rotation_<P>
1479{return Rotation_<P>(R1) /= R2;}
1480template <class P> inline Rotation_<P>
1482{return Rotation_<P>(R1) /= R2;}
1484
1485
1486//------------------------------------------------------------------------------
1487} // End of namespace SimTK
1488
1489#endif // SimTK_SimTKCOMMON_ROTATION_H_
1490
1491
Defines the CoordinateAxis and CoordinateDirection classes.
#define SimTK_SimTKCOMMON_EXPORT
Definition SimTKcommon/include/SimTKcommon/internal/common.h:224
This file is the user-includeable header to be included in user programs to provide fixed-length Vec ...
Declares and defines the UnitVec and UnitRow classes.
Definition CoordinateAxis.h:194
Definition CoordinateAxis.h:198
Definition CoordinateAxis.h:202
This class, along with its sister class CoordinateDirection, provides convenient manipulation of the ...
Definition CoordinateAxis.h:53
A CoordinateDirection is a CoordinateAxis plus a direction indicating the positive or negative direct...
Definition CoordinateAxis.h:247
(Advanced) This InverseRotation class is the inverse of a Rotation.
Definition Rotation.h:1301
Rotation_< P > & updInvert()
Definition Rotation.h:1348
const ColType & col(int j) const
Definition Rotation.h:1369
const ColType & z() const
Definition Rotation.h:1374
const Rotation_< P > & invert() const
We can invert an InverseRotation just by recasting it to a Rotation at zero cost.
Definition Rotation.h:1346
const Rotation_< P > & transpose() const
Transpose, and transpose operators (override BaseMat versions of transpose).
Definition Rotation.h:1354
InverseRotation_(const InverseRotation_ &R)
An explicit implementation of the default copy constructor.
Definition Rotation.h:1329
const ColType & getAxisUnitVec(CoordinateAxis axis) const
Given a CoordinateAxis (XAxis,YAxis, or ZAxis) return a reference to the corresponding column of this...
Definition Rotation.h:1382
Rotation_< P > & updTranspose()
Definition Rotation.h:1356
const ColType & operator()(int j) const
Definition Rotation.h:1371
UnitVec< P, BaseMat::RowSpacing > ColType
Note that the unit vectors representing the rows and columns of this matrix do not necessarily have u...
Definition Rotation.h:1318
Rotation_< P > & operator~()
Definition Rotation.h:1357
SymMat< 3, P > reexpressSymMat33(const SymMat< 3, P > &S_BB) const
Assuming this InverseRotation_ is R_AB, and given a symmetric dyadic matrix S_BB expressed in B,...
BaseMat toMat33() const
Definition Rotation.h:1400
const ColType & y() const
Definition Rotation.h:1373
InverseRotation_()
You should not ever construct one of these as they should only occur as expression intermediates resu...
Definition Rotation.h:1326
Mat< 3, 3, P >::TransposeType BaseMat
This is the type of the underlying 3x3 matrix; note that it will have unusual row and column spacing ...
Definition Rotation.h:1312
const BaseMat & asMat33() const
Conversion from InverseRotation_ to BaseMat.
Definition Rotation.h:1399
InverseRotation_ & operator=(const InverseRotation_ &R)
An explicit implementation of the default copy assignment operator.
Definition Rotation.h:1331
UnitRow< P, BaseMat::ColSpacing > RowType
This is the type of a row of this InverseRotation.
Definition Rotation.h:1320
const UnitVec< P, 1 > getAxisUnitVec(CoordinateDirection dir) const
Given a CoordinateDirection (+/-XAxis, etc.) return a unit vector in that direction.
Definition Rotation.h:1389
const ColType & x() const
Definition Rotation.h:1372
const RowType & operator[](int i) const
Definition Rotation.h:1368
const Rotation_< P > & operator~() const
Definition Rotation.h:1355
const RowType & row(int i) const
Access individual rows and columns of this InverseRotation; no cost or copying since suitably-cast re...
Definition Rotation.h:1366
This class represents a small matrix whose size is known at compile time, containing elements of any ...
Definition Mat.h:100
void setToNaN()
Definition Mat.h:857
P E
Definition Mat.h:102
void set(int i, int j, const P &value)
Variant of indexing operator that's scripting friendly to set entry (i, j)
Definition Mat.h:1180
Mat & operator=(const Mat &src)
Copy assignment copies only the elements that are present and does not touch any unused memory space ...
Definition Mat.h:309
Definition NTraits.h:486
A Quaternion is a Vec4 with the following behavior:
Definition Quaternion.h:65
Vec4P convertQuaternionToAngleAxis() const
Returns [ a vx vy vz ] with (a,v) in canonical form, i.e., -180 < a <= 180 and |v|=1.
The Rotation class is a Mat33 that guarantees that the matrix can be interpreted as a legitimate 3x3 ...
Definition Rotation.h:111
Mat< 3, 2, P > Mat32P
Definition Rotation.h:115
static Mat33P calcNForBodyXYZInParentFrame(const Vec3P &q)
Given Euler angles q forming a body-fixed X-Y-Z (123) sequence return the block N_P of the system N m...
Definition Rotation.h:563
static Mat33P calcNInvForBodyXYZInParentFrame(const Vec3P &cq, const Vec3P &sq)
This faster version of calcNInvForBodyXYZInParentFrame() assumes you have already calculated the cosi...
Definition Rotation.h:717
SymMat33P reexpressSymMat33(const SymMat33P &S_BB) const
Perform an efficient transform of a symmetric matrix that must be re-expressed with a multiply from b...
static Mat33P calcNInvForBodyXYZInBodyFrame(const Vec3P &cq, const Vec3P &sq)
This faster version of calcNInvForBodyXYZInBodyFrame() assumes you have already calculated the cosine...
Definition Rotation.h:688
Rotation_ & setRotationFromAngleAboutY(RealP angle)
Set this Rotation_ object to a right-handed rotation by an angle (in radians) about the Y-axis.
Definition Rotation.h:191
Vec3P convertThreeAxesRotationToThreeAngles(BodyOrSpaceType bodyOrSpace, const CoordinateAxis &axis1, const CoordinateAxis &axis2, const CoordinateAxis &axis3) const
Converts rotation matrix to three orientation angles.
bool areAllRotationElementsSameToMachinePrecision(const Rotation_ &R) const
Returns true if each element of "this" Rotation is within machine precision of the corresponding elem...
Definition Rotation.h:1113
Rotation_ & setRotationFromTwoAnglesTwoAxes(BodyOrSpaceType bodyOrSpace, RealP angle1, const CoordinateAxis &axis1, RealP angle2, const CoordinateAxis &axis2)
Set this Rotation_ object to a two-angle, two-axes, Body-fixed or Space-fixed rotation sequences (ang...
static Vec3P convertBodyFixed321DotToAngVel(const Vec3P &q, const Vec3P &qd)
Inverse of convertAngVelToBodyFixed321Dot.
Definition Rotation.h:883
UnitRow< P, Mat33P::ColSpacing > RowType
This is the type of a row of this Rotation matrix.
Definition Rotation.h:131
InverseRotation_< P > & operator~()
Transpose operator.
Definition Rotation.h:360
Rotation_(const InverseRotation_< P > &)
Like copy constructor but for inverse rotation.
Definition Rotation.h:1433
Rotation_ & setRotationFromOneAxis(const UnitVec3P &uvec, CoordinateAxis axis)
Calculate R_AB by knowing one of B's unit vectors expressed in A.
const RowType & row(int i) const
Return a reference to the ith row of this Rotation matrix as a UnitRow3.
Definition Rotation.h:479
Rotation_ & setRotationFromAngleAboutZ(RealP angle)
Set this Rotation_ object to a right-handed rotation by an angle (in radians) about the Z-axis.
Definition Rotation.h:206
Rotation_(RealP angle, const CoordinateAxis &axis)
Constructor for right-handed rotation by an angle (in radians) about a coordinate axis.
Definition Rotation.h:161
void setRotationToBodyFixedXYZ(const Vec3P &v)
Set this Rotation_ to represent a rotation characterized by subsequent rotations of: +v[0] about the ...
Definition Rotation.h:336
SymMat< 3, P > SymMat33P
Definition Rotation.h:123
Rotation_ & setRotationFromAngleAboutY(RealP cosAngle, RealP sinAngle)
Set this Rotation_ object to a right-handed rotation by an angle about the Y-axis,...
Definition Rotation.h:195
Rotation_ & operator*=(const Rotation_< P > &R)
In-place composition of Rotation matrices.
Definition Rotation.h:1440
Rotation_ & setRotationFromAngleAboutZ(RealP cosAngle, RealP sinAngle)
Set this Rotation_ object to a right-handed rotation by an angle about the Z-axis,...
Definition Rotation.h:210
InverseRotation_< P > & updInvert()
Convert from Rotation_ to writable InverseRotation_ (no cost).
Definition Rotation.h:376
bool areAllRotationElementsSameToEpsilon(const Rotation_ &R, RealP epsilon) const
Returns true if each element of "this" Rotation is within epsilon of the corresponding element of "R"...
Definition Rotation.h:1108
static Mat43P calcUnnormalizedNDotForQuaternion(const Vec4P &qdot)
Given the time derivative qdot of a possibly unnormalized quaternion q, calculate the 4x3 matrix NDot...
Definition Rotation.h:744
Mat< 4, 3, P > Mat43P
Definition Rotation.h:117
Rotation_(RealP angle, const Vec3P &nonUnitVector)
Constructor for right-handed rotation by an angle (in radians) about an arbitrary vector of arbitrary...
Definition Rotation.h:226
static Mat33P calcNInvForBodyXYZInParentFrame(const Vec3P &q)
Inverse of the above routine.
Definition Rotation.h:704
const InverseRotation_< P > & transpose() const
Transpose.
Definition Rotation.h:365
static Vec3P multiplyByBodyXYZ_N_P(const Vec2P &cosxy, const Vec2P &sinxy, RealP oocosy, const Vec3P &w_PB)
This is the fastest way to form the product qdot=N_P*w_PB for a body-fixed XYZ sequence where angular...
Definition Rotation.h:413
P RealP
These are just local abbreviations.
Definition Rotation.h:113
Rotation_ & setRotationFromAngleAboutNonUnitVector(RealP angle, const Vec3P &nonUnitVector)
Set this Rotation_ object to a right-handed rotation of an angle (in radians) about an arbitrary vect...
Definition Rotation.h:231
static Mat33P calcNForBodyXYZInBodyFrame(const Vec3P &q)
Given Euler angles q forming a body-fixed X-Y-Z sequence return the block N_B of the system N matrix ...
Definition Rotation.h:529
static Vec3P convertAngVelDotToBodyFixed321DotDot(const Vec3P &q, const Vec3P &w_PB_B, const Vec3P &wdot_PB_B)
Caution: needs testing.
Definition Rotation.h:899
bool isSameRotationToWithinAngle(const Rotation_ &R, RealP okPointingAngleErrorRads) const
Return true if "this" Rotation is nearly identical to "R" within a specified pointing angle error.
Vec< 4, P > Vec4P
Definition Rotation.h:121
Rotation_(BodyOrSpaceType bodyOrSpace, RealP angle1, const CoordinateAxis &axis1, RealP angle2, const CoordinateAxis &axis2)
Constructor for two-angle, two-axes, Body-fixed or Space-fixed rotation sequences (angles are in radi...
Definition Rotation.h:236
const ColType & y() const
Return col(1) of this Rotation matrix as a UnitVec3.
Definition Rotation.h:494
Rotation_ & operator=(const InverseRotation_< P > &)
Like copy assignment but for inverse rotation.
Definition Rotation.h:1437
static Vec3P convertAngVelDotInBodyFrameToBodyXYZDotDot(const Vec3P &cq, const Vec3P &sq, const Vec3P &w_PB_B, const Vec3P &wdot_PB_B)
This faster version of convertAngVelDotInBodyFrameToBodyXYZDotDot() assumes you have already calculat...
Definition Rotation.h:995
const ColType & x() const
Return col(0) of this Rotation matrix as a UnitVec3.
Definition Rotation.h:492
Rotation_(BodyOrSpaceType bodyOrSpace, RealP angle1, const CoordinateAxis &axis1, RealP angle2, const CoordinateAxis &axis2, RealP angle3, const CoordinateAxis &axis3)
Constructor for three-angle Body-fixed or Space-fixed rotation sequences (angles are in radians).
Definition Rotation.h:249
const RowType & operator[](int i) const
Same as row(i) but nicer to look at.
Definition Rotation.h:482
RealP convertOneAxisRotationToOneAngle(const CoordinateAxis &axis1) const
Converts rotation matrix to a single orientation angle.
Rotation_(const QuaternionP &q)
Constructor for creating a rotation matrix from a quaternion.
Definition Rotation.h:264
Rotation_ & setRotationColFromUnitVecTrustMe(int colj, const UnitVec3P &uvecj)
(Advanced) Set the Rotation_ matrix directly - but you had better know what you are doing!
Definition Rotation.h:286
Rotation_(const UnitVec3P &uvec, CoordinateAxis axis)
Calculate R_AB by knowing one of B's unit vectors expressed in A.
Definition Rotation.h:297
Rotation_ & setRotationToIdentityMatrix()
Construct identity Rotation_.
Definition Rotation.h:156
static Mat33P calcNDotForBodyXYZInBodyFrame(const Vec3P &q, const Vec3P &qdot)
Given Euler angles forming a body-fixed X-Y-Z (123) sequence q, and their time derivatives qdot,...
Definition Rotation.h:598
const ColType & getAxisUnitVec(CoordinateAxis axis) const
Given a CoordinateAxis (XAxis,YAxis, or ZAxis) return a reference to the corresponding column of this...
Definition Rotation.h:502
const ColType & operator()(int j) const
Same as col(j) but nicer to look at.
Definition Rotation.h:489
Rotation_(RealP angle, const CoordinateAxis::YCoordinateAxis)
Constructor for right-handed rotation by an angle (in radians) about the Y-axis.
Definition Rotation.h:187
void setRotationToBodyFixedXYZ(const Vec3P &c, const Vec3P &s)
Given cosines and sines (in that order) of three angles, set this Rotation matrix to the body-fixed 1...
Definition Rotation.h:342
Vec2P convertRotationToBodyFixedXY() const
A convenient special case of convertTwoAxesRotationToTwoAngles().
Definition Rotation.h:858
static Mat33P calcNDotForBodyXYZInParentFrame(const Vec3P &q, const Vec3P &qdot)
Given Euler angles forming a body-fixed X-Y-Z (123) sequence q, and their time derivatives qdot,...
Definition Rotation.h:639
static Mat33P calcNDotForBodyXYZInParentFrame(const Vec2P &cq, const Vec2P &sq, RealP ooc1, const Vec3P &qdot)
This faster version of calcNDotForBodyXYZInParentFrame() assumes you have already calculated the cosi...
Definition Rotation.h:653
Rotation_ & operator=(const Rotation_ &R)
Assignment operator.
Definition Rotation.h:146
Rotation_ & setRotationFromAngleAboutUnitVector(RealP angle, const UnitVec3P &unitVector)
Set this Rotation_ object to a right-handed rotation of an angle (in radians) about an arbitrary unit...
const InverseRotation_< P > & invert() const
Convert from Rotation_ to InverseRotation_ (no cost).
Definition Rotation.h:373
Rotation_ & setRotationFromAngleAboutX(RealP angle)
Set this Rotation_ object to a right-handed rotation by an angle (in radians) about the X-axis.
Definition Rotation.h:176
static Vec3P multiplyByBodyXYZ_NT_P(const Vec2P &cosxy, const Vec2P &sinxy, RealP oocosy, const Vec3P &q)
This is the fastest way to form the product v_P=~N_P*q=~(~q*N_P); see the untransposed method multipl...
Definition Rotation.h:429
Mat33P toMat33() const
Conversion from Rotation to its base class Mat33.
Definition Rotation.h:779
Rotation_()
Default constructor.
Definition Rotation.h:137
InverseRotation_< P > & updTranspose()
Transpose.
Definition Rotation.h:369
Rotation_ & operator*=(const InverseRotation_< P > &)
In-place composition of Rotation matrices.
Definition Rotation.h:1446
UnitVec< P, Mat33P::RowSpacing > ColType
This is the type of a column of this Rotation matrix.
Definition Rotation.h:128
const ColType & z() const
Return col(2) of this Rotation matrix as a UnitVec3.
Definition Rotation.h:496
const InverseRotation_< P > & operator~() const
Transpose operator.
Definition Rotation.h:357
Rotation_ mirror(const CoordinateAxis &axis) const
Return this rotation mirrored about the plane normal to one of the coordinate axes.
Definition Rotation.h:386
Vec3P convertRotationToBodyFixedXYZ() const
A convenient special case of convertThreeAxesRotationToThreeAngles().
Definition Rotation.h:861
Rotation_(const Mat33P &m)
Constructs an (hopefully nearby) orthogonal rotation matrix from a generic Mat33P.
Definition Rotation.h:271
static Mat34P calcUnnormalizedNInvForQuaternion(const Vec4P &q)
Given a (possibly unnormalized) quaternion q, calculate the 3x4 matrix NInv (= N^-1) which maps quate...
Definition Rotation.h:760
Rotation_ & operator/=(const InverseRotation_< P > &)
In-place composition of Rotation matrices.
Definition Rotation.h:1449
QuaternionP convertRotationToQuaternion() const
Converts rotation matrix to an equivalent quaternion in canonical form (meaning its scalar element is...
Rotation_ & setRotationFromQuaternion(const QuaternionP &q)
Method for creating a rotation matrix from a quaternion.
Rotation_(const Rotation_ &R)
Copy constructor.
Definition Rotation.h:140
UnitVec< P, 1 > UnitVec3P
Definition Rotation.h:122
Rotation_(const Mat33P &m, bool)
(Advanced) Construct a Rotation_ directly from a Mat33P (we trust that m is a valid Rotation_!...
Definition Rotation.h:279
static Vec3P convertAngVelInBodyFrameToBodyXYZDot(const Vec3P &cq, const Vec3P &sq, const Vec3P &w_PB_B)
This faster version of convertAngVelInBodyFrameToBodyXYZDot() assumes you have already calculated the...
Definition Rotation.h:945
static Vec3P convertAngAccInParentToBodyXYZDotDot(const Vec2P &cosxy, const Vec2P &sinxy, RealP oocosy, const Vec3P &qdot, const Vec3P &b_PB)
Calculate second time derivative qdotdot of body-fixed XYZ Euler angles q given sines and cosines of ...
Definition Rotation.h:1060
static Mat33P calcNForBodyXYZInBodyFrame(const Vec3P &cq, const Vec3P &sq)
This faster version of calcNForBodyXYZInBodyFrame() assumes you have already calculated the cosine an...
Definition Rotation.h:542
static Mat33P calcNForBodyXYZInParentFrame(const Vec3P &cq, const Vec3P &sq)
This faster version of calcNForBodyXYZInParentFrame() assumes you have already calculated the cosine ...
Definition Rotation.h:577
Rotation_ & setRotationFromTwoAxes(const UnitVec3P &uveci, const CoordinateAxis &axisi, const Vec3P &vecjApprox, const CoordinateAxis &axisjApprox)
Calculate R_AB by knowing one of B's unit vectors u1 (could be Bx, By, or Bz) expressed in A and a ve...
static Vec3P convertBodyXYZDotToAngVelInBodyFrame(const Vec3P &cq, const Vec3P &sq, const Vec3P &qdot)
This faster version of convertBodyXYZDotToAngVelInBodyFrame() assumes you have already calculated the...
Definition Rotation.h:968
Rotation_(RealP angle, const CoordinateAxis::ZCoordinateAxis)
Constructor for right-handed rotation by an angle (in radians) about the Z-axis.
Definition Rotation.h:202
Rotation_ & operator/=(const Rotation_< P > &R)
In-place composition of Rotation matrices.
Definition Rotation.h:1443
const Mat33P & asMat33() const
Conversion from Rotation to its base class Mat33.
Definition Rotation.h:775
static Mat33P calcNInvForBodyXYZInBodyFrame(const Vec3P &q)
Inverse of routine calcNForBodyXYZInBodyFrame().
Definition Rotation.h:675
Rotation_(const UnitVec3P &uveci, const CoordinateAxis &axisi, const Vec3P &vecjApprox, const CoordinateAxis &axisjApprox)
Calculate R_AB by knowing one of B's unit vectors u1 (could be Bx, By, or Bz) expressed in A and a ve...
Definition Rotation.h:310
Mat< 3, 3, P > Mat33P
Definition Rotation.h:116
Rotation_ & setRotationFromApproximateMat33(const Mat33P &m)
Set this Rotation_ object to an (hopefully nearby) orthogonal rotation matrix from a generic Mat33P.
static Vec4P convertAngVelDotToQuaternionDotDot(const Vec4P &q, const Vec3P &w_PB, const Vec3P &b_PB)
We want to differentiate qdot=N(q)*w to get qdotdot=N*b+NDot*w where b is angular acceleration wdot.
Definition Rotation.h:1025
Vec2P convertTwoAxesRotationToTwoAngles(BodyOrSpaceType bodyOrSpace, const CoordinateAxis &axis1, const CoordinateAxis &axis2) const
Converts rotation matrix to two orientation angles.
static Vec3P multiplyByBodyXYZ_NInv_P(const Vec2P &cosxy, const Vec2P &sinxy, const Vec3P &qdot)
Fastest way to form the product w_PB=NInv_P*qdot.
Definition Rotation.h:444
Mat< 3, 4, P > Mat34P
Definition Rotation.h:118
static Vec3P convertAngVelInParentToBodyXYZDot(const Vec2P &cosxy, const Vec2P &sinxy, RealP oocosy, const Vec3P &w_PB)
Calculate first time derivative qdot of body-fixed XYZ Euler angles q given sines and cosines of the ...
Definition Rotation.h:1040
static Vec3P convertAngVelToBodyFixed321Dot(const Vec3P &q, const Vec3P &w_PB_B)
Given Euler angles forming a body-fixed 3-2-1 sequence, and the relative angular velocity vector of B...
Definition Rotation.h:869
static Vec3P convertQuaternionDotToAngVel(const Vec4P &q, const Vec4P &qdot)
Inverse of the above routine.
Definition Rotation.h:1014
Rotation_ & setRotationFromAngleAboutAxis(RealP angle, const CoordinateAxis &axis)
Set this Rotation_ object to a right-handed rotation by an angle (in radians) about a coordinate axis...
Definition Rotation.h:165
RealP getMaxAbsDifferenceInRotationElements(const Rotation_ &R) const
Returns maximum absolute difference between elements in "this" Rotation and elements in "R".
Definition Rotation.h:1097
Rotation_ & setRotationFromThreeAnglesThreeAxes(BodyOrSpaceType bodyOrSpace, RealP angle1, const CoordinateAxis &axis1, RealP angle2, const CoordinateAxis &axis2, RealP angle3, const CoordinateAxis &axis3)
Set this Rotation_ object to a three-angle Body-fixed or Space-fixed rotation sequences (angles are i...
Rotation_ & setRotationFromUnitVecsTrustMe(const UnitVec3P &colA, const UnitVec3P &colB, const UnitVec3P &colC)
(Advanced) Set the Rotation_ matrix directly - but you had better know what you are doing!
Definition Rotation.h:291
static Vec3P multiplyByBodyXYZ_NInvT_P(const Vec2P &cosxy, const Vec2P &sinxy, const Vec3P &v_P)
Fastest way to form the product q=~NInv_P*v_P=~(~v_P*NInv_P).
Definition Rotation.h:460
Rotation_(RealP angle, const UnitVec3P &unitVector)
Constructor for right-handed rotation by an angle (in radians) about an arbitrary unit vector.
Definition Rotation.h:217
Quaternion_< P > QuaternionP
Definition Rotation.h:124
Vec< 2, P > Vec2P
Definition Rotation.h:119
static Vec3P convertAngVelInBodyFrameToBodyXYZDot(const Vec3P &q, const Vec3P &w_PB_B)
Given Euler angles forming a body-fixed X-Y-Z (123) sequence, and the relative angular velocity vecto...
Definition Rotation.h:931
static Vec4P convertAngVelToQuaternionDot(const Vec4P &q, const Vec3P &w_PB_P)
Given a possibly unnormalized quaternion (0th element is the scalar) and the relative angular velocit...
Definition Rotation.h:1008
Rotation_(RealP angle, const CoordinateAxis::XCoordinateAxis)
Constructor for right-handed rotation by an angle (in radians) about the X-axis.
Definition Rotation.h:172
static Vec3P convertAngVelDotInBodyFrameToBodyXYZDotDot(const Vec3P &q, const Vec3P &w_PB_B, const Vec3P &wdot_PB_B)
Warning: everything is measured in the PARENT frame, but has to be expressed in the BODY frame.
Definition Rotation.h:978
Rotation_ & setRotationFromMat33TrustMe(const Mat33P &m)
(Advanced) Set the Rotation_ matrix directly - but you had better know what you are doing!
Definition Rotation.h:282
bool isSameRotationToWithinAngleOfMachinePrecision(const Rotation_ &R) const
Return true if "this" Rotation is nearly identical to "R" within machine precision.
Definition Rotation.h:1092
Rotation_ & setRotationToNaN()
Construct Rotation_ filled with NaNs.
Definition Rotation.h:152
static Mat33P calcNDotForBodyXYZInBodyFrame(const Vec3P &cq, const Vec3P &sq, const Vec3P &qdot)
This faster version of calcNDotForBodyXYZInBodyFrame() assumes you have already calculated the cosine...
Definition Rotation.h:613
void setRotationToBodyFixedXY(const Vec2P &v)
Set this Rotation_ to represent a rotation characterized by subsequent rotations of: +v[0] about the ...
Definition Rotation.h:327
Vec4P convertRotationToAngleAxis() const
Converts rotation matrix to an equivalent angle-axis representation in canonicalized form.
Definition Rotation.h:854
static Mat43P calcUnnormalizedNForQuaternion(const Vec4P &q)
Given a possibly unnormalized quaternion q, calculate the 4x3 matrix N which maps angular velocity w ...
Definition Rotation.h:730
const UnitVec< P, 1 > getAxisUnitVec(CoordinateDirection dir) const
Given a CoordinateDirection (+/-XAxis, etc.) return a unit vector in that direction.
Definition Rotation.h:509
Mat< 2, 2, P > Mat22P
Definition Rotation.h:114
const ColType & col(int j) const
Return a reference to the jth column of this Rotation matrix as a UnitVec3.
Definition Rotation.h:486
Rotation_ & setRotationFromAngleAboutX(RealP cosAngle, RealP sinAngle)
Set this Rotation_ object to a right-handed rotation by an angle about the X-axis,...
Definition Rotation.h:180
static Vec3P convertBodyXYZDotToAngVelInBodyFrame(const Vec3P &q, const Vec3P &qdot)
Inverse of the above routine.
Definition Rotation.h:954
Vec< 3, P > Vec3P
Definition Rotation.h:120
This is a small, fixed-size symmetric or Hermitian matrix designed for no-overhead inline computation...
Definition SymMat.h:87
This type is used for the transpose of UnitVec, and as the returned row type of a Rotation.
Definition UnitVec.h:211
const BaseRow & asRow3() const
Return a const reference to the Row3 underlying this UnitRow.
Definition UnitVec.h:256
This class is a Vec3 plus an ironclad guarantee either that:
Definition UnitVec.h:56
const BaseVec & asVec3() const
Return a reference to the underlying Vec3 (no copying here).
Definition UnitVec.h:117
This is a fixed-length column vector designed for no-overhead inline computation.
Definition Vec.h:186
ScalarNormSq normSqr() const
Definition Vec.h:658
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition Assembler.h:37
Rotation_< Real > Rotation
Definition Rotation.h:49
Rotation_< float > fRotation
Definition Rotation.h:50
constexpr CoordinateAxis::XCoordinateAxis XAxis
Constant representing the X coordinate axis; will implicitly convert to the integer 0 when used in a ...
Definition CoordinateAxis.h:209
BodyOrSpaceType
Definition Rotation.h:42
@ BodyRotationSequence
Definition Rotation.h:42
@ SpaceRotationSequence
Definition Rotation.h:42
Matrix_< E > operator*(const MatrixBase< E > &l, const typename CNT< E >::StdNumber &r)
Definition BigMatrix.h:605
Matrix_< E > operator/(const MatrixBase< E > &l, const typename CNT< E >::StdNumber &r)
Definition BigMatrix.h:613
InverseRotation_< double > dInverseRotation
Definition Rotation.h:55
std::ostream & operator<<(std::ostream &o, const ContactForce &f)
Definition CompliantContactSubsystem.h:387
Rotation_< double > dRotation
Definition Rotation.h:51
InverseRotation_< Real > InverseRotation
Definition Rotation.h:53
constexpr CoordinateAxis::YCoordinateAxis YAxis
Constant representing the Y coordinate axis; will implicitly convert to the integer 1 when used in a ...
Definition CoordinateAxis.h:212
InverseRotation_< float > fInverseRotation
Definition Rotation.h:54
constexpr CoordinateAxis::ZCoordinateAxis ZAxis
Constant representing the Z coordinate axis; will implicitly convert to the integer 2 when used in a ...
Definition CoordinateAxis.h:215