My Project
Loading...
Searching...
No Matches
CMatrix3d.h
Go to the documentation of this file.
1//==============================================================================
2/*
3 Software License Agreement (BSD License)
4 Copyright (c) 2003-2019, CHAI3D
5 (www.chai3d.org)
6
7 All rights reserved.
8
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions
11 are met:
12
13 * Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15
16 * Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the following
18 disclaimer in the documentation and/or other materials provided
19 with the distribution.
20
21 * Neither the name of CHAI3D nor the names of its contributors may
22 be used to endorse or promote products derived from this software
23 without specific prior written permission.
24
25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 POSSIBILITY OF SUCH DAMAGE.
37
38 \author <http://www.chai3d.org>
39 \author Francois Conti
40 \version 3.3.0
41*/
42//==============================================================================
43
44//------------------------------------------------------------------------------
45#ifndef CMatrix3dH
46#define CMatrix3dH
47//------------------------------------------------------------------------------
48#include "math/CConstants.h"
49#include "math/CVector3d.h"
50//------------------------------------------------------------------------------
51
52//------------------------------------------------------------------------------
53namespace chai3d {
54//------------------------------------------------------------------------------
55
56//------------------------------------------------------------------------------
72//------------------------------------------------------------------------------
73
74//==============================================================================
82//==============================================================================
83
84//==============================================================================
96//==============================================================================
98{
99 //--------------------------------------------------------------------------
100 // CONSTRUCTOR & DESTRUCTOR:
101 //--------------------------------------------------------------------------
102
103public:
104
105 //--------------------------------------------------------------------------
109 //--------------------------------------------------------------------------
111
112
113#ifdef C_USE_EIGEN
114 //--------------------------------------------------------------------------
120 //--------------------------------------------------------------------------
121 cMatrix3d(const Eigen::Matrix3d& a_matrix)
122 {
123 (*this)(0,0) = a_matrix(0,0);
124 (*this)(0,1) = a_matrix(0,1);
125 (*this)(0,2) = a_matrix(0,2);
126 (*this)(1,0) = a_matrix(1,0);
127 (*this)(1,1) = a_matrix(1,1);
128 (*this)(1,2) = a_matrix(1,2);
129 (*this)(2,0) = a_matrix(2,0);
130 (*this)(2,1) = a_matrix(2,1);
131 (*this)(2,2) = a_matrix(2,2);
132 }
133#endif
134
135 //--------------------------------------------------------------------------
150 //--------------------------------------------------------------------------
151 cMatrix3d(const double& a_m00, const double& a_m01, const double& a_m02,
152 const double& a_m10, const double& a_m11, const double& a_m12,
153 const double& a_m20, const double& a_m21, const double& a_m22)
154 {
155 (*this)(0,0) = a_m00; (*this)(0,1) = a_m01; (*this)(0,2) = a_m02;
156 (*this)(1,0) = a_m10; (*this)(1,1) = a_m11; (*this)(1,2) = a_m12;
157 (*this)(2,0) = a_m20; (*this)(2,1) = a_m21; (*this)(2,2) = a_m22;
158 }
159
160
161 //--------------------------------------------------------------------------
170 //--------------------------------------------------------------------------
171 cMatrix3d(const cVector3d& a_colVector0,
172 const cVector3d& a_colVector1,
173 const cVector3d& a_colVector2)
174 {
175 (*this).setCol0(a_colVector0);
176 (*this).setCol1(a_colVector1);
177 (*this).setCol2(a_colVector2);
178 }
179
180
181#ifdef C_USE_EIGEN
182 //--------------------------------------------------------------------------
191 //--------------------------------------------------------------------------
192 cMatrix3d(const Eigen::Vector3d& a_colVector0,
193 const Eigen::Vector3d& a_colVector1,
194 const Eigen::Vector3d& a_colVector2)
195 {
196 (*this)(0,0) = a_colVector0(0); (*this)(0,1) = a_colVector1(0); (*this)(0,2) = a_colVector2(0);
197 (*this)(1,0) = a_colVector0(1); (*this)(1,1) = a_colVector1(1); (*this)(1,2) = a_colVector2(1);
198 (*this)(2,0) = a_colVector0(2); (*this)(2,1) = a_colVector1(2); (*this)(2,2) = a_colVector2(2);
199 }
200#endif
201
202 //--------------------------------------------------------------------------
221 //--------------------------------------------------------------------------
222 cMatrix3d(const double& a_angle1,
223 const double& a_angle2,
224 const double& a_angle3,
225 const cEulerOrder a_eulerOrder,
226 const bool a_useIntrinsicEulerModel = true,
227 const bool a_anglesDefinedInDegrees = false)
228 {
229 if (a_anglesDefinedInDegrees)
230 {
231 if (a_useIntrinsicEulerModel)
232 {
233 setIntrinsicEulerRotationDeg(a_angle1, a_angle2, a_angle3, a_eulerOrder);
234 }
235 else
236 {
237 setExtrinsicEulerRotationDeg(a_angle1, a_angle2, a_angle3, a_eulerOrder);
238 }
239 }
240 else
241 {
242 if (a_useIntrinsicEulerModel)
243 {
244 setIntrinsicEulerRotationRad(a_angle1, a_angle2, a_angle3, a_eulerOrder);
245 }
246 else
247 {
248 setExtrinsicEulerRotationRad(a_angle1, a_angle2, a_angle3, a_eulerOrder);
249 }
250 }
251 }
252
253
254 //--------------------------------------------------------------------------
263 //--------------------------------------------------------------------------
264 cMatrix3d(const cVector3d& a_axis,
265 const double& a_angleRad)
266 {
267 setAxisAngleRotationRad(a_axis, a_angleRad);
268 }
269
270
271 //--------------------------------------------------------------------------
281 //--------------------------------------------------------------------------
282 cMatrix3d(const double& a_axisX,
283 const double& a_axisY,
284 const double& a_axisZ,
285 const double& a_angleRad)
286 {
288 a_axisY,
289 a_axisZ,
290 a_angleRad);
291 }
292
293
294#ifdef C_USE_EIGEN
295
297 Eigen::Matrix3d eigen()
298 {
299 Eigen::Matrix3d m;
300 m(0,0) = (*this)(0,0);
301 m(0,1) = (*this)(0,1);
302 m(0,2) = (*this)(0,2);
303 m(1,0) = (*this)(1,0);
304 m(1,1) = (*this)(1,1);
305 m(1,2) = (*this)(1,2);
306 m(2,0) = (*this)(2,0);
307 m(2,1) = (*this)(2,1);
308 m(2,2) = (*this)(2,2);
309 return (m);
310 }
311
312#endif
313
314
315 //--------------------------------------------------------------------------
324 //--------------------------------------------------------------------------
325 inline void identity()
326 {
327 (*this)(0,0) = 1.0; (*this)(0,1) = 0.0; (*this)(0,2) = 0.0;
328 (*this)(1,0) = 0.0; (*this)(1,1) = 1.0; (*this)(1,2) = 0.0;
329 (*this)(2,0) = 0.0; (*this)(2,1) = 0.0; (*this)(2,2) = 1.0;
330 }
331
332
333 //--------------------------------------------------------------------------
344 //--------------------------------------------------------------------------
345 inline void set(const double& a_value)
346 {
347 (*this)(0,0) = a_value; (*this)(0,1) = a_value; (*this)(0,2) = a_value;
348 (*this)(1,0) = a_value; (*this)(1,1) = a_value; (*this)(1,2) = a_value;
349 (*this)(2,0) = a_value; (*this)(2,1) = a_value; (*this)(2,2) = a_value;
350 }
351
352
353 //--------------------------------------------------------------------------
364 //--------------------------------------------------------------------------
365 inline void set(const double a_source[3][3])
366 {
367 (*this)(0,0) = a_source[0][0];
368 (*this)(0,1) = a_source[0][1];
369 (*this)(0,2) = a_source[0][2];
370 (*this)(1,0) = a_source[1][0];
371 (*this)(1,1) = a_source[1][1];
372 (*this)(1,2) = a_source[1][2];
373 (*this)(2,0) = a_source[2][0];
374 (*this)(2,1) = a_source[2][1];
375 (*this)(2,2) = a_source[2][2];
376 }
377
378
379 //--------------------------------------------------------------------------
399 //--------------------------------------------------------------------------
400 inline void set(const double& a_m00, const double& a_m01, const double& a_m02,
401 const double& a_m10, const double& a_m11, const double& a_m12,
402 const double& a_m20, const double& a_m21, const double& a_m22)
403 {
404 (*this)(0,0) = a_m00; (*this)(0,1) = a_m01; (*this)(0,2) = a_m02;
405 (*this)(1,0) = a_m10; (*this)(1,1) = a_m11; (*this)(1,2) = a_m12;
406 (*this)(2,0) = a_m20; (*this)(2,1) = a_m21; (*this)(2,2) = a_m22;
407 }
408
409
410 //--------------------------------------------------------------------------
428 //--------------------------------------------------------------------------
429 inline void setCol(const cVector3d& a_vectCol0,
430 const cVector3d& a_vectCol1,
431 const cVector3d& a_vectCol2)
432 {
433 (*this)(0,0) = a_vectCol0(0); (*this)(0,1) = a_vectCol1(0); (*this)(0,2) = a_vectCol2(0);
434 (*this)(1,0) = a_vectCol0(1); (*this)(1,1) = a_vectCol1(1); (*this)(1,2) = a_vectCol2(1);
435 (*this)(2,0) = a_vectCol0(2); (*this)(2,1) = a_vectCol1(2); (*this)(2,2) = a_vectCol2(2);
436 }
437
438
439 //--------------------------------------------------------------------------
450 //--------------------------------------------------------------------------
451 inline void setCol0(const cVector3d& a_vectCol)
452 {
453 (*this)(0,0) = a_vectCol(0);
454 (*this)(1,0) = a_vectCol(1);
455 (*this)(2,0) = a_vectCol(2);
456 }
457
458
459 //--------------------------------------------------------------------------
470 //--------------------------------------------------------------------------
471 inline void setCol1(const cVector3d& a_vectCol)
472 {
473 (*this)(0,1) = a_vectCol(0);
474 (*this)(1,1) = a_vectCol(1);
475 (*this)(2,1) = a_vectCol(2);
476 }
477
478
479 //--------------------------------------------------------------------------
490 //--------------------------------------------------------------------------
491 inline void setCol2(const cVector3d& a_vectCol)
492 {
493 (*this)(0,2) = a_vectCol(0);
494 (*this)(1,2) = a_vectCol(1);
495 (*this)(2,2) = a_vectCol(2);
496 }
497
498
499 //--------------------------------------------------------------------------
510 //--------------------------------------------------------------------------
511 inline void get(double* a_destination[])
512 {
513 *a_destination[0] = (*this)(0,0);
514 *a_destination[1] = (*this)(0,1);
515 *a_destination[2] = (*this)(0,2);
516 *a_destination[3] = (*this)(1,0);
517 *a_destination[4] = (*this)(1,1);
518 *a_destination[5] = (*this)(1,2);
519 *a_destination[6] = (*this)(2,0);
520 *a_destination[7] = (*this)(2,1);
521 *a_destination[8] = (*this)(2,2);
522 }
523
524
525 //--------------------------------------------------------------------------
535 //--------------------------------------------------------------------------
536 inline cVector3d getCol0() const
537 {
538 cVector3d result;
539 result(0) = (*this)(0,0);
540 result(1) = (*this)(1,0);
541 result(2) = (*this)(2,0);
542 return (result);
543 }
544
545
546 //--------------------------------------------------------------------------
556 //--------------------------------------------------------------------------
557 inline cVector3d getCol1() const
558 {
559 cVector3d result;
560 result(0) = (*this)(0,1);
561 result(1) = (*this)(1,1);
562 result(2) = (*this)(2,1);
563 return (result);
564 }
565
566
567 //--------------------------------------------------------------------------
577 //--------------------------------------------------------------------------
578 inline cVector3d getCol2() const
579 {
580 cVector3d result;
581 result(0) = (*this)(0,2);
582 result(1) = (*this)(1,2);
583 result(2) = (*this)(2,2);
584 return (result);
585 }
586
587
588 //--------------------------------------------------------------------------
601 //--------------------------------------------------------------------------
602 inline cVector3d getRow(const unsigned int& a_index) const
603 {
604 cVector3d result;
605 result(0) = (*this)(a_index, 0);
606 result(1) = (*this)(a_index, 1);
607 result(2) = (*this)(a_index, 2);
608 return (result);
609 }
610
611
612 //--------------------------------------------------------------------------
627 //--------------------------------------------------------------------------
628 inline void copyto(cMatrix3d& a_destination) const
629 {
630 a_destination = (*this);
631 }
632
633
634#ifdef C_USE_EIGEN
635 //--------------------------------------------------------------------------
650 //--------------------------------------------------------------------------
651 inline void copyto(Eigen::Matrix3d& a_destination) const
652 {
653 a_destination(0,0) = (*this)(0,0); a_destination(0,1) = (*this)(0,1); a_destination(0,2) = (*this)(0,2);
654 a_destination(1,0) = (*this)(1,0); a_destination(1,1) = (*this)(1,1); a_destination(1,2) = (*this)(1,2);
655 a_destination(2,0) = (*this)(2,0); a_destination(2,1) = (*this)(2,1); a_destination(2,2) = (*this)(2,2);
656 }
657#endif
658
659 //--------------------------------------------------------------------------
674 //--------------------------------------------------------------------------
675 inline void copyfrom(const cMatrix3d& a_source)
676 {
677 (*this) = a_source;
678 }
679
680
681#ifdef C_USE_EIGEN
682 //--------------------------------------------------------------------------
697 //--------------------------------------------------------------------------
698 inline void copyfrom(const Eigen::Matrix3d& a_source)
699 {
700 (*this)(0,0) = a_source(0,0); (*this)(0,1) = a_source(0,1); (*this)(0,2) = a_source(0,2);
701 (*this)(1,0) = a_source(1,0); (*this)(1,1) = a_source(1,1); (*this)(1,2) = a_source(1,2);
702 (*this)(2,0) = a_source(2,0); (*this)(2,1) = a_source(2,1); (*this)(2,2) = a_source(2,2);
703 }
704#endif
705
706
707 //--------------------------------------------------------------------------
721 //--------------------------------------------------------------------------
722 inline bool equals(cMatrix3d& a_matrix) const
723 {
724 for(int i=0; i<3; i++)
725 {
726 for(int j=0; j<3; j++)
727 {
728 if (a_matrix(i,j) != (*this)(i,j)) return (false);
729 }
730 }
731 return (true);
732 }
733
734
735 //--------------------------------------------------------------------------
751 //--------------------------------------------------------------------------
752 inline void add(const cMatrix3d& a_matrix)
753 {
754 (*this)(0,0) = (*this)(0,0) + a_matrix(0,0);
755 (*this)(0,1) = (*this)(0,1) + a_matrix(0,1);
756 (*this)(0,2) = (*this)(0,2) + a_matrix(0,2);
757 (*this)(1,0) = (*this)(1,0) + a_matrix(1,0);
758 (*this)(1,1) = (*this)(1,1) + a_matrix(1,1);
759 (*this)(1,2) = (*this)(1,2) + a_matrix(1,2);
760 (*this)(2,0) = (*this)(2,0) + a_matrix(2,0);
761 (*this)(2,1) = (*this)(2,1) + a_matrix(2,1);
762 (*this)(2,2) = (*this)(2,2) + a_matrix(2,2);
763 }
764
765
766 //--------------------------------------------------------------------------
784 //--------------------------------------------------------------------------
785 inline void addr(const cMatrix3d& a_matrix,
786 cMatrix3d& a_result) const
787 {
788 a_result(0,0) = (*this)(0,0) + a_matrix(0,0);
789 a_result(0,1) = (*this)(0,1) + a_matrix(0,1);
790 a_result(0,2) = (*this)(0,2) + a_matrix(0,2);
791 a_result(1,0) = (*this)(1,0) + a_matrix(1,0);
792 a_result(1,1) = (*this)(1,1) + a_matrix(1,1);
793 a_result(1,2) = (*this)(1,2) + a_matrix(1,2);
794 a_result(2,0) = (*this)(2,0) + a_matrix(2,0);
795 a_result(2,1) = (*this)(2,1) + a_matrix(2,1);
796 a_result(2,2) = (*this)(2,2) + a_matrix(2,2);
797 }
798
799
800 //--------------------------------------------------------------------------
816 //--------------------------------------------------------------------------
817 inline void sub(const cMatrix3d& a_matrix)
818 {
819 (*this)(0,0) = (*this)(0,0) - a_matrix(0,0);
820 (*this)(0,1) = (*this)(0,1) - a_matrix(0,1);
821 (*this)(0,2) = (*this)(0,2) - a_matrix(0,2);
822 (*this)(1,0) = (*this)(1,0) - a_matrix(1,0);
823 (*this)(1,1) = (*this)(1,1) - a_matrix(1,1);
824 (*this)(1,2) = (*this)(1,2) - a_matrix(1,2);
825 (*this)(2,0) = (*this)(2,0) - a_matrix(2,0);
826 (*this)(2,1) = (*this)(2,1) - a_matrix(2,1);
827 (*this)(2,2) = (*this)(2,2) - a_matrix(2,2);
828 }
829
830
831 //--------------------------------------------------------------------------
849 //--------------------------------------------------------------------------
850 inline void subr(const cMatrix3d& a_matrix,
851 cMatrix3d& a_result) const
852 {
853 a_result(0,0) = (*this)(0,0) - a_matrix(0,0);
854 a_result(0,1) = (*this)(0,1) - a_matrix(0,1);
855 a_result(0,2) = (*this)(0,2) - a_matrix(0,2);
856 a_result(1,0) = (*this)(1,0) - a_matrix(1,0);
857 a_result(1,1) = (*this)(1,1) - a_matrix(1,1);
858 a_result(1,2) = (*this)(1,2) - a_matrix(1,2);
859 a_result(2,0) = (*this)(2,0) - a_matrix(2,0);
860 a_result(2,1) = (*this)(2,1) - a_matrix(2,1);
861 a_result(2,2) = (*this)(2,2) - a_matrix(2,2);
862 }
863
864 //--------------------------------------------------------------------------
881 //--------------------------------------------------------------------------
882 inline void mul(const double& a_scalar)
883 {
884 // compute multiplication between matrix and scalar
885 (*this)(0, 0) = (*this)(0, 0) * a_scalar;
886 (*this)(0, 1) = (*this)(0, 1) * a_scalar;
887 (*this)(0, 2) = (*this)(0, 2) * a_scalar;
888 (*this)(1, 0) = (*this)(1, 0) * a_scalar;
889 (*this)(1, 1) = (*this)(1, 1) * a_scalar;
890 (*this)(1, 2) = (*this)(1, 2) * a_scalar;
891 (*this)(2, 0) = (*this)(2, 0) * a_scalar;
892 (*this)(2, 1) = (*this)(2, 1) * a_scalar;
893 (*this)(2, 2) = (*this)(2, 2) * a_scalar;
894 }
895
896
897 //--------------------------------------------------------------------------
915 //--------------------------------------------------------------------------
916 inline void mulr(const double& a_scalar,
917 cMatrix3d& a_result) const
918 {
919 // compute multiplication between matrix and scalar
920 a_result(0, 0) = (*this)(0, 0) * a_scalar;
921 a_result(0, 1) = (*this)(0, 1) * a_scalar;
922 a_result(0, 2) = (*this)(0, 2) * a_scalar;
923 a_result(1, 0) = (*this)(1, 0) * a_scalar;
924 a_result(1, 1) = (*this)(1, 1) * a_scalar;
925 a_result(1, 2) = (*this)(1, 2) * a_scalar;
926 a_result(2, 0) = (*this)(2, 0) * a_scalar;
927 a_result(2, 1) = (*this)(2, 1) * a_scalar;
928 a_result(2, 2) = (*this)(2, 2) * a_scalar;
929 }
930
931
932 //--------------------------------------------------------------------------
949 //--------------------------------------------------------------------------
950 inline void mul(const cMatrix3d& a_matrix)
951 {
952 // compute multiplication between both matrices
953 double m00 = (*this)(0,0) * a_matrix(0,0) + (*this)(0,1) * a_matrix(1,0) + (*this)(0,2) * a_matrix(2,0);
954 double m01 = (*this)(0,0) * a_matrix(0,1) + (*this)(0,1) * a_matrix(1,1) + (*this)(0,2) * a_matrix(2,1);
955 double m02 = (*this)(0,0) * a_matrix(0,2) + (*this)(0,1) * a_matrix(1,2) + (*this)(0,2) * a_matrix(2,2);
956 double m10 = (*this)(1,0) * a_matrix(0,0) + (*this)(1,1) * a_matrix(1,0) + (*this)(1,2) * a_matrix(2,0);
957 double m11 = (*this)(1,0) * a_matrix(0,1) + (*this)(1,1) * a_matrix(1,1) + (*this)(1,2) * a_matrix(2,1);
958 double m12 = (*this)(1,0) * a_matrix(0,2) + (*this)(1,1) * a_matrix(1,2) + (*this)(1,2) * a_matrix(2,2);
959 double m20 = (*this)(2,0) * a_matrix(0,0) + (*this)(2,1) * a_matrix(1,0) + (*this)(2,2) * a_matrix(2,0);
960 double m21 = (*this)(2,0) * a_matrix(0,1) + (*this)(2,1) * a_matrix(1,1) + (*this)(2,2) * a_matrix(2,1);
961 double m22 = (*this)(2,0) * a_matrix(0,2) + (*this)(2,1) * a_matrix(1,2) + (*this)(2,2) * a_matrix(2,2);
962
963 // return values to current matrix
964 (*this)(0,0) = m00; (*this)(0,1) = m01; (*this)(0,2) = m02;
965 (*this)(1,0) = m10; (*this)(1,1) = m11; (*this)(1,2) = m12;
966 (*this)(2,0) = m20; (*this)(2,1) = m21; (*this)(2,2) = m22;
967 }
968
969
970 //--------------------------------------------------------------------------
988 //--------------------------------------------------------------------------
989 inline void mulr(const cMatrix3d& a_matrix,
990 cMatrix3d& a_result) const
991 {
992 // compute multiplication between both matrices
993 a_result(0,0) = (*this)(0,0) * a_matrix(0,0) + (*this)(0,1) * a_matrix(1,0) + (*this)(0,2) * a_matrix(2,0);
994 a_result(0,1) = (*this)(0,0) * a_matrix(0,1) + (*this)(0,1) * a_matrix(1,1) + (*this)(0,2) * a_matrix(2,1);
995 a_result(0,2) = (*this)(0,0) * a_matrix(0,2) + (*this)(0,1) * a_matrix(1,2) + (*this)(0,2) * a_matrix(2,2);
996 a_result(1,0) = (*this)(1,0) * a_matrix(0,0) + (*this)(1,1) * a_matrix(1,0) + (*this)(1,2) * a_matrix(2,0);
997 a_result(1,1) = (*this)(1,0) * a_matrix(0,1) + (*this)(1,1) * a_matrix(1,1) + (*this)(1,2) * a_matrix(2,1);
998 a_result(1,2) = (*this)(1,0) * a_matrix(0,2) + (*this)(1,1) * a_matrix(1,2) + (*this)(1,2) * a_matrix(2,2);
999 a_result(2,0) = (*this)(2,0) * a_matrix(0,0) + (*this)(2,1) * a_matrix(1,0) + (*this)(2,2) * a_matrix(2,0);
1000 a_result(2,1) = (*this)(2,0) * a_matrix(0,1) + (*this)(2,1) * a_matrix(1,1) + (*this)(2,2) * a_matrix(2,1);
1001 a_result(2,2) = (*this)(2,0) * a_matrix(0,2) + (*this)(2,1) * a_matrix(1,2) + (*this)(2,2) * a_matrix(2,2);
1002 }
1003
1004
1005 //--------------------------------------------------------------------------
1022 //--------------------------------------------------------------------------
1023 inline void mul(cVector3d& a_vector) const
1024 {
1025 // compute multiplication
1026 double x = (*this)(0,0) * a_vector(0) + (*this)(0,1) * a_vector(1) + (*this)(0,2) * a_vector(2);
1027 double y = (*this)(1,0) * a_vector(0) + (*this)(1,1) * a_vector(1) + (*this)(1,2) * a_vector(2);
1028 double z = (*this)(2,0) * a_vector(0) + (*this)(2,1) * a_vector(1) + (*this)(2,2) * a_vector(2);
1029
1030 // store result
1031 a_vector(0) = x;
1032 a_vector(1) = y;
1033 a_vector(2) = z;
1034 }
1035
1036
1037 //--------------------------------------------------------------------------
1051 //--------------------------------------------------------------------------
1052 inline void mulr(const cVector3d& a_vector,
1053 cVector3d& a_result) const
1054 {
1055 a_result(0) = (*this)(0,0) * a_vector(0) + (*this)(0,1) * a_vector(1) + (*this)(0,2) * a_vector(2);
1056 a_result(1) = (*this)(1,0) * a_vector(0) + (*this)(1,1) * a_vector(1) + (*this)(1,2) * a_vector(2);
1057 a_result(2) = (*this)(2,0) * a_vector(0) + (*this)(2,1) * a_vector(1) + (*this)(2,2) * a_vector(2);
1058 }
1059
1060
1061 //--------------------------------------------------------------------------
1071 //--------------------------------------------------------------------------
1072 inline double det() const
1073 {
1074 return (+ (*this)(0,0) * (*this)(1,1) * (*this)(2,2)
1075 + (*this)(0,1) * (*this)(1,2) * (*this)(2,0)
1076 + (*this)(0,2) * (*this)(1,0) * (*this)(2,1)
1077 - (*this)(2,0) * (*this)(1,1) * (*this)(0,2)
1078 - (*this)(2,1) * (*this)(1,2) * (*this)(0,0)
1079 - (*this)(2,2) * (*this)(1,0) * (*this)(0,1));
1080 }
1081
1082
1083 //--------------------------------------------------------------------------
1093 //--------------------------------------------------------------------------
1094 inline void trans()
1095 {
1096 double t;
1097 t = (*this)(0,1); (*this)(0,1) = (*this)(1,0); (*this)(1,0) = t;
1098 t = (*this)(0,2); (*this)(0,2) = (*this)(2,0); (*this)(2,0) = t;
1099 t = (*this)(1,2); (*this)(1,2) = (*this)(2,1); (*this)(2,1) = t;
1100 }
1101
1102
1103 //--------------------------------------------------------------------------
1115 //--------------------------------------------------------------------------
1116 inline void transr(cMatrix3d& a_result) const
1117 {
1118 a_result(0,0) = (*this)(0,0);
1119 a_result(0,1) = (*this)(1,0);
1120 a_result(0,2) = (*this)(2,0);
1121
1122 a_result(1,0) = (*this)(0,1);
1123 a_result(1,1) = (*this)(1,1);
1124 a_result(1,2) = (*this)(2,1);
1125
1126 a_result(2,0) = (*this)(0,2);
1127 a_result(2,1) = (*this)(1,2);
1128 a_result(2,2) = (*this)(2,2);
1129 }
1130
1131
1132 //--------------------------------------------------------------------------
1143 //--------------------------------------------------------------------------
1144 bool invert()
1145 {
1146 // compute determinant
1147 double d = ( + (*this)(0,0) * (*this)(1,1) * (*this)(2,2)
1148 + (*this)(0,1) * (*this)(1,2) * (*this)(2,0)
1149 + (*this)(0,2) * (*this)(1,0) * (*this)(2,1)
1150 - (*this)(2,0) * (*this)(1,1) * (*this)(0,2)
1151 - (*this)(2,1) * (*this)(1,2) * (*this)(0,0)
1152 - (*this)(2,2) * (*this)(1,0) * (*this)(0,1));
1153
1154 // check if determinant null
1155 if ((d < C_TINY) && (d > -C_TINY))
1156 {
1157 // determinant null, matrix inversion could not be performed
1158 return (false);
1159 }
1160 else
1161 {
1162 // compute inverted matrix
1163 double m00 = ((*this)(1,1) * (*this)(2,2) - (*this)(2,1)*(*this)(1,2)) / d;
1164 double m01 = -((*this)(0,1) * (*this)(2,2) - (*this)(2,1)*(*this)(0,2)) / d;
1165 double m02 = ((*this)(0,1) * (*this)(1,2) - (*this)(1,1)*(*this)(0,2)) / d;
1166
1167 double m10 = -((*this)(1,0) * (*this)(2,2) - (*this)(2,0)*(*this)(1,2)) / d;
1168 double m11 = ((*this)(0,0) * (*this)(2,2) - (*this)(2,0)*(*this)(0,2)) / d;
1169 double m12 = -((*this)(0,0) * (*this)(1,2) - (*this)(1,0)*(*this)(0,2)) / d;
1170
1171 double m20 = ((*this)(1,0) * (*this)(2,1) - (*this)(2,0)*(*this)(1,1)) / d;
1172 double m21 = -((*this)(0,0) * (*this)(2,1) - (*this)(2,0)*(*this)(0,1)) / d;
1173 double m22 = ((*this)(0,0) * (*this)(1,1) - (*this)(1,0)*(*this)(0,1)) / d;
1174
1175 // return values to current matrix
1176 (*this)(0,0) = m00; (*this)(0,1) = m01; (*this)(0,2) = m02;
1177 (*this)(1,0) = m10; (*this)(1,1) = m11; (*this)(1,2) = m12;
1178 (*this)(2,0) = m20; (*this)(2,1) = m21; (*this)(2,2) = m22;
1179
1180 // return success
1181 return (true);
1182 }
1183 }
1184
1185
1186 //--------------------------------------------------------------------------
1198 //--------------------------------------------------------------------------
1199 bool invertr(cMatrix3d& a_result) const
1200 {
1201 // compute determinant
1202 double d = ( + (*this)(0,0) * (*this)(1,1) * (*this)(2,2)
1203 + (*this)(0,1) * (*this)(1,2) * (*this)(2,0)
1204 + (*this)(0,2) * (*this)(1,0) * (*this)(2,1)
1205 - (*this)(2,0) * (*this)(1,1) * (*this)(0,2)
1206 - (*this)(2,1) * (*this)(1,2) * (*this)(0,0)
1207 - (*this)(2,2) * (*this)(1,0) * (*this)(0,1));
1208
1209 // check if determinant null.
1210 if ((d < C_TINY) && (d > -C_TINY))
1211 {
1212 // determinant null, matrix inversion can not be performed
1213 return (false);
1214 }
1215 else
1216 {
1217 // compute inverted matrix
1218 a_result(0,0) = ((*this)(1,1) * (*this)(2,2) - (*this)(2,1)*(*this)(1,2)) / d;
1219 a_result(0,1) = -((*this)(0,1) * (*this)(2,2) - (*this)(2,1)*(*this)(0,2)) / d;
1220 a_result(0,2) = ((*this)(0,1) * (*this)(1,2) - (*this)(1,1)*(*this)(0,2)) / d;
1221
1222 a_result(1,0) = -((*this)(1,0) * (*this)(2,2) - (*this)(2,0)*(*this)(1,2)) / d;
1223 a_result(1,1) = ((*this)(0,0) * (*this)(2,2) - (*this)(2,0)*(*this)(0,2)) / d;
1224 a_result(1,2) = -((*this)(0,0) * (*this)(1,2) - (*this)(1,0)*(*this)(0,2)) / d;
1225
1226 a_result(2,0) = ((*this)(1,0) * (*this)(2,1) - (*this)(2,0)*(*this)(1,1)) / d;
1227 a_result(2,1) = -((*this)(0,0) * (*this)(2,1) - (*this)(2,0)*(*this)(0,1)) / d;
1228 a_result(2,2) = ((*this)(0,0) * (*this)(1,1) - (*this)(1,0)*(*this)(0,1)) / d;
1229
1230 // return success
1231 return (true);
1232 }
1233 }
1234
1235
1236 //--------------------------------------------------------------------------
1246 //--------------------------------------------------------------------------
1248 {
1249 cVector3d c0 = getCol0();
1250 cVector3d c1 = getCol1();
1251 cVector3d c2;
1252
1253 c0.crossr(c1, c2);
1254 c2.crossr(c0, c1);
1255
1256 c0.normalize();
1257 c1.normalize();
1258 c2.normalize();
1259
1260 (*this)(0, 0) = c0(0); (*this)(0, 1) = c1(0); (*this)(0, 2) = c2(0);
1261 (*this)(1, 0) = c0(1); (*this)(1, 1) = c1(1); (*this)(1, 2) = c2(1);
1262 (*this)(2, 0) = c0(2); (*this)(2, 1) = c1(2); (*this)(2, 2) = c2(2);
1263 }
1264
1265
1266 //--------------------------------------------------------------------------
1281 //--------------------------------------------------------------------------
1282 inline bool setAxisAngleRotationRad(const cVector3d& a_axis,
1283 const double& a_angleRad)
1284 {
1285 // compute length of axis vector
1286 double length = a_axis.length();
1287
1288 // check length of axis vector
1289 if (length < C_TINY)
1290 {
1291 // rotation matrix could not be computed because axis vector is not defined
1292 return (false);
1293 }
1294
1295 // normalize axis vector
1296 double f = 1.0 / length;
1297 double x = f * a_axis(0);
1298 double y = f * a_axis(1);
1299 double z = f * a_axis(2);
1300
1301 // compute rotation matrix
1302 double c = ::cos(a_angleRad);
1303 double s = ::sin(a_angleRad);
1304 double v = 1-c;
1305
1306 (*this)(0,0) = x*x*v+c; (*this)(0,1) = x*y*v-z*s; (*this)(0,2) = x*z*v+y*s;
1307 (*this)(1,0) = x*y*v+z*s; (*this)(1,1) = y*y*v+c; (*this)(1,2) = y*z*v-x*s;
1308 (*this)(2,0) = x*z*v-y*s; (*this)(2,1) = y*z*v+x*s; (*this)(2,2) = z*z*v+c;
1309
1310 // return success
1311 return (true);
1312 }
1313
1314
1315 //--------------------------------------------------------------------------
1330 //--------------------------------------------------------------------------
1331 inline bool setAxisAngleRotationDeg(const cVector3d& a_axis,
1332 const double& a_angleDeg)
1333 {
1334 return (setAxisAngleRotationRad(a_axis, C_DEG2RAD * (a_angleDeg)));
1335 }
1336
1337
1338 //--------------------------------------------------------------------------
1355 //--------------------------------------------------------------------------
1356 inline bool setAxisAngleRotationRad(const double& a_axisX,
1357 const double& a_axisY,
1358 const double& a_axisZ,
1359 const double& a_angleRad)
1360 {
1361 return (setAxisAngleRotationRad(cVector3d(a_axisX, a_axisY, a_axisZ), a_angleRad));
1362 }
1363
1364
1365 //--------------------------------------------------------------------------
1382 //--------------------------------------------------------------------------
1383 inline bool setAxisAngleRotationDeg(const double& a_axisX,
1384 const double& a_axisY,
1385 const double& a_axisZ,
1386 const double& a_angleDeg)
1387 {
1388 return (setAxisAngleRotationRad(cVector3d(a_axisX, a_axisY, a_axisZ), C_DEG2RAD * (a_angleDeg)));
1389 }
1390
1391
1392 //--------------------------------------------------------------------------
1407 //--------------------------------------------------------------------------
1408 inline void setExtrinsicEulerRotationRad(const double& a_angle1,
1409 const double& a_angle2,
1410 const double& a_angle3,
1411 const cEulerOrder a_eulerOrder)
1412 {
1413 switch(a_eulerOrder)
1414 {
1415 case(C_EULER_ORDER_XYZ):
1416 setIntrinsicEulerRotationRad(a_angle3, a_angle2, a_angle1, C_EULER_ORDER_ZYX);
1417 break;
1418
1419 case(C_EULER_ORDER_XYX):
1420 setIntrinsicEulerRotationRad(a_angle3, a_angle2, a_angle1, C_EULER_ORDER_XYX);
1421 break;
1422
1423 case(C_EULER_ORDER_XZY):
1424 setIntrinsicEulerRotationRad(a_angle3, a_angle2, a_angle1, C_EULER_ORDER_YZX);
1425 break;
1426
1427 case(C_EULER_ORDER_XZX):
1428 setIntrinsicEulerRotationRad(a_angle3, a_angle2, a_angle1, C_EULER_ORDER_XZX);
1429 break;
1430
1431 case(C_EULER_ORDER_YZX):
1432 setIntrinsicEulerRotationRad(a_angle3, a_angle2, a_angle1, C_EULER_ORDER_XZY);
1433 break;
1434
1435 case(C_EULER_ORDER_YZY):
1436 setIntrinsicEulerRotationRad(a_angle3, a_angle2, a_angle1, C_EULER_ORDER_YZY);
1437 break;
1438
1439 case(C_EULER_ORDER_YXZ):
1440 setIntrinsicEulerRotationRad(a_angle3, a_angle2, a_angle1, C_EULER_ORDER_ZXY);
1441 break;
1442
1443 case(C_EULER_ORDER_YXY):
1444 setIntrinsicEulerRotationRad(a_angle3, a_angle2, a_angle1, C_EULER_ORDER_YXY);
1445 break;
1446
1447 case(C_EULER_ORDER_ZXY):
1448 setIntrinsicEulerRotationRad(a_angle3, a_angle2, a_angle1, C_EULER_ORDER_YXZ);
1449 break;
1450
1451 case(C_EULER_ORDER_ZXZ):
1452 setIntrinsicEulerRotationRad(a_angle3, a_angle2, a_angle1, C_EULER_ORDER_ZXZ);
1453 break;
1454
1455 case(C_EULER_ORDER_ZYX):
1456 setIntrinsicEulerRotationRad(a_angle3, a_angle2, a_angle1, C_EULER_ORDER_XYZ);
1457 break;
1458
1459 case(C_EULER_ORDER_ZYZ):
1460 setIntrinsicEulerRotationRad(a_angle3, a_angle2, a_angle1, C_EULER_ORDER_ZYZ);
1461 break;
1462 }
1463 }
1464
1465
1466 //--------------------------------------------------------------------------
1481 //--------------------------------------------------------------------------
1482 inline void setExtrinsicEulerRotationDeg(const double& a_angle1,
1483 const double& a_angle2,
1484 const double& a_angle3,
1485 const cEulerOrder a_eulerOrder)
1486 {
1488 C_DEG2RAD * (a_angle2),
1489 C_DEG2RAD * (a_angle3),
1490 a_eulerOrder);
1491 }
1492
1493
1494 //--------------------------------------------------------------------------
1509 //--------------------------------------------------------------------------
1510 inline void setIntrinsicEulerRotationRad(const double& a_angle1,
1511 const double& a_angle2,
1512 const double& a_angle3,
1513 const cEulerOrder a_eulerOrder)
1514 {
1515 double c1 = ::cos(a_angle1);
1516 double s1 = ::sin(a_angle1);
1517 double c2 = ::cos(a_angle2);
1518 double s2 = ::sin(a_angle2);
1519 double c3 = ::cos(a_angle3);
1520 double s3 = ::sin(a_angle3);
1521
1522 switch(a_eulerOrder)
1523 {
1524 case(C_EULER_ORDER_XYZ):
1525 (*this)(0,0) = c2*c3; (*this)(0,1) =-c2*s3; (*this)(0,2) = s2;
1526 (*this)(1,0) = c1*s3+c3*s1*s2; (*this)(1,1) = c1*c3-s1*s2*s3; (*this)(1,2) =-c2*s1;
1527 (*this)(2,0) = s1*s3-c1*c3*s2; (*this)(2,1) = c3*s1+c1*s2*s3; (*this)(2,2) = c1*c2;
1528 break;
1529
1530 case(C_EULER_ORDER_XYX):
1531 (*this)(0,0) = c2; (*this)(0,1) = s2*s3; (*this)(0,2) = c3*s2;
1532 (*this)(1,0) = s1*s2; (*this)(1,1) = c1*c3-c2*s1*s3; (*this)(1,2) =-c1*s3-c2*c3*s1;
1533 (*this)(2,0) =-c1*s2; (*this)(2,1) = c3*s1+c1*c2*s3; (*this)(2,2) = c1*c2*c3-s1*s3;
1534 break;
1535
1536 case(C_EULER_ORDER_XZY):
1537 (*this)(0,0) = c2*c3; (*this)(0,1) =-s2; (*this)(0,2) = c2*s3;
1538 (*this)(1,0) = s1*s3+c1*c3*s2; (*this)(1,1) = c1*c2; (*this)(1,2) = c1*s2*s3-c3*s1;
1539 (*this)(2,0) = c3*s1*s2-c1*s3; (*this)(2,1) = c2*s1; (*this)(2,2) = c1*c3+s1*s2*s3;
1540 break;
1541
1542 case(C_EULER_ORDER_XZX):
1543 (*this)(0,0) = c2; (*this)(0,1) =-c3*s2; (*this)(0,2) = s2*s3;
1544 (*this)(1,0) = c1*s2; (*this)(1,1) = c1*c2*c3-s1*s3; (*this)(1,2) =-c3*s1-c1*c2*s3;
1545 (*this)(2,0) = s1*s2; (*this)(2,1) = c1*s3+c2*c3*s1; (*this)(2,2) = c1*c3-c2*s1*s3;
1546 break;
1547
1548 case(C_EULER_ORDER_YZX):
1549 (*this)(0,0) = c1*c2; (*this)(0,1) = s1*s3-c1*c3*s2; (*this)(0,2) = c3*s1+c1*s2*s3;
1550 (*this)(1,0) = s2; (*this)(1,1) = c2*c3; (*this)(1,2) =-c2*s3;
1551 (*this)(2,0) =-c2*s1; (*this)(2,1) = c1*s3+c3*s1*s2; (*this)(2,2) = c1*c3-s1*s2*s3;
1552 break;
1553
1554 case(C_EULER_ORDER_YZY):
1555 (*this)(0,0) = c1*c2*c3-s1*s3; (*this)(0,1) =-c1*s2; (*this)(0,2) = c3*s1+c1*c2*s3;
1556 (*this)(1,0) = c3*s2; (*this)(1,1) = c2; (*this)(1,2) = s2*s3;
1557 (*this)(2,0) =-c1*s3-c2*c3*s1; (*this)(2,1) = s1*s2; (*this)(2,2) = c1*c3-c2*s1*s3;
1558 break;
1559
1560 case(C_EULER_ORDER_YXZ):
1561 (*this)(0,0) = c1*c3+s1*s2*s3; (*this)(0,1) = c3*s1*s2-c1*s3; (*this)(0,2) = c2*s1;
1562 (*this)(1,0) = c2*s3; (*this)(1,1) = c2*c3; (*this)(1,2) =-s2;
1563 (*this)(2, 0) = c1*s2*s3 - c3*s1; (*this)(2, 1) = s1*s3 + c1*c3*s2; (*this)(2, 2) = c1*c2;
1564 break;
1565
1566 case(C_EULER_ORDER_YXY):
1567 (*this)(0,0) = c1*c3-c2*s1*s3; (*this)(0,1) = s1*s2; (*this)(0,2) = c1*s3+c2*c3*s1;
1568 (*this)(1,0) = s2*s3; (*this)(1,1) = c2; (*this)(1,2) =-c3*s2;
1569 (*this)(2,0) =-c3*s1-c1*c2*s3; (*this)(2,1) = c1*s2; (*this)(2,2) = c1*c2*c3-s1*s3;
1570 break;
1571
1572 case(C_EULER_ORDER_ZXY):
1573 (*this)(0,0) = c1*c3-s1*s2*s3; (*this)(0,1) =-c2*s1; (*this)(0,2) = c1*s3+c3*s1*s2;
1574 (*this)(1,0) = c3*s1+c1*s2*s3; (*this)(1,1) = c1*c2; (*this)(1,2) = s1*s3-c1*c3*s2;
1575 (*this)(2,0) =-c2*s3; (*this)(2,1) = s2; (*this)(2,2) = c2*c3;
1576 break;
1577
1578 case(C_EULER_ORDER_ZXZ):
1579 (*this)(0,0) = c1*c3-c2*s1*s3; (*this)(0,1) =-c1*s3-c2*c3*s1; (*this)(0,2) = s1*s2;
1580 (*this)(1,0) = c3*s1+c1*c2*s3; (*this)(1,1) = c1*c2*c3-s1*s3; (*this)(1,2) =-c1*s2;
1581 (*this)(2,0) = s2*s3; (*this)(2,1) = c3*s2; (*this)(2,2) = c2;
1582 break;
1583
1584 case(C_EULER_ORDER_ZYX):
1585 (*this)(0,0) = c1*c2; (*this)(0,1) = c1*s2*s3-c3*s1; (*this)(0,2) = s1*s3+c1*c3*s2;
1586 (*this)(1,0) = c2*s1; (*this)(1,1) = c1*c3+s1*s2*s3; (*this)(1,2) = c3*s1*s2-c1*s3;
1587 (*this)(2,0) =-s2; (*this)(2,1) = c2*s3; (*this)(2,2) = c2*c3;
1588 break;
1589
1590 case(C_EULER_ORDER_ZYZ):
1591 (*this)(0,0) = c1*c2*c3-s1*s3; (*this)(0,1) =-c3*s1-c1*c2*s3; (*this)(0,2) = c1*s2;
1592 (*this)(1,0) = c1*s3+c2*c3*s1; (*this)(1,1) = c1*c3-c2*s1*s3; (*this)(1,2) = s1*s2;
1593 (*this)(2,0) =-c3*s2; (*this)(2,1) = s2*s3; (*this)(2,2) = c2;
1594 break;
1595 }
1596 }
1597
1598
1599 //--------------------------------------------------------------------------
1614 //--------------------------------------------------------------------------
1615 inline void setIntrinsicEulerRotationDeg(const double& a_angle1,
1616 const double& a_angle2,
1617 const double& a_angle3,
1618 const cEulerOrder a_eulerOrder)
1619 {
1621 C_DEG2RAD * (a_angle2),
1622 C_DEG2RAD * (a_angle3),
1623 a_eulerOrder);
1624 }
1625
1626
1627 //--------------------------------------------------------------------------
1644 //--------------------------------------------------------------------------
1645 inline bool getExtrinsicEulerAnglesRad(cVector3d& a_eulerAngles1,
1646 cVector3d& a_eulerAngles2,
1647 const cEulerOrder a_eulerOrder)
1648 {
1649 switch(a_eulerOrder)
1650 {
1651 case(C_EULER_ORDER_XYZ):
1652 return getIntrinsicEulerAnglesRad(a_eulerAngles1, a_eulerAngles2, C_EULER_ORDER_ZYX);
1653 break;
1654
1655 case(C_EULER_ORDER_XYX):
1656 return getIntrinsicEulerAnglesRad(a_eulerAngles1, a_eulerAngles2, C_EULER_ORDER_XYX);
1657 break;
1658
1659 case(C_EULER_ORDER_XZY):
1660 return getIntrinsicEulerAnglesRad(a_eulerAngles1, a_eulerAngles2, C_EULER_ORDER_YZX);
1661 break;
1662
1663 case(C_EULER_ORDER_XZX):
1664 return getIntrinsicEulerAnglesRad(a_eulerAngles1, a_eulerAngles2, C_EULER_ORDER_XZX);
1665 break;
1666
1667 case(C_EULER_ORDER_YZX):
1668 return getIntrinsicEulerAnglesRad(a_eulerAngles1, a_eulerAngles2, C_EULER_ORDER_XZY);
1669 break;
1670
1671 case(C_EULER_ORDER_YZY):
1672 return getIntrinsicEulerAnglesRad(a_eulerAngles1, a_eulerAngles2, C_EULER_ORDER_YZY);
1673 break;
1674
1675 case(C_EULER_ORDER_YXZ):
1676 return getIntrinsicEulerAnglesRad(a_eulerAngles1, a_eulerAngles2, C_EULER_ORDER_ZXY);
1677 break;
1678
1679 case(C_EULER_ORDER_YXY):
1680 return getIntrinsicEulerAnglesRad(a_eulerAngles1, a_eulerAngles2, C_EULER_ORDER_YXY);
1681 break;
1682
1683 case(C_EULER_ORDER_ZXY):
1684 return getIntrinsicEulerAnglesRad(a_eulerAngles1, a_eulerAngles2, C_EULER_ORDER_YXZ);
1685 break;
1686
1687 case(C_EULER_ORDER_ZXZ):
1688 return getIntrinsicEulerAnglesRad(a_eulerAngles1, a_eulerAngles2, C_EULER_ORDER_ZXZ);
1689 break;
1690
1691 case(C_EULER_ORDER_ZYX):
1692 return getIntrinsicEulerAnglesRad(a_eulerAngles1, a_eulerAngles2, C_EULER_ORDER_XYZ);
1693 break;
1694
1695 case(C_EULER_ORDER_ZYZ):
1696 return getIntrinsicEulerAnglesRad(a_eulerAngles1, a_eulerAngles2, C_EULER_ORDER_ZYZ);
1697 break;
1698
1699 default:
1700 return false;
1701 }
1702 }
1703
1704
1705 //--------------------------------------------------------------------------
1722 //--------------------------------------------------------------------------
1723 inline bool getExtrinsicEulerAnglesDeg(cVector3d& a_eulerAngles1,
1724 cVector3d& a_eulerAngles2,
1725 const cEulerOrder a_eulerOrder)
1726 {
1727 cVector3d eulerAngles1, eulerAngles2;
1728 bool locked = getExtrinsicEulerAnglesRad(eulerAngles1,
1729 eulerAngles2,
1730 a_eulerOrder);
1731
1732 // convert angles from radians to degrees
1733 a_eulerAngles1(0) = C_RAD2DEG * eulerAngles1(0);
1734 a_eulerAngles1(1) = C_RAD2DEG * eulerAngles1(1);
1735 a_eulerAngles1(2) = C_RAD2DEG * eulerAngles1(2);
1736
1737 a_eulerAngles2(0) = C_RAD2DEG * eulerAngles2(0);
1738 a_eulerAngles2(1) = C_RAD2DEG * eulerAngles2(1);
1739 a_eulerAngles2(2) = C_RAD2DEG * eulerAngles2(2);
1740
1741 return locked;
1742 }
1743
1744
1745 //--------------------------------------------------------------------------
1762 //--------------------------------------------------------------------------
1763 inline bool getIntrinsicEulerAnglesRad(cVector3d& a_eulerAngles1,
1764 cVector3d& a_eulerAngles2,
1765 const cEulerOrder a_eulerOrder)
1766 {
1767 double Rs;
1768 double Rc1c2;
1769 double Rc2s1;
1770 double Rc2s3;
1771 double Rc2c3;
1772 double Rc1s2s3c3s1;
1773 double Rs1s3c1c3s2;
1774
1775 bool locked = false;
1776 bool flagUseSin = false;
1777 double sign = 1.0;
1778
1779 switch(a_eulerOrder)
1780 {
1781
1782 case(C_EULER_ORDER_XYZ):
1783 /*
1784 (*this)(0,0) = c2*c3; (*this)(0,1) =-c2*s3; (*this)(0,2) = s2;
1785 (*this)(1,0) = c1*s3+c3*s1*s2; (*this)(1,1) = c1*c3-s1*s2*s3; (*this)(1,2) =-c2*s1;
1786 (*this)(2,0) = s1*s3-c1*c3*s2; (*this)(2,1) = c3*s1+c1*s2*s3; (*this)(2,2) = c1*c2;
1787 */
1788 {
1789 Rs = (*this)(0,2);
1790 Rc1c2 = (*this)(2, 2);
1791 Rc2s1 = (*this)(1, 2);
1792 Rc2s3 = (*this)(0, 1);
1793 Rc2c3 = (*this)(0, 0);
1794 Rc1s2s3c3s1 = (*this)(2, 1);
1795 Rs1s3c1c3s2 = (*this)(2, 0);
1796 flagUseSin = true;
1797 sign = 1.0;
1798 break;
1799 }
1800
1801 case(C_EULER_ORDER_XYX):
1802 /*
1803 (*this)(0,0) = c2; (*this)(0,1) = s2*s3; (*this)(0,2) = c3*s2;
1804 (*this)(1,0) = s1*s2; (*this)(1,1) = c1*c3-c2*s1*s3; (*this)(1,2) =-c1*s3-c2*c3*s1;
1805 (*this)(2,0) =-c1*s2; (*this)(2,1) = c3*s1+c1*c2*s3; (*this)(2,2) = c1*c2*c3-s1*s3;
1806 */
1807 break;
1808
1809 case(C_EULER_ORDER_XZY):
1810 /*
1811 (*this)(0,0) = c2*c3; (*this)(0,1) =-s2; (*this)(0,2) = c2*s3;
1812 (*this)(1,0) = s1*s3+c1*c3*s2; (*this)(1,1) = c1*c2; (*this)(1,2) = c1*s2*s3-c3*s1;
1813 (*this)(2,0) = c3*s1*s2-c1*s3; (*this)(2,1) = c2*s1; (*this)(2,2) = c1*c3+s1*s2*s3;
1814 */
1815 {
1816 Rs = (*this)(0,1);
1817 Rc1c2 = (*this)(1, 1);
1818 Rc2s1 = (*this)(2, 1);
1819 Rc2s3 = (*this)(0, 2);
1820 Rc2c3 = (*this)(0, 0);
1821 Rc1s2s3c3s1 = (*this)(1, 2);
1822 Rs1s3c1c3s2 = (*this)(1, 0);
1823 flagUseSin = true;
1824 sign =-1.0;
1825 break;
1826 }
1827
1828 case(C_EULER_ORDER_XZX):
1829 /*
1830 (*this)(0,0) = c2; (*this)(0,1) =-c3*s2; (*this)(0,2) = s2*s3;
1831 (*this)(1,0) = c1*s2; (*this)(1,1) = c1*c2*c3-s1*s3; (*this)(1,2) =-c3*s1-c1*c2*s3;
1832 (*this)(2,0) = s1*s2; (*this)(2,1) = c1*s3+c2*c3*s1; (*this)(2,2) = c1*c3-c2*s1*s3;
1833 */
1834 break;
1835
1836 case(C_EULER_ORDER_YZX):
1837 /*
1838 (*this)(0,0) = c1*c2; (*this)(0,1) = s1*s3-c1*c3*s2; (*this)(0,2) = c3*s1+c1*s2*s3;
1839 (*this)(1,0) = s2; (*this)(1,1) = c2*c3; (*this)(1,2) =-c2*s3;
1840 (*this)(2,0) =-c2*s1; (*this)(2,1) = c1*s3+c3*s1*s2; (*this)(2,2) = c1*c3-s1*s2*s3;
1841 */
1842 {
1843 Rs = (*this)(1,0);
1844 Rc1c2 = (*this)(0, 0);
1845 Rc2s1 = (*this)(2, 0);
1846 Rc2s3 = (*this)(1, 2);
1847 Rc2c3 = (*this)(1, 1);
1848 Rc1s2s3c3s1 = (*this)(0, 2);
1849 Rs1s3c1c3s2 = (*this)(0, 1);
1850 flagUseSin = true;
1851 sign = 1.0;
1852 break;
1853 }
1854
1855
1856 case(C_EULER_ORDER_YZY):
1857 /*
1858 (*this)(0,0) = c1*c2*c3-s1*s3; (*this)(0,1) =-c1*s2; (*this)(0,2) = c3*s1+c1*c2*s3;
1859 (*this)(1,0) = c3*s2; (*this)(1,1) = c2; (*this)(1,2) = s2*s3;
1860 (*this)(2,0) =-c1*s3-c2*c3*s1; (*this)(2,1) = s1*s2; (*this)(2,2) = c1*c3-c2*s1*s3;
1861 */
1862 break;
1863
1864 case(C_EULER_ORDER_YXZ):
1865 /*
1866 (*this)(0,0) = c1*c3+s1*s2*s3; (*this)(0,1) = c3*s1*s2-c1*s3; (*this)(0,2) = c2*s1;
1867 (*this)(1,0) = c2*s3; (*this)(1,1) = c2*c3; (*this)(1,2) =-s2;
1868 (*this)(2,0) = c1*s2*s3-c3*s1; (*this)(2,1) = s1*s3+c1*c3*s2; (*this)(2,2) = c1*c2
1869 */
1870 {
1871 Rs = (*this)(1,2);
1872 Rc1c2 = (*this)(2, 2);
1873 Rc2s1 = (*this)(0, 2);
1874 Rc2s3 = (*this)(1, 0);
1875 Rc2c3 = (*this)(1, 1);
1876 Rc1s2s3c3s1 = (*this)(2, 0);
1877 Rs1s3c1c3s2 = (*this)(2, 1);
1878 flagUseSin = true;
1879 sign =-1.0;
1880 break;
1881 }
1882
1883 case(C_EULER_ORDER_YXY):
1884 /*
1885 (*this)(0,0) = c1*c3-c2*s1*s3; (*this)(0,1) = s1*s2; (*this)(0,2) = c1*s3+c2*c3*s1;
1886 (*this)(1,0) = s2*s3; (*this)(1,1) = c2; (*this)(1,2) =-c3*s2;
1887 (*this)(2,0) =-c3*s1-c1*c2*s3; (*this)(2,1) = c1*s2; (*this)(2,2) = c1*c2*c3-s1*s3;
1888 */
1889 break;
1890
1891 case(C_EULER_ORDER_ZXY):
1892 /*
1893 (*this)(0,0) = c1*c3-s1*s2*s3; (*this)(0,1) =-c2*s1; (*this)(0,2) = c1*s3+c3*s1*s2;
1894 (*this)(1,0) = c3*s1+c1*s2*s3; (*this)(1,1) = c1*c2; (*this)(1,2) = s1*s3-c1*c3*s2;
1895 (*this)(2,0) =-c2*s3; (*this)(2,1) = s2; (*this)(2,2) = c2*c3;
1896 */
1897 {
1898 Rs = (*this)(2,1);
1899 Rc1c2 = (*this)(1, 1);
1900 Rc2s1 = (*this)(0, 1);
1901 Rc2s3 = (*this)(2, 0);
1902 Rc2c3 = (*this)(2, 2);
1903 Rc1s2s3c3s1 = (*this)(1, 0);
1904 Rs1s3c1c3s2 = (*this)(1, 2);
1905 flagUseSin = true;
1906 sign = 1.0;
1907 break;
1908 }
1909
1910 case(C_EULER_ORDER_ZXZ):
1911 /*
1912 (*this)(0,0) = c1*c3-c2*s1*s3; (*this)(0,1) =-c1*s3-c2*c3*s1; (*this)(0,2) = s1*s2;
1913 (*this)(1,0) = c3*s1+c1*c2*s3; (*this)(1,1) = c1*c2*c3-s1*s3; (*this)(1,2) =-c1*s2;
1914 (*this)(2,0) = s2*s3; (*this)(2,1) = c3*s2; (*this)(2,2) = c2;
1915 */
1916 break;
1917
1918 case(C_EULER_ORDER_ZYX):
1919 /*
1920 (*this)(0,0) = c1*c2; (*this)(0,1) = c1*s2*s3-c3*s1; (*this)(0,2) = s1*s3+c1*c3*s2;
1921 (*this)(1,0) = c2*s1; (*this)(1,1) = c1*c3+s1*s2*s3; (*this)(1,2) = c3*s1*s2-c1*s3;
1922 (*this)(2,0) =-s2; (*this)(2,1) = c2*s3; (*this)(2,2) = c2*c3;
1923 */
1924 {
1925 Rs = (*this)(2,0);
1926 Rc1c2 = (*this)(0, 0);
1927 Rc2s1 = (*this)(1, 0);
1928 Rc2s3 = (*this)(2, 1);
1929 Rc2c3 = (*this)(2, 2);
1930 Rc1s2s3c3s1 = (*this)(0, 1);
1931 Rs1s3c1c3s2 = (*this)(0, 2);
1932 flagUseSin = true;
1933 sign =-1.0;
1934 break;
1935 }
1936
1937 case(C_EULER_ORDER_ZYZ):
1938 /*
1939 (*this)(0,0) = c1*c2*c3-s1*s3; (*this)(0,1) =-c3*s1-c1*c2*s3; (*this)(0,2) = c1*s2;
1940 (*this)(1,0) = c1*s3+c2*c3*s1; (*this)(1,1) = c1*c3-c2*s1*s3; (*this)(1,2) = s1*s2;
1941 (*this)(2,0) =-c3*s2; (*this)(2,1) = s2*s3; (*this)(2,2) = c2;
1942 */
1943 break;
1944 }
1945
1946
1947 if (flagUseSin)
1948 {
1949 if ((Rs != 1.0) && (Rs != -1.0))
1950 {
1951 a_eulerAngles1(1) = sign * asin(Rs);
1952 a_eulerAngles2(1) = C_PI - a_eulerAngles1(1);
1953
1954 double cosAng1 = cos(a_eulerAngles1(1));
1955 double cosAng2 = cos(a_eulerAngles2(1));
1956
1957 a_eulerAngles1(0) = -sign * atan2(Rc2s1 / cosAng1, Rc1c2 / cosAng1);
1958 a_eulerAngles2(0) = -sign * atan2(Rc2s1 / cosAng2, Rc1c2 / cosAng2);
1959 a_eulerAngles1(2) = -sign * atan2(Rc2s3 / cosAng1, Rc2c3 / cosAng1);
1960 a_eulerAngles2(2) = -sign * atan2(Rc2s3 / cosAng2, Rc2c3 / cosAng2);
1961 }
1962 else
1963 {
1964 locked = true;
1965 a_eulerAngles1(0) = 0.0;
1966 a_eulerAngles2(0) = 0.0;
1967
1968 if (Rs > 0)
1969 {
1970 a_eulerAngles1(1) = sign * C_PI_DIV_2;
1971 a_eulerAngles2(1) = sign * C_PI_DIV_2;
1972 double value = atan2(-Rc1s2s3c3s1,-Rs1s3c1c3s2);
1973 a_eulerAngles1(2) =-sign * (a_eulerAngles1(0) + value);
1974 a_eulerAngles2(2) =-sign * (a_eulerAngles2(0) + value);
1975 }
1976 else
1977 {
1978 a_eulerAngles1(1) = sign * (-C_PI_DIV_2);
1979 a_eulerAngles2(1) = sign * (-C_PI_DIV_2);
1980 double value = atan2(Rc1s2s3c3s1, Rs1s3c1c3s2);
1981 a_eulerAngles1(2) =-sign * (a_eulerAngles1(0) + value);
1982 a_eulerAngles2(2) =-sign * (a_eulerAngles2(0) + value);
1983 }
1984 }
1985 }
1986
1987 return locked;
1988 }
1989
1990
1991 //--------------------------------------------------------------------------
2008 //--------------------------------------------------------------------------
2009 inline bool getIntrinsicEulerAnglesDeg(cVector3d& a_eulerAngles1,
2010 cVector3d& a_eulerAngles2,
2011 const cEulerOrder a_eulerOrder)
2012
2013 {
2014 cVector3d eulerAngles1, eulerAngles2;
2015 bool locked = getIntrinsicEulerAnglesRad(eulerAngles1,
2016 eulerAngles2,
2017 a_eulerOrder);
2018
2019 // convert angles from radians to degrees
2020 a_eulerAngles1(0) = C_RAD2DEG * eulerAngles1(0);
2021 a_eulerAngles1(1) = C_RAD2DEG * eulerAngles1(1);
2022 a_eulerAngles1(2) = C_RAD2DEG * eulerAngles1(2);
2023
2024 a_eulerAngles2(0) = C_RAD2DEG * eulerAngles2(0);
2025 a_eulerAngles2(1) = C_RAD2DEG * eulerAngles2(1);
2026 a_eulerAngles2(2) = C_RAD2DEG * eulerAngles2(2);
2027
2028 return locked;
2029 }
2030
2031
2032 //--------------------------------------------------------------------------
2047 //--------------------------------------------------------------------------
2048 inline bool rotateAboutGlobalAxisRad(const cVector3d& a_axis,
2049 const double& a_angleRad)
2050 {
2051 // compute length of axis vector
2052 double length = a_axis.length();
2053
2054 // check length of axis vector
2055 if (length < C_TINY)
2056 {
2057 // rotation matrix could not be computed because axis vector is not defined
2058 return (false);
2059 }
2060
2061 // normalize axis vector
2062 double f = 1.0 / length;
2063 double x = f * a_axis(0);
2064 double y = f * a_axis(1);
2065 double z = f * a_axis(2);
2066
2067 // compute rotation matrix
2068 double c = ::cos(a_angleRad);
2069 double s = ::sin(a_angleRad);
2070 double v = 1-c;
2071
2072 cMatrix3d m;
2073 m(0,0) = x*x*v+c; m(0,1) = x*y*v-z*s; m(0,2) = x*z*v+y*s;
2074 m(1,0) = x*y*v+z*s; m(1,1) = y*y*v+c; m(1,2) = y*z*v-x*s;
2075 m(2,0) = x*z*v-y*s; m(2,1) = y*z*v+x*s; m(2,2) = z*z*v+c;
2076
2077 (*this) = m*(*this);
2078
2079 // return success
2080 return (true);
2081 }
2082
2083
2084 //--------------------------------------------------------------------------
2099 //--------------------------------------------------------------------------
2100 inline bool rotateAboutGlobalAxisDeg(const cVector3d& a_axis,
2101 const double& a_angleDeg)
2102 {
2103 return (rotateAboutGlobalAxisRad(a_axis, C_DEG2RAD * (a_angleDeg)));
2104 }
2105
2106
2107 //--------------------------------------------------------------------------
2124 //--------------------------------------------------------------------------
2125 inline bool rotateAboutGlobalAxisRad(const double& a_axisX,
2126 const double& a_axisY,
2127 const double& a_axisZ,
2128 const double& a_angleRad)
2129 {
2130 return(rotateAboutGlobalAxisRad(cVector3d(a_axisX, a_axisY, a_axisZ), a_angleRad));
2131 }
2132
2133
2134 //--------------------------------------------------------------------------
2151 //--------------------------------------------------------------------------
2152 inline bool rotateAboutGlobalAxisDeg(const double& a_axisX,
2153 const double& a_axisY,
2154 const double& a_axisZ,
2155 const double& a_angleDeg)
2156 {
2157 return(rotateAboutGlobalAxisRad(cVector3d(a_axisX, a_axisY, a_axisZ), C_DEG2RAD * (a_angleDeg)));
2158 }
2159
2160
2161 //--------------------------------------------------------------------------
2176 //--------------------------------------------------------------------------
2177 inline bool rotateAboutLocalAxisRad(const cVector3d& a_axis,
2178 const double& a_angleRad)
2179 {
2180 // compute length of axis vector
2181 double length = a_axis.length();
2182
2183 // check length of axis vector
2184 if (length < C_TINY)
2185 {
2186 // rotation matrix could not be computed because axis vector is not defined
2187 return (false);
2188 }
2189
2190 // normalize axis vector
2191 double f = 1.0 / length;
2192 double x = f * a_axis(0);
2193 double y = f * a_axis(1);
2194 double z = f * a_axis(2);
2195
2196 // compute rotation matrix
2197 double c = ::cos(a_angleRad);
2198 double s = ::sin(a_angleRad);
2199 double v = 1-c;
2200
2201 cMatrix3d m;
2202 m(0,0) = x*x*v+c; m(0,1) = x*y*v-z*s; m(0,2) = x*z*v+y*s;
2203 m(1,0) = x*y*v+z*s; m(1,1) = y*y*v+c; m(1,2) = y*z*v-x*s;
2204 m(2,0) = x*z*v-y*s; m(2,1) = y*z*v+x*s; m(2,2) = z*z*v+c;
2205
2206 (*this) = (*this)*m;
2207
2208 // return success
2209 return (true);
2210 }
2211
2212
2213 //--------------------------------------------------------------------------
2228 //--------------------------------------------------------------------------
2229 inline bool rotateAboutLocalAxisDeg(const cVector3d& a_axis,
2230 const double& a_angleDeg)
2231 {
2232 return(rotateAboutLocalAxisRad(a_axis, C_DEG2RAD * (a_angleDeg)));
2233 }
2234
2235
2236 //--------------------------------------------------------------------------
2253 //--------------------------------------------------------------------------
2254 inline bool rotateAboutLocalAxisRad(const double& a_axisX,
2255 const double& a_axisY,
2256 const double& a_axisZ,
2257 const double& a_angleRad)
2258 {
2259 return(rotateAboutLocalAxisRad(cVector3d(a_axisX, a_axisY, a_axisZ), a_angleRad));
2260 }
2261
2262
2263 //--------------------------------------------------------------------------
2280 //--------------------------------------------------------------------------
2281 inline bool rotateAboutLocalAxisDeg(const double& a_axisX,
2282 const double& a_axisY,
2283 const double& a_axisZ,
2284 const double& a_angleDeg)
2285 {
2286 return(rotateAboutLocalAxisRad(cVector3d(a_axisX, a_axisY, a_axisZ), C_DEG2RAD * (a_angleDeg)));
2287 }
2288
2289
2290 //--------------------------------------------------------------------------
2305 //--------------------------------------------------------------------------
2306 bool toAxisAngle(cVector3d& a_axis,
2307 double& a_angle) const
2308 {
2309 double angle,x,y,z; // variables for result
2310 double epsilon1 = 0.01; // margin to allow for rounding errors
2311 double epsilon2 = 0.1; // margin to distinguish between 0 and 180 degrees
2312
2313 if ((fabs((*this)(0,1) - (*this)(1,0)) < epsilon1) &&
2314 (fabs((*this)(0,2) - (*this)(2,0)) < epsilon1) &&
2315 (fabs((*this)(1,2) - (*this)(2,1)) < epsilon1))
2316 {
2317 // singularity found
2318 // first check for identity matrix which must have +1 for all terms
2319 // in leading diagonal and zero in other terms
2320 if ( (fabs((*this)(0,1) + (*this)(1,0)) < epsilon2) &&
2321 (fabs((*this)(0,2) + (*this)(2,0)) < epsilon2) &&
2322 (fabs((*this)(1,2) + (*this)(2,1)) < epsilon2) &&
2323 (fabs((*this)(0,0) + (*this)(1,1) + (*this)(2,2)-3) < epsilon2))
2324 {
2325 // this singularity is identity matrix so angle = 0
2326 a_axis.set(1,0,0);
2327 a_angle = 0;
2328 return (true);
2329 }
2330
2331 // otherwise this singularity is angle = 180
2332 angle = C_PI;
2333 double xx = ((*this)(0,0)+1)/2;
2334 double yy = ((*this)(1,1)+1)/2;
2335 double zz = ((*this)(2,2)+1)/2;
2336 double xy = ((*this)(0,1)+(*this)(1,0))/4;
2337 double xz = ((*this)(0,2)+(*this)(2,0))/4;
2338 double yz = ((*this)(1,2)+(*this)(2,1))/4;
2339
2340 if ((xx > yy) && (xx > zz))
2341 {
2342 // (*this)(0,0) is the largest diagonal term
2343 if (xx < epsilon1)
2344 {
2345 x = 0;
2346 y = 0.7071;
2347 z = 0.7071;
2348 }
2349 else
2350 {
2351 x = sqrt(xx);
2352 y = xy/x;
2353 z = xz/x;
2354 }
2355 }
2356 else if (yy > zz)
2357 {
2358 // (*this)(1,1) is the largest diagonal term
2359 if (yy< epsilon1)
2360 {
2361 x = 0.7071067811865475;
2362 y = 0.0;
2363 z = 0.7071067811865475;
2364 }
2365 else
2366 {
2367 y = sqrt(yy);
2368 x = xy/y;
2369 z = yz/y;
2370 }
2371 }
2372 else
2373 {
2374 // (*this)(2,2) is the largest diagonal term so base result on this
2375 if (zz < epsilon1)
2376 {
2377 x = 0.7071067811865475;
2378 y = 0.7071067811865475;
2379 z = 0.0;
2380 }
2381 else
2382 {
2383 z = sqrt(zz);
2384 x = xz/z;
2385 y = yz/z;
2386 }
2387 }
2388
2389 a_axis.set(x,y,z);
2390 a_angle = angle;
2391 return (true);
2392 }
2393
2394 // as we have reached here there are no singularities so we can handle normally
2395 double s = sqrt(((*this)(2,1) - (*this)(1,2))*((*this)(2,1) - (*this)(1,2)) +
2396 ((*this)(0,2) - (*this)(2,0))*((*this)(0,2) - (*this)(2,0)) +
2397 ((*this)(1,0) - (*this)(0,1))*((*this)(1,0) - (*this)(0,1)));
2398
2399
2400 // prevent divide by zero, should not happen if matrix is orthogonal and should be
2401 // caught by singularity test above, but I've left it in just in case
2402 if (fabs(s) < 0.001) s=1;
2403
2404 angle = acos(( (*this)(0,0) + (*this)(1,1) + (*this)(2,2) - 1)/2);
2405 x = ((*this)(2,1) - (*this)(1,2))/s;
2406 y = ((*this)(0,2) - (*this)(2,0))/s;
2407 z = ((*this)(1,0) - (*this)(0,1))/s;
2408
2409 a_axis.set(x,y,z);
2410 a_angle = angle;
2411
2412 return (true);
2413 }
2414
2415
2416 //--------------------------------------------------------------------------
2431 //--------------------------------------------------------------------------
2432 inline std::string str(const unsigned int a_precision = 2) const
2433 {
2434 std::string result;
2435 result.append("[ ");
2436
2437 for (int i=0; i<3; i++)
2438 {
2439 result.append("( ");
2440 for (int j=0; j<3; j++)
2441 {
2442 result.append(cStr((*this)(j,i), a_precision));
2443 if (j<2)
2444 {
2445 result.append(", ");
2446 }
2447 }
2448 result.append(" ) ");
2449 }
2450 result.append("]");
2451
2452 return (result);
2453 }
2454
2455
2457 inline void operator*= (const double& a_val)
2458 {
2459 (*this)(0,0) *= a_val; (*this)(0,1) *= a_val; (*this)(0,2) *= a_val;
2460 (*this)(1,0) *= a_val; (*this)(1,1) *= a_val; (*this)(1,2) *= a_val;
2461 (*this)(2,0) *= a_val; (*this)(2,1) *= a_val; (*this)(2,2) *= a_val;
2462 }
2463
2464
2466 inline cVector3d operator* (const cVector3d& a_val)
2467 {
2468 cVector3d result;
2469 mulr(a_val, result);
2470 return result;
2471 }
2472
2473
2475 inline cMatrix3d operator* (const cMatrix3d& a_val)
2476 {
2477 cMatrix3d result;
2478 mulr(a_val,result);
2479 return result;
2480 }
2481
2482
2484 inline void operator*= (const cMatrix3d& a_val)
2485 {
2486 (*this).mul(a_val);
2487 }
2488
2489
2491 inline void operator+= (const cMatrix3d& a_input)
2492 {
2493 (*this)(0,0) += a_input(0,0);
2494 (*this)(0,1) += a_input(0,1);
2495 (*this)(0,2) += a_input(0,2);
2496
2497 (*this)(1,0) += a_input(1,0);
2498 (*this)(1,1) += a_input(1,1);
2499 (*this)(1,2) += a_input(1,2);
2500
2501 (*this)(2,0) += a_input(2,0);
2502 (*this)(2,1) += a_input(2,1);
2503 (*this)(2,2) += a_input(2,2);
2504 }
2505
2506
2508 inline void operator-= (const cMatrix3d& a_input)
2509 {
2510 (*this)(0,0) -= a_input(0,0);
2511 (*this)(0,1) -= a_input(0,1);
2512 (*this)(0,2) -= a_input(0,2);
2513
2514 (*this)(1,0) -= a_input(1,0);
2515 (*this)(1,1) -= a_input(1,1);
2516 (*this)(1,2) -= a_input(1,2);
2517
2518 (*this)(2,0) -= a_input(2,0);
2519 (*this)(2,1) -= a_input(2,1);
2520 (*this)(2,2) -= a_input(2,2);
2521 }
2522
2523
2525 inline double& operator() (const int a_index0, const int a_index1)
2526 {
2527 return m_data[a_index0][a_index1];
2528 }
2529
2530
2532 inline const double& operator() (const int a_index0, const int a_index1) const
2533 {
2534 return m_data[a_index0][a_index1];
2535 }
2536
2537
2538 //--------------------------------------------------------------------------
2539 // PRIVATE MEMBERS
2540 //--------------------------------------------------------------------------
2541
2542private:
2543
2545 double m_data[3][3];
2546};
2547
2548
2549//==============================================================================
2550// OPERATORS
2551//==============================================================================
2552
2554inline cVector3d operator*(const cMatrix3d& a_matrix,
2555 const cVector3d& a_vector)
2556{
2557 cVector3d result;
2558 a_matrix.mulr(a_vector, result);
2559 return (result);
2560}
2561
2562
2564inline cMatrix3d operator*(const cMatrix3d& a_matrix1,
2565 const cMatrix3d& a_matrix2)
2566{
2567 cMatrix3d result;
2568 a_matrix1.mulr(a_matrix2, result);
2569 return (result);
2570}
2571
2573inline cMatrix3d operator*(const double& a_scalar,
2574 const cMatrix3d& a_matrix)
2575{
2576 cMatrix3d result;
2577 a_matrix.mulr(a_scalar, result);
2578 return (result);
2579}
2580
2581
2583inline cMatrix3d operator+(const cMatrix3d& a_matrix1,
2584 const cMatrix3d& a_matrix2)
2585{
2586 cMatrix3d result;
2587 a_matrix1.addr(a_matrix2, result);
2588 return (result);
2589}
2590
2591
2593inline cMatrix3d operator-(const cMatrix3d& a_matrix1,
2594 const cMatrix3d& a_matrix2)
2595{
2596 cMatrix3d result;
2597 a_matrix1.subr(a_matrix2, result);
2598 return (result);
2599}
2600
2601
2602//------------------------------------------------------------------------------
2603} // namespace chai3d
2604//------------------------------------------------------------------------------
2605
2606//------------------------------------------------------------------------------
2607#endif
2608//------------------------------------------------------------------------------
Implements mathematical constants.
Implements a 3D vector.
Definition CAudioBuffer.cpp:57
cMatrix3d operator-(const cMatrix3d &a_matrix1, const cMatrix3d &a_matrix2)
An overloaded - operator for matrix/matrix addition.
Definition CMatrix3d.h:2593
std::string cStr(const bool a_value)
This function converts a boolean into a string.
Definition CString.cpp:189
const double C_RAD2DEG
Conversion from radians to degrees.
Definition CConstants.h:97
const double C_TINY
Smallest value near zero for a double.
Definition CConstants.h:100
const double C_PI
PI constant.
Definition CConstants.h:88
cMatrix3d operator+(const cMatrix3d &a_matrix1, const cMatrix3d &a_matrix2)
An overloaded + operator for matrix/matrix addition.
Definition CMatrix3d.h:2583
const double C_PI_DIV_2
PI constant divided by two.
Definition CConstants.h:91
cVector3d operator*(const cMatrix3d &a_matrix, const cVector3d &a_vector)
An overloaded * operator for matrix/vector multiplication.
Definition CMatrix3d.h:2554
const double C_DEG2RAD
Conversion from degrees to radians.
Definition CConstants.h:94
cEulerOrder
Definition CMatrix3d.h:58
@ C_EULER_ORDER_ZXY
Definition CMatrix3d.h:67
@ C_EULER_ORDER_YXY
Definition CMatrix3d.h:66
@ C_EULER_ORDER_ZXZ
Definition CMatrix3d.h:68
@ C_EULER_ORDER_XZX
Definition CMatrix3d.h:62
@ C_EULER_ORDER_YZY
Definition CMatrix3d.h:64
@ C_EULER_ORDER_ZYZ
Definition CMatrix3d.h:70
@ C_EULER_ORDER_XYX
Definition CMatrix3d.h:60
@ C_EULER_ORDER_YZX
Definition CMatrix3d.h:63
@ C_EULER_ORDER_ZYX
Definition CMatrix3d.h:69
@ C_EULER_ORDER_XZY
Definition CMatrix3d.h:61
@ C_EULER_ORDER_XYZ
Definition CMatrix3d.h:59
@ C_EULER_ORDER_YXZ
Definition CMatrix3d.h:65
This class implements a 3D matrix.
Definition CMatrix3d.h:98
void addr(const cMatrix3d &a_matrix, cMatrix3d &a_result) const
This method computes the addition of this matrix with another.
Definition CMatrix3d.h:785
void subr(const cMatrix3d &a_matrix, cMatrix3d &a_result) const
This method computes the subtraction of this matrix with another.
Definition CMatrix3d.h:850
void mul(const double &a_scalar)
This function computes the multiplication of this matrix by a scalar.
Definition CMatrix3d.h:882
void setCol2(const cVector3d &a_vectCol)
This method initializes column 2 of this matrix.
Definition CMatrix3d.h:491
bool invert()
This method computes the inverse of this matrix.
Definition CMatrix3d.h:1144
void setExtrinsicEulerRotationRad(const double &a_angle1, const double &a_angle2, const double &a_angle3, const cEulerOrder a_eulerOrder)
This method builds a rotation matrix from an Euler angle representation.
Definition CMatrix3d.h:1408
std::string str(const unsigned int a_precision=2) const
This method converts this matrix to a string representation.
Definition CMatrix3d.h:2432
bool rotateAboutLocalAxisDeg(const double &a_axisX, const double &a_axisY, const double &a_axisZ, const double &a_angleDeg)
This method rotates this matrix around an axis described in local coordinates.
Definition CMatrix3d.h:2281
cVector3d getCol0() const
This method returns column vector 0 of matrix.
Definition CMatrix3d.h:536
bool rotateAboutGlobalAxisRad(const double &a_axisX, const double &a_axisY, const double &a_axisZ, const double &a_angleRad)
This method rotates this matrix around an axis described in global coordinates.
Definition CMatrix3d.h:2125
void setCol1(const cVector3d &a_vectCol)
This method initializes column 1 of this matrix.
Definition CMatrix3d.h:471
void setIntrinsicEulerRotationDeg(const double &a_angle1, const double &a_angle2, const double &a_angle3, const cEulerOrder a_eulerOrder)
This method builds a rotation matrix from an Euler angle representation.
Definition CMatrix3d.h:1615
cMatrix3d(const cVector3d &a_axis, const double &a_angleRad)
Definition CMatrix3d.h:264
bool setAxisAngleRotationRad(const cVector3d &a_axis, const double &a_angleRad)
This method builds a rotation matrix from an axis-angle representation.
Definition CMatrix3d.h:1282
void mulr(const cMatrix3d &a_matrix, cMatrix3d &a_result) const
This function computes the multiplication of this matrix with another.
Definition CMatrix3d.h:989
void mulr(const double &a_scalar, cMatrix3d &a_result) const
This function computes the multiplication of this matrix by a scalar.
Definition CMatrix3d.h:916
bool rotateAboutLocalAxisRad(const cVector3d &a_axis, const double &a_angleRad)
This method rotates this matrix around an axis described in local coordinates.
Definition CMatrix3d.h:2177
double det() const
This method computes and returns the determinant of this matrix.
Definition CMatrix3d.h:1072
bool rotateAboutLocalAxisDeg(const cVector3d &a_axis, const double &a_angleDeg)
This method rotates this matrix around an axis described in local coordinates.
Definition CMatrix3d.h:2229
void operator+=(const cMatrix3d &a_input)
An overloaded += operator for matrix/matrix addition.
Definition CMatrix3d.h:2491
void mul(cVector3d &a_vector) const
This function computes the multiplication of this matrix with a vector.
Definition CMatrix3d.h:1023
cVector3d operator*(const cVector3d &a_val)
An overloaded * operator for matrix/vector multiplication.
Definition CMatrix3d.h:2466
void add(const cMatrix3d &a_matrix)
This method computes the addition of this matrix with another.
Definition CMatrix3d.h:752
void set(const double a_source[3][3])
This method initializes this matrix from an array.
Definition CMatrix3d.h:365
bool rotateAboutGlobalAxisDeg(const double &a_axisX, const double &a_axisY, const double &a_axisZ, const double &a_angleDeg)
This method rotates this matrix around an axis described in global coordinates.
Definition CMatrix3d.h:2152
cMatrix3d(const cVector3d &a_colVector0, const cVector3d &a_colVector1, const cVector3d &a_colVector2)
Definition CMatrix3d.h:171
cMatrix3d()
Definition CMatrix3d.h:110
double & operator()(const int a_index0, const int a_index1)
An overloaded () operator.
Definition CMatrix3d.h:2525
void setIntrinsicEulerRotationRad(const double &a_angle1, const double &a_angle2, const double &a_angle3, const cEulerOrder a_eulerOrder)
This method builds a rotation matrix from an Euler angle representation.
Definition CMatrix3d.h:1510
void copyfrom(const cMatrix3d &a_source)
This method copies all elements from another matrix to this one.
Definition CMatrix3d.h:675
bool invertr(cMatrix3d &a_result) const
This method computes the inverse of this matrix.
Definition CMatrix3d.h:1199
bool getIntrinsicEulerAnglesDeg(cVector3d &a_eulerAngles1, cVector3d &a_eulerAngles2, const cEulerOrder a_eulerOrder)
This method computes the intrinsic Euler angle representations for this matrix in degrees.
Definition CMatrix3d.h:2009
bool equals(cMatrix3d &a_matrix) const
This method compares if two matrices are equal.
Definition CMatrix3d.h:722
bool rotateAboutGlobalAxisDeg(const cVector3d &a_axis, const double &a_angleDeg)
This method rotates this matrix around an axis described in global coordinates.
Definition CMatrix3d.h:2100
bool rotateAboutLocalAxisRad(const double &a_axisX, const double &a_axisY, const double &a_axisZ, const double &a_angleRad)
This method rotates this matrix around an axis described in local coordinates.
Definition CMatrix3d.h:2254
void operator*=(const double &a_val)
An overloaded *= operator for matrix/scalar multiplication.
Definition CMatrix3d.h:2457
void set(const double &a_m00, const double &a_m01, const double &a_m02, const double &a_m10, const double &a_m11, const double &a_m12, const double &a_m20, const double &a_m21, const double &a_m22)
This method initializes this matrix with individual elements passed as arguments.
Definition CMatrix3d.h:400
cMatrix3d(const double &a_angle1, const double &a_angle2, const double &a_angle3, const cEulerOrder a_eulerOrder, const bool a_useIntrinsicEulerModel=true, const bool a_anglesDefinedInDegrees=false)
Definition CMatrix3d.h:222
void copyto(cMatrix3d &a_destination) const
This method copies all elements of this matrix to another matrix.
Definition CMatrix3d.h:628
void trans()
This method computes the transpose of this matrix.
Definition CMatrix3d.h:1094
bool getIntrinsicEulerAnglesRad(cVector3d &a_eulerAngles1, cVector3d &a_eulerAngles2, const cEulerOrder a_eulerOrder)
This method computes the intrinsic Euler angle representations for this matrix in radians.
Definition CMatrix3d.h:1763
void mulr(const cVector3d &a_vector, cVector3d &a_result) const
This function computes the multiplication of this matrix with a vector.
Definition CMatrix3d.h:1052
void operator-=(const cMatrix3d &a_input)
An overloaded -= operator for matrix/matrix subtraction.
Definition CMatrix3d.h:2508
void set(const double &a_value)
This method initializes all elements of this matrix with an input value.
Definition CMatrix3d.h:345
void identity()
This method builds an identity matrix.
Definition CMatrix3d.h:325
void mul(const cMatrix3d &a_matrix)
This function computes the multiplication of this matrix with another.
Definition CMatrix3d.h:950
void setExtrinsicEulerRotationDeg(const double &a_angle1, const double &a_angle2, const double &a_angle3, const cEulerOrder a_eulerOrder)
This method builds a rotation matrix from an Euler angle representation.
Definition CMatrix3d.h:1482
bool setAxisAngleRotationDeg(const cVector3d &a_axis, const double &a_angleDeg)
This method builds a rotation matrix from an axis-angle representation.
Definition CMatrix3d.h:1331
bool getExtrinsicEulerAnglesRad(cVector3d &a_eulerAngles1, cVector3d &a_eulerAngles2, const cEulerOrder a_eulerOrder)
This method computes the extrinsic Euler angle representations for this matrix in radians.
Definition CMatrix3d.h:1645
bool setAxisAngleRotationDeg(const double &a_axisX, const double &a_axisY, const double &a_axisZ, const double &a_angleDeg)
This method builds a rotation matrix from axis-angle representation.
Definition CMatrix3d.h:1383
cVector3d getCol1() const
This method returns column vector 1 of matrix.
Definition CMatrix3d.h:557
void get(double *a_destination[])
This method copies matrix elements to a table of doubles
Definition CMatrix3d.h:511
cMatrix3d(const double &a_m00, const double &a_m01, const double &a_m02, const double &a_m10, const double &a_m11, const double &a_m12, const double &a_m20, const double &a_m21, const double &a_m22)
Definition CMatrix3d.h:151
void transr(cMatrix3d &a_result) const
This method computes the transpose of this matrix.
Definition CMatrix3d.h:1116
cMatrix3d(const double &a_axisX, const double &a_axisY, const double &a_axisZ, const double &a_angleRad)
Definition CMatrix3d.h:282
bool getExtrinsicEulerAnglesDeg(cVector3d &a_eulerAngles1, cVector3d &a_eulerAngles2, const cEulerOrder a_eulerOrder)
This method computes the extrinsic Euler angle representations for this matrix in degrees.
Definition CMatrix3d.h:1723
bool setAxisAngleRotationRad(const double &a_axisX, const double &a_axisY, const double &a_axisZ, const double &a_angleRad)
This method builds a rotation matrix from an axis-angle representation.
Definition CMatrix3d.h:1356
bool toAxisAngle(cVector3d &a_axis, double &a_angle) const
This method converts this rotation matrix to an axis-angle representation.
Definition CMatrix3d.h:2306
bool rotateAboutGlobalAxisRad(const cVector3d &a_axis, const double &a_angleRad)
This method rotates this matrix around an axis described in global coordinates.
Definition CMatrix3d.h:2048
void setCol0(const cVector3d &a_vectCol)
This method initializes column 0 of this matrix.
Definition CMatrix3d.h:451
void sub(const cMatrix3d &a_matrix)
This method computes the subtraction of this matrix with another.
Definition CMatrix3d.h:817
void setCol(const cVector3d &a_vectCol0, const cVector3d &a_vectCol1, const cVector3d &a_vectCol2)
This method initialize this matrix with column vectors passed as arguments.
Definition CMatrix3d.h:429
cVector3d getRow(const unsigned int &a_index) const
This method returns the i th row of matrix.
Definition CMatrix3d.h:602
void orthogonalize()
This method orthogonalizes this matrix.
Definition CMatrix3d.h:1247
cVector3d getCol2() const
This method returns column vector 2 of matrix.
Definition CMatrix3d.h:578
This class implements a 3D vector.
Definition CVector3d.h:89
void normalize()
This method normalizes this vector to length 1.
Definition CVector3d.h:1034
void set(const double &a_x, const double &a_y, const double &a_z)
This method initializes this vector with components x, y, and z passed as arguments.
Definition CVector3d.h:278
void crossr(const cVector3d &a_vector, cVector3d &a_result) const
This method computes the cross product.
Definition CVector3d.h:955
double length() const
This method computes the Euclidean norm of this vector.
Definition CVector3d.h:995