17 #ifndef GZ_MATH_TRIANGLE3_HH_
18 #define GZ_MATH_TRIANGLE3_HH_
24 #include <gz/math/config.hh>
29 inline namespace GZ_MATH_VERSION_NAMESPACE {
51 this->Set(_pt1, _pt2, _pt3);
65 this->pts[
clamp(_index, 0u, 2u)] = _pt;
92 T a = this->Side(0).Length();
93 T b = this->Side(1).Length();
94 T c = this->Side(2).Length();
95 return (a+b) > c && (b+c) > a && (c+a) > b;
108 return Line3<T>(this->pts[0], this->pts[1]);
109 else if (_index == 1)
110 return Line3<T>(this->pts[1], this->pts[2]);
112 return Line3<T>(this->pts[2], this->pts[0]);
122 return this->Contains(_line[0]) && this->Contains(_line[1]);
138 double dot00 = v0.
Dot(v0);
139 double dot01 = v0.
Dot(v1);
140 double dot02 = v0.
Dot(v2);
141 double dot11 = v1.
Dot(v1);
142 double dot12 = v1.
Dot(v2);
145 double invDenom = 1.0 / (dot00 * dot11 - dot01 * dot01);
146 double u = (dot11 * dot02 - dot01 * dot12) * invDenom;
147 double v = (dot00 * dot12 - dot01 * dot02) * invDenom;
150 return (u >= 0) && (v >= 0) && (u + v <= 1);
160 Vector3d(this->pts[0][0], this->pts[0][1], this->pts[0][2]),
161 Vector3d(this->pts[1][0], this->pts[1][1], this->pts[1][2]),
162 Vector3d(this->pts[2][0], this->pts[2][1], this->pts[2][2]));
188 Vector3<T> dir = (_line[1] - _line[0]).Normalize();
190 double denom = norm.
Dot(
Vector3d(dir[0], dir[1], dir[2]));
197 double intersection =
198 -norm.
Dot(
Vector3d(diff[0], diff[1], diff[2])) / denom;
201 if (intersection < 1.0 || intersection > _line.
Length())
205 _ipt1 = _line[0] + (dir * intersection);
213 if (this->Contains(_line))
219 else if (_line.
Intersect(this->Side(0), _ipt1))
224 else if (_line.
Intersect(this->Side(1), _ipt1))
229 else if (_line.
Intersect(this->Side(2), _ipt1))
242 return this->Side(0).Length() + this->Side(1).Length() +
243 this->Side(2).Length();
250 double s = this->Perimeter() / 2.0;
251 T a = this->Side(0).Length();
252 T b = this->Side(1).Length();
253 T c = this->Side(2).Length();
257 return sqrt(s * (s-a) * (s-b) * (s-c));