Flow123d  release_2.2.0-914-gf1a3a4f
plain.cpp
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file plain.cpp
15  * @brief
16  */
17 
18 #include "mesh/ngh/include/plain.h"
21 
22 using namespace mathfce;
23 namespace ngh {
24 
25 int TPlain::numberInstance = 0;
26 
27 int TPlain::generateId() {
28  return TPlain::numberInstance++;
29 }
30 
31 TPlain::TPlain() {
32  id = generateId();
33 
34  U = new TVector(0, 0, 0);
35  V = new TVector(0, 0, 0);
36  N = new TVector(0, 0, 0);
37  X = new TPoint(0, 0, 0);
38 
39  Compute();
40 }
41 
42 TPlain::TPlain(const TVector &UU, const TVector &VV, const TPoint &XX) {
43  id = generateId();
44 
45  U = new TVector(UU);
46  V = new TVector(VV);
47  N = new TVector(0, 0, 0);
48  X = new TPoint(XX);
49 
50  Compute();
51 }
52 
53 TPlain::TPlain(const TPoint &P1, const TPoint &P2, const TPoint &P3) {
54  id = generateId();
55 
56  U = new TVector(P1, P2);
57  V = new TVector(P1, P3);
58  N = new TVector(0, 0, 0);
59  X = new TPoint(P1);
60 
61  Compute();
62 }
63 
64 TPlain::TPlain(const TPlain &p) {
65  id = generateId();
66 
67  N = new TVector();
68  U = new TVector();
69  V = new TVector();
70  X = new TPoint();
71 
72  a = p.a;
73  b = p.b;
74  c = p.c;
75  d = p.d;
76 
77  *N = *p.N;
78  *U = *p.U;
79  *V = *p.V;
80  *X = *p.X;
81 }
82 
83 void TPlain::Compute() {
84  *N = Cross(*U, *V);
85  a = N->X1();
86  b = N->X2();
87  c = N->X3();
88  d = -a * X->X() - b * X->Y() - c * X->Z();
89  return;
90 }
91 
92 TPlain::~TPlain() {
93  delete U;
94  delete V;
95  delete N;
96  delete X;
97 }
98 
99 double TPlain::GetA() const {
100  return a;
101 }
102 
103 double TPlain::GetB() const {
104  return b;
105 }
106 
107 double TPlain::GetC() const {
108  return c;
109 }
110 
111 double TPlain::GetD() const {
112  return d;
113 }
114 
115 const TVector &TPlain::GetNormal() const {
116  return *N;
117 }
118 
119 const TVector &TPlain::GetU() const {
120  return *U;
121 }
122 
123 const TVector &TPlain::GetV() const {
124  return *V;
125 }
126 
127 const TPoint &TPlain::GetPoint() const {
128  return *X;
129 }
130 
131 TPoint TPlain::GetPoint(double r, double s) const {
132  TPoint tmp;
133  tmp = r * *U + s * *V + *X;
134  return tmp;
135 }
136 
137 bool TPlain::Belong(const TPoint &P) const {
138  if (IsZero(Distance(*this, P)))
139  return true;
140  return false;
141 }
142 
143 TPlain & TPlain::operator =(const TPlain &p) {
144  a = p.a;
145  b = p.b;
146  c = p.c;
147  d = p.d;
148  *(*this).U = *p.U;
149  *(*this).V = *p.V;
150  *(*this).N = *p.N;
151  *(*this).X = *p.X;
152  return *this;
153 }
154 
155 void TPlain::SetPoints(const TPoint &P1, const TPoint &P2, const TPoint &P3) {
156  *U = (TPoint) P2 - P1;
157  *V = (TPoint) P3 - P1;
158  *X = P1;
159  Compute();
160 }
161 
162 } //namespace ngh
TVector * V
Definition: plain.h:33
TPoint * X
Definition: plain.h:41
double c
Definition: plain.h:38
Definition: abscissa.h:25
double b
Definition: plain.h:37
bool IsZero(double)
Definition: mathfce.cpp:22
TVector * N
Definition: plain.h:34
double Distance(const TBisector &, const TPoint &)
double d
Definition: plain.h:39
TVector * U
Definition: plain.h:32
double a
Definition: plain.h:36
TVector Cross(const TVector &, const TVector &)
Definition: vector.cpp:182