14 using EdgeType = Edge<T>;
15 using VertexType = Vector2<T>;
17 Triangle(
const VertexType &_p1,
const VertexType &_p2,
const VertexType &_p3)
18 : p1(_p1), p2(_p2), p3(_p3),
19 e1(_p1, _p2), e2(_p2, _p3), e3(_p3, _p1)
22 bool containsVertex(
const VertexType &v)
24 return p1 == v || p2 == v || p3 == v;
27 bool circumCircleContains(
const VertexType &v)
29 float ab = (p1.x * p1.x) + (p1.y * p1.y);
30 float cd = (p2.x * p2.x) + (p2.y * p2.y);
31 float ef = (p3.x * p3.x) + (p3.y * p3.y);
33 float circum_x = (ab * (p3.y - p2.y) + cd * (p1.y - p3.y) + ef * (p2.y - p1.y)) / (p1.x * (p3.y - p2.y) + p2.x * (p1.y - p3.y) + p3.x * (p2.y - p1.y)) / 2.f;
34 float circum_y = (ab * (p3.x - p2.x) + cd * (p1.x - p3.x) + ef * (p2.x - p1.x)) / (p1.y * (p3.x - p2.x) + p2.y * (p1.x - p3.x) + p3.y * (p2.x - p1.x)) / 2.f;
35 float circum_radius = sqrtf(((p1.x - circum_x) * (p1.x - circum_x)) + ((p1.y - circum_y) * (p1.y - circum_y)));
37 float dist = sqrtf(((v.x - circum_x) * (v.x - circum_x)) + ((v.y - circum_y) * (v.y - circum_y)));
38 return dist <= circum_radius;
50 inline std::ostream &operator << (std::ostream &str,
const Triangle<T> & t)
52 return str <<
"Triangle:" << std::endl <<
"\t" << t.p1 << std::endl <<
"\t" << t.p2 << std::endl <<
"\t" << t.p3 << std::endl <<
"\t" << t.e1 << std::endl <<
"\t" << t.e2 << std::endl <<
"\t" << t.e3 << std::endl;
57 inline bool operator == (
const Triangle<T> &t1,
const Triangle<T> &t2)
59 return (t1.p1 == t2.p1 || t1.p1 == t2.p2 || t1.p1 == t2.p3) &&
60 (t1.p2 == t2.p1 || t1.p2 == t2.p2 || t1.p2 == t2.p3) &&
61 (t1.p3 == t2.p1 || t1.p3 == t2.p2 || t1.p3 == t2.p3);