00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef OPM_POINT2D_HEADER_INCLUDED
00021 #define OPM_POINT2D_HEADER_INCLUDED
00022
00023 namespace Opm {
00024
00025
00026
00027 namespace detail {
00028
00029
00030 class Point2D
00031 {
00032 public:
00033 Point2D(const double xi, const double yi)
00034 : x_(xi),
00035 y_(yi) {
00036
00037 }
00038
00039 Point2D()
00040 {
00041 }
00042
00043 double getX() const
00044 {
00045 return x_;
00046 }
00047
00048 double getY() const
00049 {
00050 return y_;
00051 }
00052
00053 void setX(const double x)
00054 {
00055 x_ = x;
00056 }
00057
00058 void setY(const double y)
00059 {
00060 y_ = y;
00061 }
00062
00065 static bool findIntersection(Point2D line_segment1[2], Point2D line2[2], Point2D& intersection_point)
00066 {
00067
00068 const double x1 = line_segment1[0].getX();
00069 const double y1 = line_segment1[0].getY();
00070 const double x2 = line_segment1[1].getX();
00071 const double y2 = line_segment1[1].getY();
00072
00073 const double x3 = line2[0].getX();
00074 const double y3 = line2[0].getY();
00075 const double x4 = line2[1].getX();
00076 const double y4 = line2[1].getY();
00077
00078 const double d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
00079
00080 if (d == 0.) {
00081 return false;
00082 }
00083
00084 const double x = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d;
00085 const double y = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d;
00086
00087 if (x >= std::min(x1,x2) && x <= std::max(x1,x2)) {
00088 intersection_point.setX(x);
00089 intersection_point.setY(y);
00090 return true;
00091 } else {
00092 return false;
00093 }
00094 }
00095
00096 private:
00097 double x_;
00098 double y_;
00099
00100 };
00101
00102
00103 }
00104
00105
00106
00107 }
00108
00109 #endif // OPM_POINT2D_HEADER_INCLUDED
00110