CONFIG LIB 1.5
Configuration Files Library (by TGG 2020)
Loading...
Searching...
No Matches
matr3d.cpp
1/*********************************************************************/
2/* */
3/* Config files library - (C) TGG 2019 */
4/* */
5/*********************************************************************/
6/* Warszawa, 2019 */
7/*********************************************************************/
8/* */
9/* File: matr3d.cpp */
10/* */
11/* Author: F.A.Dul, modif. by T.Grabowski */
12/* */
13/* Contents - matrix 3x3 class */
14/* */
15/* */
16/*********************************************************************/
17/* */
18/* */
19
20#include "matr3d.h"
21
22using namespace std;
23
24// Matrix 3x3 and Vector 3D operators
25
26
27VECTOR_3D operator *( const MATRIX_3x3 &A , const VECTOR_3D &b )
28{
29 VECTOR_3D w;
30
31 w.x = A.xx * b.x + A.xy * b.y + A.xz * b.z;
32 w.y = A.yx * b.x + A.yy * b.y + A.yz * b.z;
33 w.z = A.zx * b.x + A.zy * b.y + A.zz * b.z;
34
35 return w;
36}
37
38
39VECTOR_3D operator *( const VECTOR_3D &b , const MATRIX_3x3 &A )
40{
41 VECTOR_3D w;
42
43 w.x = b.x * A.xx + b.y * A.yx + b.z * A.zx;
44 w.y = b.x * A.xy + b.y * A.yy + b.z * A.zy;
45 w.z = b.x * A.xz + b.y * A.yz + b.z * A.zz;
46
47 return w;
48}
49
50
51MATRIX_3x3 operator &( const MATRIX_3x3 &A , const MATRIX_3x3 &B )
52{
53 MATRIX_3x3 C;
54
55 C.xx = A.xx * B.xx; C.xy = A.xy * B.xy; C.xz = A.xz * B.xz;
56 C.yx = A.yx * B.yx; C.yy = A.yy * B.yy; C.yz = A.yz * B.yz;
57 C.zx = A.zx * B.zx; C.zy = A.zy * B.zy; C.zz = A.zz * B.zz;
58
59 return C;
60}
61
62
63MATRIX_3x3 operator +( const MATRIX_3x3 &A , const MATRIX_3x3 &B )
64{
65 MATRIX_3x3 C;
66
67 C.xx = A.xx + B.xx; C.xy = A.xy + B.xy; C.xz = A.xz + B.xz;
68 C.yx = A.yx + B.yx; C.yy = A.yy + B.yy; C.yz = A.yz + B.yz;
69 C.zx = A.zx + B.zx; C.zy = A.zy + B.zy; C.zz = A.zz + B.zz;
70
71 return C;
72}
73
74
75MATRIX_3x3 operator -( const MATRIX_3x3 &A , const MATRIX_3x3 &B )
76{
77 MATRIX_3x3 C;
78
79 C.xx = A.xx - B.xx; C.xy = A.xy - B.xy; C.xz = A.xz - B.xz;
80 C.yx = A.yx - B.yx; C.yy = A.yy - B.yy; C.yz = A.yz - B.yz;
81 C.zx = A.zx - B.zx; C.zy = A.zy - B.zy; C.zz = A.zz - B.zz;
82
83 return C;
84}
85
86
87MATRIX_3x3 operator -( const MATRIX_3x3 &A )
88{
89 MATRIX_3x3 C;
90
91 C.xx = -A.xx; C.xy = -A.xy; C.xz = -A.xz;
92 C.yx = -A.yx; C.yy = -A.yy; C.yz = -A.yz;
93 C.zx = -A.zx; C.zy = -A.zy; C.zz = -A.zz;
94
95 return C;
96}
97
98
99
100MATRIX_3x3 operator *( const MATRIX_3x3 &A , const double &s )
101{
102 MATRIX_3x3 C;
103
104 C.xx = A.xx * s; C.xy = A.xy * s; C.xz = A.xz * s;
105 C.yx = A.yx * s; C.yy = A.yy * s; C.yz = A.yz * s;
106 C.zx = A.zx * s; C.zy = A.zy * s; C.zz = A.zz * s;
107
108 return C;
109}
110
111
112MATRIX_3x3 operator *( const double &s , const MATRIX_3x3 &A )
113{
114 MATRIX_3x3 C;
115
116 C.xx = A.xx * s; C.xy = A.xy * s; C.xz = A.xz * s;
117 C.yx = A.yx * s; C.yy = A.yy * s; C.yz = A.yz * s;
118 C.zx = A.zx * s; C.zy = A.zy * s; C.zz = A.zz * s;
119
120 return C;
121}
122
123
124MATRIX_3x3 operator /( const MATRIX_3x3 &A , const double &s )
125{
126 MATRIX_3x3 C;
127
128 C.xx = A.xx / s; C.xy = A.xy / s; C.xz = A.xz / s;
129 C.yx = A.yx / s; C.yy = A.yy / s; C.yz = A.yz / s;
130 C.zx = A.zx / s; C.zy = A.zy / s; C.zz = A.zz / s;
131
132 return C;
133}
134
135void operator /=( MATRIX_3x3 &A , const double &s )
136{
137 A.xx /= s; A.xy /= s; A.xz /= s;
138 A.yx /= s; A.yy /= s; A.yz /= s;
139 A.zx /= s; A.zy /= s; A.zz /= s;
140}
141
142MATRIX_3x3 operator !( const MATRIX_3x3 &A ) // A^T
143{
144 return MATRIX_3x3 (
145 A.xx , A.yx , A.zx ,
146 A.xy , A.yy , A.zy ,
147 A.xz , A.yz , A.zz
148 );
149}
150
151
152MATRIX_3x3 operator *( const MATRIX_3x3 &A , const MATRIX_3x3 &B )
153{
154 MATRIX_3x3 C;
155
156 C.xx = A.xx * B.xx + A.xy * B.yx + A.xz * B.zx;
157 C.yx = A.yx * B.xx + A.yy * B.yx + A.yz * B.zx;
158 C.zx = A.zx * B.xx + A.zy * B.yx + A.zz * B.zx;
159
160 C.xy = A.xx * B.xy + A.xy * B.yy + A.xz * B.zy;
161 C.yy = A.yx * B.xy + A.yy * B.yy + A.yz * B.zy;
162 C.zy = A.zx * B.xy + A.zy * B.yy + A.zz * B.zy;
163
164 C.xz = A.xx * B.xz + A.xy * B.yz + A.xz * B.zz;
165 C.yz = A.yx * B.xz + A.yy * B.yz + A.yz * B.zz;
166 C.zz = A.zx * B.xz + A.zy * B.yz + A.zz * B.zz;
167
168 return C;
169}
170
171MATRIX_3x3 operator ~( const MATRIX_3x3 &A ) // A^(-1)
172{
173// C = A^(-1)
174
175 MATRIX_3x3 C = A;
176 double w = C.Det();
177 C.SetToZero();
178
179 C.xx = A.yy * A.zz - A.zy * A.yz;
180 C.xy = A.xz * A.zy - A.xy * A.zz;
181 C.xz = A.xy * A.yz - A.xz * A.yy;
182
183 C.yx = A.yz * A.zx - A.yx * A.zz;
184 C.yy = A.xx * A.zz - A.xz * A.zx;
185 C.yz = A.xz * A.yx - A.xx * A.yz;
186
187 C.zx = A.yx * A.zy - A.yy * A.zx;
188 C.zy = A.xy * A.zx - A.xx * A.zy;
189 C.zz = A.xx * A.yy - A.xy * A.yx;
190
191 if( w != 0.0 ) C /= w;
192
193 return C;
194}
195
196VECTOR_3D operator / ( const VECTOR_3D &b , MATRIX_3x3 &B )
197{
198 return b * ~B;
199}
200
202
203void v_printf( char *name , const MATRIX_3x3 &mat )
204{
205 printf( "%s=[%19.11f,%19.11f,%19.11f]\n[%19.11f,%19.11f,%19.11f]\n[%19.11f,%19.11f,%19.11f]\n",
206 name , mat.xx , mat.xy , mat.xz, mat.yx , mat.yy , mat.yz, mat.zx , mat.zy , mat.zz );
207}
208
209void v_printf( char *fmt , char *name , const MATRIX_3x3 &mat )
210{
211 printf( fmt , name , mat.xx , mat.xy , mat.xz, mat.yx , mat.yy , mat.yz, mat.zx , mat.zy , mat.zz );
212}
213
214void v_sprintf( char *dest , char *name , const MATRIX_3x3 &mat )
215{
216 sprintf(dest,"%s=[%19.11f,%19.11f %19.11f][%19.11f,%19.11f,%19.11f][%19.11f,%19.11f,%19.11f]",
217 name , mat.xx , mat.xy , mat.xz, mat.yx , mat.yy , mat.yz, mat.zx , mat.zy , mat.zz );
218}
219
220void v_sprintf( char *dest , char *fmt , char *name , const MATRIX_3x3 &mat )
221{
222 sprintf(dest , fmt , name , mat.xx , mat.xy , mat.xz, mat.yx , mat.yy , mat.yz, mat.zx , mat.zy , mat.zz );
223}
224
225void v_fprintf( FILE *dest , char *name , const MATRIX_3x3 &mat )
226{
227 fprintf(dest,"%s=[%19.11f,%19.11f %19.11f]\n[%19.11f,%19.11f,%19.11f]\n[%19.11f,%19.11f,%19.11f]\n",
228 name , mat.xx , mat.xy , mat.xz, mat.yx , mat.yy , mat.yz, mat.zx , mat.zy , mat.zz );
229}
230
231void v_fprintf( FILE *dest , char *fmt , char *name , const MATRIX_3x3 &mat )
232{
233 fprintf( dest , fmt , name , mat.xx , mat.xy , mat.xz, mat.yx , mat.yy , mat.yz, mat.zx , mat.zy , mat.zz );
234}
235
236ostream & operator << ( ostream & out, const MATRIX_3x3 & mat )
237{
238 out << "[" << mat.xx << " , " << mat.xy << " , " << mat.xz << "]"
239 << "[" << mat.yx << " , " << mat.yy << " , " << mat.yz << "]"
240 << "[" << mat.zx << " , " << mat.zy << " , " << mat.zz << "]";
241 return out;
242}
243
244
MATRIX_3x3 class and functions.
Definition matr3d.h:41
double yy
(1,1) element
Definition matr3d.h:48
double xx
(0,0) element
Definition matr3d.h:44
double zz
(2,2) element
Definition matr3d.h:52
double yz
(1,2) element
Definition matr3d.h:49
double Det(void)
matrix determinant
Definition matr3d.h:114
double zx
(2,0) element
Definition matr3d.h:50
double yx
(1,0) element
Definition matr3d.h:47
double xz
(0,2) element
Definition matr3d.h:46
double xy
(0,1) element
Definition matr3d.h:45
void SetToZero(void)
reset matrix - set all components to zero
Definition matr3d.h:100
double zy
(2,1) element
Definition matr3d.h:51
Vector 3D class - vector manipulation.
Definition vector3d.h:34
double x
x coordinate
Definition vector3d.h:38
double z
z coordinate
Definition vector3d.h:38
double y
y coordinate
Definition vector3d.h:38
MATRIX_3x3 class and functions.