17 #ifndef GZ_MATH_LINE2_HH_
18 #define GZ_MATH_LINE2_HH_
22 #include <gz/math/config.hh>
27 inline namespace GZ_MATH_VERSION_NAMESPACE {
40 this->Set(_ptA, _ptB);
48 public:
Line2(
double _x1,
double _y1,
double _x2,
double _y2)
50 this->Set(_x1, _y1, _x2, _y2);
68 public:
void Set(
double _x1,
double _y1,
double _x2,
double _y2)
70 this->pts[0].Set(_x1, _y1);
71 this->pts[1].Set(_x2, _y2);
82 return (this->pts[0].X() - this->pts[1].X()) *
83 (_line[0].Y() -_line[1].Y()) -
84 (this->pts[0].Y() - this->pts[1].Y()) *
85 (_line[0].X() - _line[1].X());
95 return (_pt.
Y() - this->pts[0].Y()) *
96 (this->pts[1].X() - this->pts[0].X()) -
97 (_pt.
X() - this->pts[0].X()) *
98 (this->pts[1].Y() - this->pts[0].Y());
108 double _epsilon = 1e-6)
const
122 double _epsilon = 1e-6)
const
136 double _epsilon = 1e-6)
const
138 return this->Parallel(_line, _epsilon) &&
139 this->Intersect(_line, _epsilon);
148 double _epsilon = 1e-6)
const
150 return this->Collinear(_pt, _epsilon) && this->Within(_pt, _epsilon);
161 double _epsilon = 1e-6)
const
163 return _pt.
X() <=
std::max(this->pts[0].X(),
164 this->pts[1].X()) + _epsilon &&
166 this->pts[1].X()) - _epsilon &&
168 this->pts[1].Y()) + _epsilon &&
170 this->pts[1].Y()) - _epsilon;
179 double _epsilon = 1e-6)
const
182 return this->Intersect(_line, ignore, _epsilon);
194 double _epsilon = 1e-6)
const
196 double d = this->CrossProduct(_line);
203 if (this->Within(_line[0], _epsilon))
209 else if (this->Within(_line[1], _epsilon))
219 _pt.
X((_line[0].X() - _line[1].X()) *
220 (this->pts[0].X() * this->pts[1].Y() -
221 this->pts[0].Y() * this->pts[1].X()) -
222 (this->pts[0].X() - this->pts[1].X()) *
223 (_line[0].X() * _line[1].Y() - _line[0].Y() * _line[1].X()));
225 _pt.
Y((_line[0].Y() - _line[1].Y()) *
226 (this->pts[0].X() * this->pts[1].Y() -
227 this->pts[0].Y() * this->pts[1].X()) -
228 (this->pts[0].Y() - this->pts[1].Y()) *
229 (_line[0].X() * _line[1].Y() - _line[0].Y() * _line[1].X()));
233 if (_pt.
X() <
std::min(this->pts[0].X(), this->pts[1].X()) ||
234 _pt.
X() >
std::max(this->pts[0].X(), this->pts[1].X()) ||
235 _pt.
X() <
std::min(_line[0].X(), _line[1].X()) ||
236 _pt.
X() >
std::max(_line[0].X(), _line[1].X()))
241 if (_pt.
Y() <
std::min(this->pts[0].Y(), this->pts[1].Y()) ||
242 _pt.
Y() >
std::max(this->pts[0].Y(), this->pts[1].Y()) ||
243 _pt.
Y() <
std::min(_line[0].Y(), _line[1].Y()) ||
244 _pt.
Y() >
std::max(_line[0].Y(), _line[1].Y()))
256 return sqrt((this->pts[0].X() - this->pts[1].X()) *
257 (this->pts[0].X() - this->pts[1].X()) +
258 (this->pts[0].Y() - this->pts[1].Y()) *
259 (this->pts[0].Y() - this->pts[1].Y()));
266 if (
math::equal(this->pts[1].X(), this->pts[0].X()))
269 return (this->pts[1].Y() - this->pts[0].Y()) /
270 static_cast<double>(this->pts[1].X() - this->pts[0].X());
278 return this->pts[0] == _line[0] && this->pts[1] == _line[1];
286 return !(*
this == _line);
304 _out << _line[0] <<
" " << _line[1];