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