17 #ifndef _IGNITION_LINE3_HH_
18 #define _IGNITION_LINE3_HH_
35 public:
Line3() =
default;
41 this->pts[0] = _line[0];
42 this->pts[1] = _line[1];
50 this->
Set(_ptA, _ptB);
58 public:
Line3(
const double _x1,
const double _y1,
59 const double _x2,
const double _y2)
61 this->
Set(_x1, _y1, _x2, _y2);
71 public:
Line3(
const double _x1,
const double _y1,
72 const double _z1,
const double _x2,
73 const double _y2,
const double _z2)
75 this->
Set(_x1, _y1, _z1, _x2, _y2, _z2);
110 public:
void Set(
const double _x1,
const double _y1,
111 const double _x2,
const double _y2,
114 this->pts[0].Set(_x1, _y1, _z);
115 this->pts[1].Set(_x2, _y2, _z);
125 public:
void Set(
const double _x1,
const double _y1,
126 const double _z1,
const double _x2,
127 const double _y2,
const double _z2)
129 this->pts[0].Set(_x1, _y1, _z1);
130 this->pts[1].Set(_x2, _y2, _z2);
137 return (this->pts[1] - this->pts[0]).Normalize();
144 return this->pts[0].Distance(this->pts[1]);
157 const double _epsilon = 1e-6)
const
162 if (std::abs(p43.
X()) < _epsilon && std::abs(p43.
Y()) < _epsilon &&
163 std::abs(p43.
Z()) < _epsilon)
170 if (std::abs(p21.
X()) < _epsilon && std::abs(p21.
Y()) < _epsilon &&
171 std::abs(p21.
Z()) < _epsilon)
176 double d1343 = p13.
Dot(p43);
177 double d4321 = p43.
Dot(p21);
178 double d1321 = p13.
Dot(p21);
179 double d4343 = p43.
Dot(p43);
180 double d2121 = p21.
Dot(p21);
182 double denom = d2121 * d4343 - d4321 * d4321;
186 if (std::abs(denom) < _epsilon)
188 double d1 = this->pts[0].Distance(_line[0]);
189 double d2 = this->pts[0].Distance(_line[1]);
191 double d3 = this->pts[1].Distance(_line[0]);
192 double d4 = this->pts[1].Distance(_line[1]);
194 if (d1 <= d2 && d1 <= d3 && d1 <= d4)
196 _result.
SetA(this->pts[0]);
197 _result.
SetB(_line[0]);
199 else if (d2 <= d3 && d2 <= d4)
201 _result.
SetA(this->pts[0]);
202 _result.
SetB(_line[1]);
206 _result.
SetA(this->pts[1]);
207 _result.
SetB(_line[0]);
211 _result.
SetA(this->pts[1]);
212 _result.
SetB(_line[1]);
218 double numer = d1343 * d4321 - d1321 * d4343;
220 double mua =
clamp(numer / denom, 0.0, 1.0);
221 double mub =
clamp((d1343 + d4321 * mua) / d4343, 0.0, 1.0);
223 _result.
Set(this->pts[0] + (p21 * mua), _line[0] + (p43 * mub));
234 double _epsilon = 1e-6)
const
237 return this->
Intersect(_line, ignore, _epsilon);
246 const double _epsilon = 1e-6)
const
248 return std::abs((_line[0] - this->pts[0]).Dot(
249 (this->pts[1] - this->pts[0]).Cross(_line[1] - _line[0])))
259 const double _epsilon = 1e-6)
const
261 return (this->pts[1] - this->pts[0]).Cross(
262 _line[1] - _line[0]).Length() <= _epsilon;
274 double _epsilon = 1e-6)
const
277 if (this->
Parallel(_line, _epsilon))
280 if (this->
Within(_line[0], _epsilon))
286 else if (this->
Within(_line[1], _epsilon))
298 this->
Distance(_line, distLine, _epsilon);
302 if (distLine.
Length() < _epsilon)
318 double _epsilon = 1e-6)
const
320 return _pt.
X() <=
std::max(this->pts[0].X(),
321 this->pts[1].X()) + _epsilon &&
323 this->pts[1].X()) - _epsilon &&
325 this->pts[1].Y()) + _epsilon &&
327 this->pts[1].Y()) - _epsilon &&
329 this->pts[1].Z()) + _epsilon &&
331 this->pts[1].Z()) - _epsilon;
339 return this->pts[0] == _line[0] && this->pts[1] == _line[1];
347 return !(*
this == _line);
357 return this->pts[_index];
365 std::ostream &_out,
const Line3<T> &_line)
367 _out << _line[0] <<
" " << _line[1];
376 this->pts[0] = _line[0];
377 this->pts[1] = _line[1];
math::Vector3< T > Direction() const
Get the direction of the line.
Definition: Line3.hh:135
T Length() const
Get the length of the line.
Definition: Line3.hh:142
void Set(const double _x1, const double _y1, const double _z1, const double _x2, const double _y2, const double _z2)
Set the start and end point of the line segment.
Definition: Line3.hh:125
void SetA(const math::Vector3< T > &_ptA)
Set the start point of the line segment.
Definition: Line3.hh:90
bool Coplanar(const Line3< T > &_line, const double _epsilon=1e-6) const
Test if this line and the given line are coplanar.
Definition: Line3.hh:245
bool Intersect(const Line3< T > &_line, double _epsilon=1e-6) const
Check if this line intersects the given line segment.
Definition: Line3.hh:233
Line3(const Line3< T > &_line)
Copy constructor.
Definition: Line3.hh:39
T max(const std::vector< T > &_values)
get the maximum value of vector of values
Definition: Helpers.hh:230
T X() const
Get the x value.
Definition: Vector3.hh:630
bool Intersect(const Line3< T > &_line, math::Vector3< T > &_pt, double _epsilon=1e-6) const
Check if this line intersects the given line segment.
Definition: Line3.hh:273
Line3< int > Line3i
Definition: Line3.hh:386
Line3()=default
Line Constructor.
Line3< float > Line3f
Definition: Line3.hh:388
friend std::ostream & operator<<(std::ostream &_out, const Line3< T > &_line)
Stream extraction operator.
Definition: Line3.hh:364
T Dot(const Vector3< T > &_v) const
Return the dot product of this vector and another vector.
Definition: Vector3.hh:187
void SetB(const math::Vector3< T > &_ptB)
Set the end point of the line segment.
Definition: Line3.hh:97
bool operator!=(const Line3< T > &_line) const
Inequality operator.
Definition: Line3.hh:345
void Set(const math::Vector3< T > &_ptA, const math::Vector3< T > &_ptB)
Set the start and end point of the line segment.
Definition: Line3.hh:81
T Y() const
Get the y value.
Definition: Vector3.hh:637
T Z() const
Get the z value.
Definition: Vector3.hh:644
Exception that is thrown when an out-of-bounds index is encountered.
Definition: IndexException.hh:37
bool operator==(const Line3< T > &_line) const
Equality operator.
Definition: Line3.hh:337
void Set(const double _x1, const double _y1, const double _x2, const double _y2, const double _z=0)
Set the start and end point of the line segment, assuming that both points have the same height...
Definition: Line3.hh:110
bool Within(const math::Vector3< T > &_pt, double _epsilon=1e-6) const
Check if the given point is between the start and end points of the line segment. ...
Definition: Line3.hh:317
Line3(const math::Vector3< T > &_ptA, const math::Vector3< T > &_ptB)
Constructor.
Definition: Line3.hh:48
math::Vector3< T > operator[](const size_t _index) const
Get the start or end point.
Definition: Line3.hh:353
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:37
bool Distance(const Line3< T > &_line, Line3< T > &_result, const double _epsilon=1e-6) const
Get the shortest line between this line and the provided line.
Definition: Line3.hh:156
Line3 & operator=(const Line3< T > &_line)
Assignment operator.
Definition: Line3.hh:374
A three dimensional line segment.
Definition: Line3.hh:32
bool Parallel(const Line3< T > &_line, const double _epsilon=1e-6) const
Test if this line and the given line are parallel.
Definition: Line3.hh:258
Line3< double > Line3d
Definition: Line3.hh:387
Definition: AffineException.hh:30
Line3(const double _x1, const double _y1, const double _z1, const double _x2, const double _y2, const double _z2)
Constructor.
Definition: Line3.hh:71
Line3(const double _x1, const double _y1, const double _x2, const double _y2)
2D Constructor where Z coordinates are 0
Definition: Line3.hh:58
T min(const std::vector< T > &_values)
get the minimum value of vector of values
Definition: Helpers.hh:243
T clamp(T _v, T _min, T _max)
Simple clamping function.
Definition: Helpers.hh:131