LBIBCell
 All Classes Functions Variables Friends Pages
EulerianPoint.hpp
1 /* Copyright (c) 2013 David Sichau <mail"at"sichau"dot"eu>
2  * 2013-2015 Simon Tanaka <tanakas"at"gmx"dot"ch>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 #ifndef EULERIANPOINT_HPP
23 #define EULERIANPOINT_HPP
24 
25 #include <LbmLib/include/Field.hpp>
26 #include <string>
27 #include <iostream>
28 #include <cmath>
29 namespace LbmLib {
30 namespace nodes {
35  public:
41  explicit EulerianPoint(
42  int x,
43  int y);
44 
48  virtual ~EulerianPoint() {}
49 
54  int getXPos() const;
55 
60  int getYPos() const;
61 
66  Field<int> getPos() const;
67 
72  virtual std::string getType() const = 0;
73 
74  private:
78  const Field<int> position_;
79 };
80 
81 
88 template <typename Point1, typename Point2>
89 double getSquaredDistance(
90  const Point1& pt1,
91  const Point2& pt2) {
92  return (
93  (pt1.getXPos() - pt2.getXPos()) * (pt1.getXPos() - pt2.getXPos()) +
94  (pt1.getYPos() - pt2.getYPos()) * (pt1.getYPos() - pt2.getYPos())
95  );
96 }
97 
104 template <typename Point1, typename Point2>
105 double getDistance(
106  const Point1& pt1,
107  const Point2& pt2) {
108  return std::sqrt(getSquaredDistance(pt1, pt2));
109 }
110 
117 template <typename Point1, typename Point2>
118 Field<double> getDistanceField(
119  const Point1& pt1,
120  const Point2& pt2) {
121  return Field<double>(pt2.getXPos() - pt1.getXPos(),
122  pt2.getYPos() - pt1.getYPos());
123 }
124 
132 std::ostream& operator<<(
133  std::ostream& ostr,
134  const EulerianPoint* pt);
135 
144 template <typename Pt1, typename Pt2, typename Pt3, typename Pt4>
145 bool isPointInTriangle(
146  const Pt1& pt1,
147  const Pt2& pt2,
148  const Pt3& pt3,
149  const Pt4& pt4) {
150  // Barycentric coordinate system
151  double lambda1 =
152  ((pt2.getYPos() - pt3.getYPos()) * (pt4.getXPos() - pt3.getXPos()) +
153  (pt3.getXPos() -
154  pt2.getXPos()) * (pt4.getYPos() - pt3.getYPos())) /
155  ((pt2.getYPos() - pt3.getYPos()) * (pt1.getXPos() - pt3.getXPos()) +
156  (pt3.getXPos() - pt2.getXPos()) * (pt1.getYPos() - pt3.getYPos()));
157  double lambda2 =
158  ((pt3.getYPos() - pt1.getYPos()) * (pt4.getXPos() - pt3.getXPos()) +
159  (pt1.getXPos() -
160  pt3.getXPos()) * (pt4.getYPos() - pt3.getYPos())) /
161  ((pt2.getYPos() - pt3.getYPos()) * (pt1.getXPos() - pt3.getXPos()) +
162  (pt3.getXPos() - pt2.getXPos()) * (pt1.getYPos() - pt3.getYPos()));
163  double lambda3 = 1 - lambda1 - lambda2;
164 
165  if ((lambda1 <= 0) || (lambda2 <= 0) || (lambda3 <= 0) || (lambda1 >= 1) ||
166  (lambda2 >= 1) || (lambda3 >= 1) ) {
167  return false;
168  }
169  return true;
170 }
171 } // end namespace
172 } // end namespace
173 #endif // EULERIANPOINT_HPP
The EulerianPoint class The base class for all points with an integer position and no speed...
EulerianPoint(int x, int y)
EulerianPoint Constructs a new EulerianPoint.
virtual std::string getType() const =0
getType The type of a node class
int getXPos() const
getXPos Getter for the X position
Field< int > getPos() const
getPos Getter for the pos
virtual ~EulerianPoint()
~Point vitual Destructor
int getYPos() const
getYPos Getter for the Y position