1 /*
2  *_________________________________________________________________________*
3  *      POEMS: PARALLELIZABLE OPEN SOURCE EFFICIENT MULTIBODY SOFTWARE     *
4  *      DESCRIPTION: SEE READ-ME                                           *
5  *      FILE NAME: mat3x3.cpp                                              *
6  *      AUTHORS: See Author List                                           *
7  *      GRANTS: See Grants List                                            *
8  *      COPYRIGHT: (C) 2005 by Authors as listed in Author's List          *
9  *      LICENSE: Please see License Agreement                              *
10  *      DOWNLOAD: Free at www.rpi.edu/~anderk5                             *
11  *      ADMINISTRATOR: Prof. Kurt Anderson                                 *
12  *                     Computational Dynamics Lab                          *
13  *                     Rensselaer Polytechnic Institute                    *
14  *                     110 8th St. Troy NY 12180                           *
15  *      CONTACT:        anderk5@rpi.edu                                    *
16  *_________________________________________________________________________*/
17 
18 
19 #include "mat3x3.h"
20 #include <cstdlib>
21 
22 using namespace std;
23 
Mat3x3()24 Mat3x3::Mat3x3(){
25   numrows = numcols = 3;
26 }
~Mat3x3()27 Mat3x3::~Mat3x3(){
28 }
29 
Mat3x3(const Mat3x3 & A)30 Mat3x3::Mat3x3(const Mat3x3& A){
31   numrows = numcols = 3;
32   elements[0][0] = A.elements[0][0];elements[0][1] = A.elements[0][1];elements[0][2] = A.elements[0][2];
33   elements[1][0] = A.elements[1][0];elements[1][1] = A.elements[1][1];elements[1][2] = A.elements[1][2];
34   elements[2][0] = A.elements[2][0];elements[2][1] = A.elements[2][1];elements[2][2] = A.elements[2][2];
35 }
36 
Mat3x3(const VirtualMatrix & A)37 Mat3x3::Mat3x3(const VirtualMatrix& A){
38   numrows = numcols = 3;
39 
40   // error check
41   if( (A.GetNumRows() != 3) || (A.GetNumCols() != 3) ){
42     cerr << "illegal matrix size" << endl;
43     exit(0);
44   }
45 
46   for(int i=0;i<3;i++)
47     for(int j=0;j<3;j++)
48       elements[i][j] = A.BasicGet(i,j);
49 }
50 
operator_2int(int i,int j)51 double& Mat3x3::operator_2int(int i, int j){ // array access
52   return elements[i-1][j-1];
53 }
54 
Get_2int(int i,int j) const55 double Mat3x3::Get_2int(int i, int j) const{
56   return elements[i-1][j-1];
57 }
58 
Set_2int(int i,int j,double value)59 void Mat3x3::Set_2int(int i, int j, double value){
60   elements[i-1][j-1] = value;
61 }
62 
BasicGet_2int(int i,int j) const63 double Mat3x3::BasicGet_2int(int i, int j) const{
64   return elements[i][j];
65 }
66 
BasicSet_2int(int i,int j,double value)67 void Mat3x3::BasicSet_2int(int i, int j, double value){
68   elements[i][j] = value;
69 }
70 
BasicIncrement_2int(int i,int j,double value)71 void Mat3x3::BasicIncrement_2int(int i, int j, double value){
72   elements[i][j] += value;
73 }
74 
Const(double value)75 void Mat3x3::Const(double value){
76   elements[0][0] = elements[0][1] = elements[0][2] = value;
77   elements[1][0] = elements[1][1] = elements[1][2] = value;
78   elements[2][0] = elements[2][1] = elements[2][2] = value;
79 }
80 
GetType() const81 MatrixType Mat3x3::GetType() const{
82   return MAT3X3;
83 }
84 
ReadData(istream & c)85 istream& Mat3x3::ReadData(istream& c){  //input
86   for(int i=0;i<3;i++)
87     for(int j=0;j<3;j++)
88       c >> elements[i][j];
89   return c;
90 }
91 
WriteData(ostream & c) const92 ostream& Mat3x3::WriteData(ostream& c) const{  //output
93   for(int i=0;i<3;i++)
94     for(int j=0;j<3;j++)
95       c << elements[i][j] << ' ';
96   return c;
97 }
98 
AssignVM(const VirtualMatrix & A)99 void Mat3x3::AssignVM(const VirtualMatrix& A){
100   // error check
101   if( (A.GetNumRows() != 3) || (A.GetNumCols() != 3) ){
102     cerr << "illegal matrix size" << endl;
103     exit(0);
104   }
105 
106   for(int i=0;i<numrows;i++)
107     for(int j=0;j<numcols;j++)
108       elements[i][j] = A.BasicGet(i,j);
109 }
110 
operator =(const Mat3x3 & A)111 Mat3x3& Mat3x3::operator=(const Mat3x3& A){ // assignment operator
112   elements[0][0] = A.elements[0][0];elements[0][1] = A.elements[0][1];elements[0][2] = A.elements[0][2];
113   elements[1][0] = A.elements[1][0];elements[1][1] = A.elements[1][1];elements[1][2] = A.elements[1][2];
114   elements[2][0] = A.elements[2][0];elements[2][1] = A.elements[2][1];elements[2][2] = A.elements[2][2];
115   return *this;
116 }
117 
operator =(const VirtualMatrix & A)118 Mat3x3& Mat3x3::operator=(const VirtualMatrix& A){ // overloaded =
119   // error check
120   if( (A.GetNumRows() != 3) || (A.GetNumCols() != 3) ){
121     cerr << "illegal matrix size" << endl;
122     exit(0);
123   }
124 
125   for(int i=0;i<numrows;i++)
126     for(int j=0;j<numcols;j++)
127       elements[i][j] = A.BasicGet(i,j);
128   return *this;
129 }
130 
operator *=(double b)131 Mat3x3& Mat3x3::operator*=(double b){
132   elements[0][0] *= b; elements[0][1] *= b; elements[0][2] *= b;
133   elements[1][0] *= b; elements[1][1] *= b; elements[1][2] *= b;
134   elements[2][0] *= b; elements[2][1] *= b; elements[2][2] *= b;
135   return *this;
136 }
137 
Identity()138 Mat3x3& Mat3x3::Identity(){
139   elements[0][0] = 1.0;
140   elements[0][1] = 0.0;
141   elements[0][2] = 0.0;
142 
143   elements[1][0] = 0.0;
144   elements[1][1] = 1.0;
145   elements[1][2] = 0.0;
146 
147   elements[2][0] = 0.0;
148   elements[2][1] = 0.0;
149   elements[2][2] = 1.0;
150 
151   return *this;
152 }
153 
154