FrontISTR  5.7.0
Large-scale structural analysis program with finit element method
cconv_mat.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2019 FrontISTR Commons
3  * This software is released under the MIT License, see LICENSE.txt
4  *****************************************************************************/
5 /* matrix for converting ver.1.0 */
6 
7 #include <assert.h>
8 #include "cconv_mat.h"
9 
11 
12 cconv_mat::cconv_mat(const cconv_mat &m, coord_type t) : type(t) {
13  for (int i = 0; i < 4; i++) {
14  for (int j = 0; j < 4; j++) {
15  e[i][j] = m(i, j);
16  }
17  }
18 }
19 
21  type = m.type;
22 
23  for (int i = 0; i < 4; i++) {
24  for (int j = 0; j < 4; j++) {
25  e[i][j] = ((cconv_mat &)m)(i, j);
26  }
27  }
28 
29  return *this;
30 }
31 
33  type = m.type;
34 
35  for (int i = 0; i < 4; i++) {
36  for (int j = 0; j < 4; j++) {
37  e[i][j] *= ((cconv_mat &)m)(i, j);
38  }
39  }
40 
41  return *this;
42 }
43 
45  for (int i = 0; i < 4; i++) {
46  for (int j = 0; j < 4; j++) {
47  e[i][j] = 0.0;
48  }
49  }
50 }
51 
53  for (int i = 0; i < 4; i++) {
54  for (int j = 0; j < 4; j++) {
55  if (i == j)
56  e[i][j] = 1.0;
57 
58  else
59  e[i][j] = 0.0;
60  }
61  }
62 }
63 
64 void cconv_mat::transfer(double x, double y, double z) {
65  unit();
66  e[0][3] = x;
67  e[1][3] = y;
68  e[2][3] = z;
69 }
70 
71 void cconv_mat::rotate(char axis, double angle) {
72  double s = sin(angle);
73  double c = cos(angle);
74  e[3][0] = e[3][1] = e[3][2] = 0.0;
75  e[3][3] = 1.0;
76 
77  switch (axis) {
78  case 'x':
79  case 'X':
80  e[0][0] = 1;
81  e[0][1] = 0;
82  e[0][2] = 0;
83  e[1][0] = 0;
84  e[1][1] = c;
85  e[1][2] = -s;
86  e[2][0] = 0;
87  e[2][1] = s;
88  e[2][2] = c;
89  break;
90 
91  case 'y':
92  case 'Y':
93  e[0][0] = c;
94  e[0][1] = 0;
95  e[0][2] = s;
96  e[1][0] = 0;
97  e[1][1] = 1;
98  e[1][2] = 0;
99  e[2][0] = -s;
100  e[2][1] = 0;
101  e[2][2] = c;
102  break;
103 
104  case 'z':
105  case 'Z':
106  e[0][0] = c;
107  e[0][1] = -s;
108  e[0][2] = 0;
109  e[1][0] = s;
110  e[1][1] = c;
111  e[1][2] = 0;
112  e[2][0] = 0;
113  e[2][1] = 0;
114  e[2][2] = 1;
115  break;
116  }
117 }
118 
119 void cconv_mat::convert(double x, double y, double z, double &X, double &Y,
120  double &Z) {
121  double xx, yy, zz;
122 
123  switch (type) {
124  case coord_t_cartesian:
125  cartesian_convert(x, y, z, X, Y, Z);
126  break;
127 
128  case coord_t_cylinder:
129  cylinder2cartesian(x, y, z, xx, yy, zz);
130  cartesian_convert(xx, yy, zz, X, Y, Z);
131  break;
132 
133  case coord_t_sphere:
134  sphere2cartesian(x, y, z, xx, yy, zz);
135  cartesian_convert(xx, yy, zz, X, Y, Z);
136  break;
137 
138  default:
139  assert(0);
140  }
141 }
142 
143 void cconv_mat::cartesian_convert(double x, double y, double z, double &X,
144  double &Y, double &Z) {
145  X = e[0][0] * x + e[0][1] * y + e[0][2] * z + e[0][3];
146  Y = e[1][0] * x + e[1][1] * y + e[1][2] * z + e[1][3];
147  Z = e[2][0] * x + e[2][1] * y + e[2][2] * z + e[2][3];
148 }
149 
150 void cconv_mat::cylinder2cartesian(double r, double a, double h, double &x,
151  double &y, double &z) {
152  x = r * cos(a);
153  y = r * sin(a);
154  z = h;
155 }
156 
157 void cconv_mat::sphere2cartesian(double r, double a, double b, double &x,
158  double &y, double &z) {
159  double R = r * cos(b);
160  x = R * cos(a);
161  y = R * sin(a);
162  z = r * sin(b);
163 }
164 
166  cconv_mat m;
167 
168  for (int i = 0; i < 4; i++) {
169  for (int j = 0; j < 4; j++) {
170  double r = 0.0;
171 
172  for (int k = 0; k < 4; k++) {
173  r += a(i, k) * b(k, j);
174  }
175 
176  m(i, j) = r;
177  }
178  }
179 
180  return m;
181 }
cconv_mat::e
double e[4][4]
Definition: cconv_mat.h:16
cconv_mat::cylinder2cartesian
void cylinder2cartesian(double r, double a, double h, double &x, double &y, double &z)
Definition: cconv_mat.cpp:150
cconv_mat::transfer
void transfer(double x, double y, double z)
Definition: cconv_mat.cpp:64
cconv_mat
Definition: cconv_mat.h:14
coord_t_cartesian
@ coord_t_cartesian
Definition: cconv_mat.h:15
cconv_mat::convert
void convert(double x, double y, double z, double &X, double &Y, double &Z)
Definition: cconv_mat.cpp:119
operator*
cconv_mat operator*(cconv_mat &a, cconv_mat &b)
Definition: cconv_mat.cpp:165
cconv_mat::cartesian_convert
void cartesian_convert(double x, double y, double z, double &X, double &Y, double &Z)
Definition: cconv_mat.cpp:143
coord_t_sphere
@ coord_t_sphere
Definition: cconv_mat.h:15
cconv_mat::type
coord_type type
Definition: cconv_mat.h:17
cconv_mat.h
cconv_mat::zero
void zero()
Definition: cconv_mat.cpp:44
coord_t_cylinder
@ coord_t_cylinder
Definition: cconv_mat.h:15
cconv_mat::sphere2cartesian
void sphere2cartesian(double r, double a, double b, double &x, double &y, double &z)
Definition: cconv_mat.cpp:157
cconv_mat::cconv_mat
cconv_mat(coord_type t=coord_t_cartesian)
Definition: cconv_mat.cpp:10
cconv_mat::unit
void unit()
Definition: cconv_mat.cpp:52
cconv_mat::rotate
void rotate(char axis, double angle)
Definition: cconv_mat.cpp:71
cconv_mat::operator=
cconv_mat & operator=(const cconv_mat &m)
Definition: cconv_mat.cpp:20
coord_type
coord_type
Definition: cconv_mat.h:12
cconv_mat::operator*=
cconv_mat & operator*=(const cconv_mat &m)
Definition: cconv_mat.cpp:32