Flow123d
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
flow123d
src
mesh
ngh
src
vector.cpp
Go to the documentation of this file.
1
#include <cmath>
2
#include "
mesh/ngh/include/point.h
"
3
#include "
mesh/ngh/include/myvector.h
"
4
//#include <math.h>
5
#include "
mesh/ngh/include/mathfce.h
"
6
7
using namespace
mathfce;
8
9
//double epsilon = 1e-6;
10
11
int
TVector::numberInstance
= 0;
12
13
int
TVector::generateId
() {
14
return
TVector::numberInstance
++;
15
}
16
17
TVector::TVector
() {
18
id
= generateId();
19
20
coors[ 0 ] = 0;
21
coors[ 1 ] = 0;
22
coors[ 2 ] = 0;
23
24
Compute();
25
}
26
27
TVector::TVector
(
double
xx1,
double
xx2,
double
xx3) {
28
id
= generateId();
29
30
coors[ 0 ] = xx1;
31
coors[ 1 ] = xx2;
32
coors[ 2 ] = xx3;
33
34
Compute();
35
}
36
37
TVector::TVector
(
TPoint
P1,
TPoint
P2) {
38
id
= generateId();
39
40
coors[ 0 ] = P2.
X
() - P1.
X
();
41
coors[ 1 ] = P2.
Y
() - P1.
Y
();
42
coors[ 2 ] = P2.
Z
() - P1.
Z
();
43
44
Compute();
45
}
46
47
TVector::TVector
(
const
TVector
&x)
48
{
49
id
= generateId();
50
51
coors[0]=x.
coors
[0];
52
coors[1]=x.
coors
[1];
53
coors[2]=x.
coors
[2];
54
55
Compute();
56
}
57
58
TVector::~TVector
() {
59
;
60
}
61
62
void
TVector::Compute
() {
63
CompLength();
64
}
65
66
void
TVector::CompLength
() {
67
length = sqrt(pow(this->coors[ 0 ], 2.0) + pow(this->coors[ 1 ], 2.0) + pow(this->coors[ 2 ], 2.0));
68
}
69
70
TVector
&
TVector::operator =
(
const
TPoint
&P) {
71
this->coors[ 0 ] = P.
X
();
72
this->coors[ 1 ] = P.
Y
();
73
this->coors[ 2 ] = P.
Z
();
74
75
Compute();
76
77
return
*
this
;
78
}
79
80
TVector
TVector::operator +
(
const
TVector
&V) {
81
TVector
res(0, 0, 0);
82
83
for
(
int
i = 0; i < 3; i++) {
84
res.
coors
[ i ] = coors[i] + V.
coors
[ i ];
85
}
86
87
res.
Compute
();
88
89
return
res;
90
}
91
92
TVector
TVector::operator +
(
const
TPoint
&P) {
93
TVector
res(0, 0, 0);
94
95
for
(
int
i = 0; i < 3; i++) {
96
res.
coors
[ i ] = coors[i] + P.
Get
(i + 1);
97
}
98
99
res.
Compute
();
100
101
return
res;
102
}
103
104
TVector
TVector::operator -
(
const
TVector
&V) {
105
TVector
res(0, 0, 0);
106
107
for
(
int
i = 0; i < 3; i++) {
108
res.
coors
[ i ] = coors[i] - V.
coors
[ i ];
109
}
110
111
res.
Compute
();
112
113
return
res;
114
}
115
116
void
TVector::SetVector
(
double
xx1,
double
xx2,
double
xx3) {
117
coors[ 0 ] = xx1;
118
coors[ 1 ] = xx2;
119
coors[ 2 ] = xx3;
120
Compute();
121
}
122
123
TVector
operator *
(
const
TVector
&U,
double
x) {
124
TVector
tmp;
125
tmp.
SetVector
(U.
X1
() * x, U.
X2
() * x, U.
X3
() * x);
126
return
tmp;
127
}
128
129
TVector
operator *
(
double
x,
const
TVector
&U) {
130
TVector
tmp;
131
tmp.
SetVector
(U.
X1
() * x, U.
X2
() * x, U.
X3
() * x);
132
return
tmp;
133
}
134
135
bool
TVector::IsZero
() {
136
if
(!
mathfce::IsZero
(length)) {
137
return
false
;
138
}
else
{
139
return
true
;
140
}
141
}
142
143
double
TVector::Length
()
const
{
144
return
length;
145
}
146
147
void
TVector::Get
(
double
&xx1,
double
&xx2,
double
&xx3)
const
{
148
xx1 = coors[ 0 ];
149
xx2 = coors[ 1 ];
150
xx3 = coors[ 2 ];
151
return
;
152
}
153
154
void
TVector::Get
(
double
*U)
const
{
155
for
(
int
i = 0; i < 3; i++) {
156
U[ i ] = coors[ i ];
157
}
158
159
return
;
160
}
161
162
double
TVector::Get
(
int
i)
const
{
163
return
coors[ i - 1 ];
164
}
165
166
TVector
Cross
(
const
TVector
&U,
const
TVector
&V) {
167
double
x1, x2, x3;
168
double
u1, u2, u3;
169
double
v1, v2, v3;
170
171
U.
Get
(u1, u2, u3);
172
V.
Get
(v1, v2, v3);
173
174
x1 = u2 * v3 - u3 * v2;
175
x2 = u3 * v1 - u1 * v3;
176
x3 = u1 * v2 - u2 * v1;
177
178
TVector
X(x1, x2, x3);
179
180
return
X;
181
}
182
183
double
Dot
(
const
TVector
&U,
const
TVector
&V) {
184
double
u1, u2, u3;
185
double
v1, v2, v3;
186
187
U.
Get
(u1, u2, u3);
188
V.
Get
(v1, v2, v3);
189
190
double
product = u1 * v1 + u2 * v2 + u3 * v3;
191
192
return
product;
193
}
194
195
bool
TVector::operator ==
(
const
TVector
&U) {
196
for
(
int
i = 0; i < 3; i++) {
197
if
((fabs(coors[ i ]) - fabs(U.
coors
[ i ])) >
epsilon
) {
198
return
false
;
199
}
200
}
201
return
true
;
202
}
203
204
double
TVector::X1
()
const
{
205
return
coors[ 0 ];
206
}
207
208
double
TVector::X2
()
const
{
209
return
coors[ 1 ];
210
}
211
212
double
TVector::X3
()
const
{
213
return
coors[ 2 ];
214
}
215
216
bool
AreParallel
(
const
TVector
&U,
const
TVector
&V) {
217
// if vector W is zero, then these two bisectors are parallel or same
218
/* TVector W;
219
W = (TVector)U - Dot(U, V) / Dot(V, V) * V;
220
if (W.IsZero())
221
return true;
222
else
223
return false;*/
224
TVector
W;
225
W =
Cross
(U, V);
226
if
((W.
Length
() <
epsilon
* 1 * U.
Length
())
227
|| (W.
Length
() <
epsilon
* 1 * V.
Length
())) {
228
return
true
;
229
}
else
{
230
return
false
;
231
}
232
}
233
234
bool
ArePerpendicular
(
const
TVector
&U,
const
TVector
&V) {
235
double
x =
Dot
(U, V) / (U.
Length
() * V.
Length
());
236
return
IsZero
(x);
237
}
Generated on Thu May 29 2014 23:14:49 for Flow123d by
1.8.4