Point2D.hpp
Go to the documentation of this file.
1/*
2 Copyright 2015 Statoil ASA.
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef OPM_POINT2D_HEADER_INCLUDED
21#define OPM_POINT2D_HEADER_INCLUDED
22
23namespace Opm {
24
25
26
27 namespace detail {
28
29
30 class Point2D
31 {
32 public:
33 Point2D(const double xi, const double yi)
34 : x_(xi),
35 y_(yi) {
36
37 }
38
40 {
41 }
42
43 double getX() const
44 {
45 return x_;
46 }
47
48 double getY() const
49 {
50 return y_;
51 }
52
53 void setX(const double x)
54 {
55 x_ = x;
56 }
57
58 void setY(const double y)
59 {
60 y_ = y;
61 }
62
65 static bool findIntersection(Point2D line_segment1[2], Point2D line2[2], Point2D& intersection_point)
66 {
67
68 const double x1 = line_segment1[0].getX();
69 const double y1 = line_segment1[0].getY();
70 const double x2 = line_segment1[1].getX();
71 const double y2 = line_segment1[1].getY();
72
73 const double x3 = line2[0].getX();
74 const double y3 = line2[0].getY();
75 const double x4 = line2[1].getX();
76 const double y4 = line2[1].getY();
77
78 const double d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
79
80 if (d == 0.) {
81 return false;
82 }
83
84 const double x = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d;
85 const double y = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d;
86
87 if (x >= std::min(x1,x2) && x <= std::max(x1,x2)) {
88 intersection_point.setX(x);
89 intersection_point.setY(y);
90 return true;
91 } else {
92 return false;
93 }
94 }
95
96 private:
97 double x_;
98 double y_;
99
100 }; // class Point2D
101
102
103 } // namespace detail
104
105
106
107} // namespace Opm
108
109#endif // OPM_POINT2D_HEADER_INCLUDED
110
Definition: Point2D.hpp:31
double getY() const
Definition: Point2D.hpp:48
Point2D(const double xi, const double yi)
Definition: Point2D.hpp:33
double getX() const
Definition: Point2D.hpp:43
void setY(const double y)
Definition: Point2D.hpp:58
Point2D()
Definition: Point2D.hpp:39
void setX(const double x)
Definition: Point2D.hpp:53
static bool findIntersection(Point2D line_segment1[2], Point2D line2[2], Point2D &intersection_point)
Definition: Point2D.hpp:65
Definition: CompressibleTpfaPolymer.hpp:33