PeriDyno
1.0.0
Loading...
Searching...
No Matches
D:
Peridyno
peridyno
src
Core
Matrix
Matrix2x2.inl
Go to the documentation of this file.
1
#include <cmath>
2
#include <limits>
3
4
#include "
Vector.h
"
5
6
namespace
dyno
7
{
8
template
<
typename
T>
9
DYN_FUNC
SquareMatrix<T, 2>::SquareMatrix
()
10
:
SquareMatrix
(0)
//delegating ctor
11
{
12
}
13
14
template
<
typename
T>
15
DYN_FUNC
SquareMatrix<T, 2>::SquareMatrix
(
T
value)
16
:
SquareMatrix
(value, value, value, value)
//delegating ctor
17
{
18
}
19
20
template
<
typename
T>
21
DYN_FUNC
SquareMatrix<T, 2>::SquareMatrix
(
T
x00,
T
x01,
T
x10,
T
x11)
22
:
data_
(x00, x10, x01, x11)
23
{
24
}
25
26
template
<
typename
T>
27
DYN_FUNC
SquareMatrix<T, 2>::SquareMatrix
(
const
Vector<T, 2>
&row1,
const
Vector<T, 2>
&row2)
28
:
data_
(row1[0], row2[0], row1[1], row2[1])
29
{
30
}
31
32
template
<
typename
T>
33
DYN_FUNC
SquareMatrix<T, 2>::SquareMatrix
(
const
SquareMatrix<T, 2>
&mat)
34
{
35
data_
= mat.data_;
36
}
37
38
template
<
typename
T>
39
DYN_FUNC
SquareMatrix<T, 2>::~SquareMatrix
()
40
{
41
42
}
43
44
template
<
typename
T>
45
DYN_FUNC
T
&
SquareMatrix<T, 2>::operator()
(
unsigned
int
i,
unsigned
int
j)
46
{
47
return
const_cast<
T
&
>
(
static_cast<
const
SquareMatrix<T, 2>
&
>
(*this)(i, j));
48
}
49
50
template
<
typename
T>
51
DYN_FUNC
const
T
&
SquareMatrix<T, 2>::operator()
(
unsigned
int
i,
unsigned
int
j)
const
52
{
53
return
data_
[j][i];
54
}
55
56
template
<
typename
T>
57
DYN_FUNC
const
Vector<T, 2>
SquareMatrix<T, 2>::row
(
unsigned
int
i)
const
58
{
59
Vector<T, 2>
result((*
this
)(i, 0), (*
this
)(i, 1));
60
return
result;
61
}
62
63
template
<
typename
T>
64
DYN_FUNC
const
Vector<T, 2>
SquareMatrix<T, 2>::col
(
unsigned
int
i)
const
65
{
66
Vector<T, 2>
result((*
this
)(0, i), (*
this
)(1, i));
67
return
result;
68
}
69
70
template
<
typename
T>
71
DYN_FUNC
void
SquareMatrix<T, 2>::setRow
(
unsigned
int
i,
const
Vector<T, 2>
& vec)
72
{
73
data_
[0][i] = vec[0];
74
data_
[1][i] = vec[1];
75
}
76
77
template
<
typename
T>
78
DYN_FUNC
void
SquareMatrix<T, 2>::setCol
(
unsigned
int
j,
const
Vector<T, 2>
& vec)
79
{
80
data_
[j][0] = vec[0];
81
data_
[j][1] = vec[1];
82
}
83
84
template
<
typename
T>
85
DYN_FUNC
const
SquareMatrix<T, 2>
SquareMatrix<T, 2>::operator+
(
const
SquareMatrix<T, 2>
&mat2)
const
86
{
87
return
SquareMatrix<T, 2>
(*
this
) += mat2;
88
}
89
90
template
<
typename
T>
91
DYN_FUNC
SquareMatrix<T, 2>
&
SquareMatrix<T, 2>::operator+=
(
const
SquareMatrix<T, 2>
&mat2)
92
{
93
data_
+= mat2.data_;
94
return
*
this
;
95
}
96
97
template
<
typename
T>
98
DYN_FUNC
const
SquareMatrix<T, 2>
SquareMatrix<T, 2>::operator-
(
const
SquareMatrix<T, 2>
&mat2)
const
99
{
100
return
SquareMatrix<T, 2>
(*
this
) -= mat2;
101
}
102
103
template
<
typename
T>
104
DYN_FUNC
SquareMatrix<T, 2>
&
SquareMatrix<T, 2>::operator-=
(
const
SquareMatrix<T, 2>
&mat2)
105
{
106
data_
-= mat2.data_;
107
return
*
this
;
108
}
109
110
111
template
<
typename
T>
112
DYN_FUNC
SquareMatrix<T, 2>
&
SquareMatrix<T, 2>::operator=
(
const
SquareMatrix<T, 2>
&mat)
113
{
114
data_
= mat.data_;
115
return
*
this
;
116
}
117
118
template
<
typename
T>
119
DYN_FUNC
bool
SquareMatrix<T, 2>::operator==
(
const
SquareMatrix<T, 2>
&mat2)
const
120
{
121
return
data_
== mat2.data_;
122
}
123
124
template
<
typename
T>
125
DYN_FUNC
bool
SquareMatrix<T, 2>::operator!=
(
const
SquareMatrix<T, 2>
&mat2)
const
126
{
127
return
!((*this) == mat2);
128
}
129
130
template
<
typename
T>
131
DYN_FUNC
const
SquareMatrix<T, 2>
SquareMatrix<T, 2>::operator*
(
const
T
& scale)
const
132
{
133
return
SquareMatrix<T, 2>
(*
this
) *= scale;
134
}
135
136
template
<
typename
T>
137
DYN_FUNC
SquareMatrix<T, 2>
&
SquareMatrix<T, 2>::operator*=
(
const
T
& scale)
138
{
139
data_
*= scale;
140
return
*
this
;
141
}
142
143
template
<
typename
T>
144
DYN_FUNC
const
Vector<T, 2>
SquareMatrix<T, 2>::operator*
(
const
Vector<T, 2>
&vec)
const
145
{
146
Vector<T, 2>
result(0);
147
for
(
unsigned
int
i = 0; i < 2; ++i)
148
for
(
unsigned
int
j = 0; j < 2; ++j)
149
result[i] += (*
this
)(i, j) * vec[j];
150
return
result;
151
}
152
153
template
<
typename
T>
154
DYN_FUNC
const
SquareMatrix<T, 2>
SquareMatrix<T, 2>::operator*
(
const
SquareMatrix<T, 2>
&mat2)
const
155
{
156
return
SquareMatrix<T, 2>
(*
this
) *= mat2;
157
}
158
159
template
<
typename
T>
160
DYN_FUNC
SquareMatrix<T, 2>
&
SquareMatrix<T, 2>::operator*=
(
const
SquareMatrix<T, 2>
&mat2)
161
{
162
data_
*= mat2.data_;
163
return
*
this
;
164
}
165
166
template
<
typename
T>
167
DYN_FUNC
const
SquareMatrix<T, 2>
SquareMatrix<T, 2>::operator/
(
const
SquareMatrix<T, 2>
&mat2)
const
168
{
169
return
SquareMatrix<T, 2>
(*
this
) *= mat2.inverse();
170
}
171
172
template
<
typename
T>
173
DYN_FUNC
SquareMatrix<T, 2>
&
SquareMatrix<T, 2>::operator/=
(
const
SquareMatrix<T, 2>
&mat2)
174
{
175
data_
*= glm::inverse(mat2.data_);
176
return
*
this
;
177
}
178
179
template
<
typename
T>
180
DYN_FUNC
const
SquareMatrix<T, 2>
SquareMatrix<T, 2>::operator/
(
const
T
& scale)
const
181
{
182
return
SquareMatrix<T, 2>
(*
this
) /= scale;
183
}
184
185
template
<
typename
T>
186
DYN_FUNC
SquareMatrix<T, 2>
&
SquareMatrix<T, 2>::operator/=
(
const
T
& scale)
187
{
188
// #ifndef __CUDA_ARCH__
189
// if (abs(scale) <= std::numeric_limits<T>::epsilon())
190
// throw PhysikaException("Matrix Divide by zero error!");
191
// #endif
192
data_
/= scale;
193
return
*
this
;
194
}
195
196
template
<
typename
T>
197
DYN_FUNC
const
SquareMatrix<T, 2>
SquareMatrix<T, 2>::operator-
(
void
)
const
198
{
199
SquareMatrix<T, 2>
res;
200
res.data_ = -
data_
;
201
return
res;
202
}
203
204
template
<
typename
T>
205
DYN_FUNC
const
SquareMatrix<T, 2>
SquareMatrix<T, 2>::transpose
()
const
206
{
207
SquareMatrix<T, 2>
res;
208
res.data_ = glm::transpose(
data_
);
209
return
res;
210
}
211
212
template
<
typename
T>
213
DYN_FUNC
const
SquareMatrix<T, 2>
SquareMatrix<T, 2>::inverse
()
const
214
{
215
SquareMatrix<T, 2>
res;
216
res.data_ = glm::inverse(
data_
);
217
218
return
res;
219
}
220
221
template
<
typename
T>
222
DYN_FUNC
T
SquareMatrix<T, 2>::determinant
()
const
223
{
224
return
glm::determinant(
data_
);
225
}
226
227
template
<
typename
T>
228
DYN_FUNC
T
SquareMatrix<T, 2>::trace
()
const
229
{
230
return
(*
this
)(0, 0) + (*
this
)(1, 1);
231
}
232
233
template
<
typename
T>
234
DYN_FUNC
T
SquareMatrix<T, 2>::doubleContraction
(
const
SquareMatrix<T, 2>
&mat2)
const
235
{
236
T
result = 0;
237
for
(
unsigned
int
i = 0; i < 2; ++i)
238
for
(
unsigned
int
j = 0; j < 2; ++j)
239
result += (*
this
)(i, j)*mat2(i, j);
240
return
result;
241
}
242
243
template
<
typename
T>
244
DYN_FUNC
T
SquareMatrix<T, 2>::frobeniusNorm
()
const
245
{
246
T
result = 0;
247
for
(
unsigned
int
i = 0; i < 2; ++i)
248
for
(
unsigned
int
j = 0; j < 2; ++j)
249
result += (*
this
)(i, j)*(*
this
)(i, j);
250
return
glm::sqrt(result);
251
}
252
253
template
<
typename
T>
254
DYN_FUNC
T
SquareMatrix<T, 2>::oneNorm
()
const
255
{
256
const
SquareMatrix<T, 2>
& A = (*this);
257
const
T
sum1 = fabs(A(0, 0)) + fabs(A(1, 0));
258
const
T
sum2 = fabs(A(0, 1)) + fabs(A(1, 1));
259
T
maxSum = sum1;
260
if
(sum2 > maxSum)
261
maxSum = sum2;
262
return
maxSum;
263
}
264
265
template
<
typename
T>
266
DYN_FUNC
T
SquareMatrix<T, 2>::infNorm
()
const
267
{
268
const
SquareMatrix<T, 2>
& A = (*this);
269
const
T
sum1 = fabs(A(0, 0)) + fabs(A(0, 1));
270
const
T
sum2 = fabs(A(1, 0)) + fabs(A(1, 1));
271
T
maxSum = sum1;
272
if
(sum2 > maxSum)
273
maxSum = sum2;
274
return
maxSum;
275
}
276
277
template
<
typename
T>
278
DYN_FUNC
const
SquareMatrix<T, 2>
SquareMatrix<T, 2>::identityMatrix
()
279
{
280
return
SquareMatrix<T, 2>
(1.0, 0.0,
281
0.0, 1.0);
282
}
283
}
Vector.h
dyno::SquareMatrix< T, 2 >::SquareMatrix
DYN_FUNC SquareMatrix()
Definition
Matrix2x2.inl:9
dyno::SquareMatrix< T, 2 >::data_
glm::tmat2x2< T > data_
Definition
Matrix2x2.h:73
dyno::SquareMatrix::~SquareMatrix
~SquareMatrix()
Definition
SquareMatrix.h:11
dyno::SquareMatrix::SquareMatrix
SquareMatrix()
Definition
SquareMatrix.h:10
dyno::Vector
Definition
VectorBase.h:24
T
#define T(t)
dyno
This is an implementation of AdditiveCCD based on peridyno.
Definition
Array.h:25
Generated by
1.13.2