Flow123d  release_2.2.0-914-gf1a3a4f
bisector.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 bisector.cpp
15  * @brief
16  */
17 
18 #include <iostream>
19 
20 #include "system/global_defs.h"
21 #include "mesh/element_impls.hh"
22 
26 
27 using namespace mathfce;
28 namespace ngh {
29 
30 int TBisector::numberInstance = 0;
31 
32 int TBisector::generateId() {
33  return TBisector::numberInstance++;
34 }
35 
36 TBisector::TBisector() {
37  id = generateId();
38 
39  X0 = new TPoint(0, 0, 0);
40  U = new TVector(0, 0, 0);
41 }
42 
43 TBisector::TBisector(const TPoint &XX0, const TVector &UU) {
44  id = generateId();
45 
46  X0 = new TPoint(XX0);
47  U = new TVector(UU);
48 }
49 
50 TBisector::TBisector(const TPoint &P0, const TPoint &P1) {
51  id = generateId();
52 
53  X0 = new TPoint(P0);
54  U = new TVector(P0, P1);
55 }
56 
57 TBisector::TBisector(const Element & ele) {
58  id = generateId();
59  OLD_ASSERT_EQUAL(ele.dim(), 1);
60 
61  X0 = new TPoint(ele.node[0]->point()(0), ele.node[0]->point()(1), ele.node[0]->point()(2));
62  U = new TVector(*X0, TPoint(ele.node[1]->point()(0), ele.node[1]->point()(1), ele.node[1]->point()(2)) );
63 }
64 
65 TBisector::TBisector(const TBisector &x)
66 {
67  id = generateId();
68 
69  X0 = new TPoint(*(x.X0));
70  U = new TVector(*(x.U));
71 }
72 
73 TBisector::~TBisector() {
74  delete X0;
75  delete U;
76 }
77 
78 TBisector & TBisector::operator =(const TBisector &b) {
79  *(*this).U = *b.U;
80  *(*this).X0 = *b.X0;
81 
82  return *this;
83 }
84 
85 std::ostream & operator <<(std::ostream &stream, const TBisector &b) {
86  stream << "U = (" << b.U->X1() << ", " << b.U->X2() << ", " << b.U->X3() << ")\n";
87  stream << "X0 = [" << b.X0->X() << ", " << b.X0->Y() << ", " << b.X0->Z() << "]\n";
88 
89  return stream;
90 }
91 
92 void TBisector::SetPoint(const TPoint &P) {
93  *X0 = P;
94 }
95 
96 void TBisector::SetVector(const TVector &UU) {
97  *U = UU;
98 }
99 
100 void TBisector::SetPoints(const TPoint &P0, const TPoint &P1) {
101  *X0 = P0;
102  *U = (TPoint) P1 - P0;
103 }
104 
105 const TVector &TBisector::GetVector() const {
106 
107  return *(this->U);
108 }
109 
110 const TPoint &TBisector::GetPoint() const
111 {
112  return *(this->X0);
113 }
114 
115 TPoint TBisector::GetPoint(double t) const {
116  TPoint tmp;
117 
118  tmp.SetCoord(t * *U);
119  tmp = tmp + *X0;
120 
121  return tmp;
122 }
123 
124 void TBisector::GetParameter(const TPoint &P, double &t, bool &onBisector) const {
125  t = (P.X() - X0->X()) / U->X1();
126  onBisector = (fabs( (P.Y() - X0->Y()) / U->X2() - t ) < epsilon) & (fabs( (P.Z() - X0->Z()) / U->X3() - t ) < epsilon);
127 }
128 
129 bool TBisector::Belong(const TPoint &P) const {
130  if (IsZero(Distance(*this, P))) {
131  return true;
132  } else {
133  return false;
134  }
135 }
136 
137 } //namespace ngh
TVector * U
Definition: bisector.h:37
Definition: abscissa.h:25
Node ** node
Definition: elements.h:90
double Y() const
Definition: point.cpp:115
bool IsZero(double)
Definition: mathfce.cpp:22
double X2() const
Definition: vector.cpp:224
unsigned int dim() const
Global macros to enhance readability and debugging, general constants.
double Distance(const TBisector &, const TPoint &)
double X3() const
Definition: vector.cpp:228
double X() const
Definition: point.cpp:111
double Z() const
Definition: point.cpp:119
const double epsilon
Definition: mathfce.h:23
std::ostream & operator<<(std::ostream &stream, const TBisector &b)
Definition: bisector.cpp:85
void SetCoord(double, double, double)
Definition: point.cpp:99
TPoint * X0
Definition: bisector.h:36
#define OLD_ASSERT_EQUAL(a, b)
Definition: global_defs.h:133
arma::vec3 & point()
Definition: nodes.hh:68
double X1() const
Definition: vector.cpp:220