17 #ifndef GZ_MATH_TRIANGLE_HH_
18 #define GZ_MATH_TRIANGLE_HH_
24 #include <gz/math/config.hh>
29 inline namespace GZ_MATH_VERSION_NAMESPACE {
47 this->Set(_pt1, _pt2, _pt3);
57 this->pts[
clamp(_index, 0u, 2u)] = _pt;
79 T a = this->Side(0).Length();
80 T b = this->Side(1).Length();
81 T c = this->Side(2).Length();
82 return (a+b) > c && (b+c) > a && (c+a) > b;
95 return Line2<T>(this->pts[0], this->pts[1]);
97 return Line2<T>(this->pts[1], this->pts[2]);
99 return Line2<T>(this->pts[2], this->pts[0]);
109 return this->Contains(_line[0]) && this->Contains(_line[1]);
123 double dot00 = v0.
Dot(v0);
124 double dot01 = v0.
Dot(v1);
125 double dot02 = v0.
Dot(v2);
126 double dot11 = v1.
Dot(v1);
127 double dot12 = v1.
Dot(v2);
130 double invDenom = 1.0 / (dot00 * dot11 - dot01 * dot01);
131 double u = (dot11 * dot02 - dot01 * dot12) * invDenom;
132 double v = (dot00 * dot12 - dot01 * dot02) * invDenom;
135 return (u >= 0) && (v >= 0) && (u + v <= 1);
149 if (this->Contains(_line))
156 Line2<T> line1(this->pts[0], this->pts[1]);
157 Line2<T> line2(this->pts[1], this->pts[2]);
158 Line2<T> line3(this->pts[2], this->pts[0]);
176 else if (points.
size() == 1)
178 auto iter = points.
begin();
181 if (this->Contains(_line[0]))
190 auto iter = points.
begin();
202 return this->Side(0).Length() + this->Side(1).Length() +
203 this->Side(2).Length();
210 double s = this->Perimeter() / 2.0;
211 T a = this->Side(0).Length();
212 T b = this->Side(1).Length();
213 T c = this->Side(2).Length();
217 return sqrt(s * (s-a) * (s-b) * (s-c));