Point.cpp
Go to the documentation of this file.
1 //=============================================================================
2 // Copyright (C) 2021-2024 Wageningen University - All Rights Reserved
3 // Author: Gonzalo Mier
4 // BSD-3 License
5 //=============================================================================
6 
8 
9 namespace f2c::types {
10 
12 
13 Point::Point(double _x, double _y, double _z) : Geometry() {
14  this->data_->setX(_x);
15  this->data_->setY(_y);
16  this->data_->setZ(_z);
17 }
18 
19 Point::Point(const Point& p) : Geometry(p.clone()) {}
20 Point::Point(Point&& p) = default;
21 Point::~Point() = default;
22 
24  this->setX(p.X());
25  this->setY(p.Y());
26  this->setZ(p.Z());
27  return *this;
28 }
29 
31  this->setX(p.X());
32  this->setY(p.Y());
33  this->setZ(p.Z());
34  return *this;
35 }
36 
37 std::ostream& operator<<(std::ostream& os, const Point& p) {
38  os << "Point(" << p.X() << ", " << p.Y() << ", " << p.Z() << ")";
39  return os;
40 }
41 
42 bool Point::operator==(const Point& b) const {
43  return (fabs(this->X() - b.X()) < 1e-7) && \
44  (fabs(this->Y() - b.Y()) < 1e-7) && \
45  (fabs(this->Z() - b.Z()) < 1e-7);
46 }
47 
48 bool Point::operator!=(const Point& b) const {
49  return !(this->operator==(b));
50 }
51 
52 bool Point::operator<(const Point& b) const {
53  return ((this->X() < b.X()) ||
54  ((this->X() == b.X()) && (this->Y() < b.Y())));
55 }
56 
57 Point Point::operator+(const Point& b) const {
58  return Point(X() + b.X(), Y() + b.Y(), Z() + b.Z());
59 }
60 
61 Point Point::operator-(const Point& b) const {
62  return Point(X() - b.X(), Y() - b.Y(), Z() - b.Z());
63 }
64 
66  data_->setX(this->X() * b);
67  data_->setY(this->Y() * b);
68  data_->setZ(this->Z() * b);
69  return *this;
70 }
71 
72 Point Point::operator*(double b) const {
73  return Point(X() * b, Y() * b, Z() * b);
74 }
75 
76 double Point::operator*(const Point& b) const {
77  return X() * b.X() + Y() * b.Y() + Z() * b.Z();
78 }
79 
80 Point Point::operator/(double b) const {
81  return Point(X() / b, Y() / b, Z() / b);
82 }
83 
84 double Point::det(const Point& u, const Point& v) {
85  return u.X() * v.Y() - u.Y() * v.X();
86 }
87 
89  return Point(this->X(), this->Y(), this->Z());
90 }
91 
92 double Point::X() const {return data_->getX();}
93 double Point::Y() const {return data_->getY();}
94 double Point::Z() const {return data_->getZ();}
95 double Point::getX() const {return data_->getX();}
96 double Point::getY() const {return data_->getY();}
97 double Point::getZ() const {return data_->getZ();}
98 
99 void Point::setX(double x) {data_->setX(x);}
100 void Point::setY(double y) {data_->setY(y);}
101 void Point::setZ(double z) {data_->setZ(z);}
102 
103 void Point::setPoint(double x, double y, double z) {
104  data_->setX(x);
105  data_->setY(y);
106  data_->setZ(z);
107 }
108 
109 void Point::setPoint(const OGRPoint& p) {
110  data_->setX(p.getX());
111  data_->setY(p.getY());
112  data_->setZ(p.getZ());
113 }
114 
115 void Point::setPoint(const Point& p) {
116  data_->setX(p.X());
117  data_->setY(p.Y());
118  data_->setZ(p.Z());
119 }
120 
121 Point Point::rotateFromPoint(double angle, const Point& p_r) const {
122  const double s = sin(angle);
123  const double c = cos(angle);
124  double x = this->X();
125  double y = this->Y();
126  double p_x = p_r.X() - x;
127  double p_y = p_r.Y() - y;
128  return Point(p_x * c - p_y * s + x,
129  p_x * s + p_y * c + y);
130 }
131 
132 double Point::getAngleFromPoints(const Point& end) const {
133  return mod_2pi(atan2(det(*this, end), *this * end));
134 }
135 
136 double Point::getAngleFromPoint() const {
137  return Point(1.0, 0.0).getAngleFromPoints(*this);
138 }
139 
141  const Point& p1, const Point& p2, const Point& p3) {
143 }
144 
145 Point Point::getPointFromAngle(double angle, double dist) const {
146  return Point(X() + dist * cos(angle), Y() + dist * sin(angle));
147 }
148 
150  const Point& start, const Point& end) const {
151  Point this2start {start - *this};
152  Point end2start {end - start};
153  return -det(end2start, this2start) / sqrt(end2start * end2start);
154 }
155 
156 
158  const Point& l1_s, const Point& l1_e,
159  const Point& l2_s, const Point& l2_e) {
160  double den = det(l1_e - l1_s, l2_e - l2_s);
161  if (den == 0) {
162  return l1_s;
163  }
164  double det1 = det(l1_e, l1_s);
165  double det2 = det(l2_e, l2_s);
166  return ((l2_e - l2_s) * det1 - (l1_e - l1_s) * det2) / den;
167 }
168 
170  const Point& seg_s, const Point& seg_e) const {
171  Point v = seg_e - seg_s;
172  Point u = seg_s - *this;
173  double t = -(v * u) / (v * v);
174  return v * std::max(0.0, std::min(1.0, t)) + seg_s;
175 }
176 
177 } // namespace f2c::types
178 
f2c::types::Point::setZ
void setZ(double z)
Definition: Point.cpp:101
f2c::types::operator<<
std::ostream & operator<<(std::ostream &os, const Point &p)
Definition: Point.cpp:37
f2c::types::Point::getZ
double getZ() const
Definition: Point.cpp:97
1_basic_types.p1
p1
Definition: 1_basic_types.py:11
Point.h
f2c::types
Types used by fields2cover library.
Definition: Cell.h:20
f2c::types::Geometry
Definition: Geometry.h:26
f2c::types::Point::operator-
Point operator-(const Point &b) const
Definition: Point.cpp:61
1_basic_types.p3
p3
Definition: 1_basic_types.py:22
f2c::types::Point::operator+
Point operator+(const Point &b) const
Definition: Point.cpp:57
f2c::types::Point::operator<
bool operator<(const Point &b) const
Definition: Point.cpp:52
1_basic_types.end
end
Definition: 1_basic_types.py:76
f2c::types::Point::intersectionOfLines
static Point intersectionOfLines(const Point &l1_s, const Point &l1_e, const Point &l2_s, const Point &l2_e)
Definition: Point.cpp:157
f2c::types::Point::closestPointInSegment
Point closestPointInSegment(const Point &seg_s, const Point &seg_e) const
Definition: Point.cpp:169
f2c::types::Point::Z
double Z() const
Definition: Point.cpp:94
f2c::types::Point::operator==
bool operator==(const Point &b) const
Definition: Point.cpp:42
f2c::types::Point::Y
double Y() const
Definition: Point.cpp:93
f2c::types::Point::setX
void setX(double x)
Definition: Point.cpp:99
f2c::types::Point::operator*
Point operator*(double b) const
Definition: Point.cpp:72
f2c::types::Point::rotateFromPoint
Point rotateFromPoint(double angle, const Point &p_r) const
Definition: Point.cpp:121
1_basic_types.p2
p2
Definition: 1_basic_types.py:15
f2c::types::Point::Point
Point()
Definition: Point.cpp:11
f2c::types::Point::X
double X() const
Definition: Point.cpp:92
f2c::types::Point::operator*=
Point & operator*=(double b)
Definition: Point.cpp:65
f2c::types::Point::clone
Point clone() const
Definition: Point.cpp:88
f2c::types::Point::setPoint
void setPoint(double x, double y, double z=0)
Definition: Point.cpp:103
f2c::types::Point::operator!=
bool operator!=(const Point &b) const
Definition: Point.cpp:48
f2c::types::Point::getAngleFromPoints
double getAngleFromPoints(const Point &end) const
Definition: Point.cpp:132
f2c::types::Point::operator/
Point operator/(double b) const
Definition: Point.cpp:80
f2c::types::Point::signedDistance2Segment
double signedDistance2Segment(const Point &start, const Point &end) const
Definition: Point.cpp:149
f2c::types::Geometry< OGRPoint, wkbPoint >::mod_2pi
static double mod_2pi(double val)
Definition: Geometry_impl.hpp:174
f2c::types::Point
Definition: Point.h:21
f2c::types::Point::setY
void setY(double y)
Definition: Point.cpp:100
f2c::types::Point::operator=
Point & operator=(const Point &)
Definition: Point.cpp:30
f2c::types::Geometry< OGRPoint, wkbPoint >::data_
std::shared_ptr< OGRPoint > data_
Definition: Geometry.h:129
f2c::types::Point::getAngleFromPoint
double getAngleFromPoint() const
Definition: Point.cpp:136
f2c::types::Point::getY
double getY() const
Definition: Point.cpp:96
f2c::types::Point::getX
double getX() const
Definition: Point.cpp:95
f2c::types::Point::~Point
~Point()
f2c::types::Point::det
static double det(const Point &u, const Point &v)
Definition: Point.cpp:84
f2c::types::Point::getPointFromAngle
Point getPointFromAngle(double angle, double dist) const
Definition: Point.cpp:145


fields2cover
Author(s):
autogenerated on Fri Apr 25 2025 02:18:31