MCPcopy Create free account
hub / github.com/comaps/comaps / IsPointInsideTriangle

Function IsPointInsideTriangle

libs/geometry/triangle2d.cpp:15–27  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13namespace m2
14{
15bool IsPointInsideTriangle(PointD const & pt, PointD const & p1, PointD const & p2, PointD const & p3)
16{
17 double const s1 = robust::OrientedS(p1, p2, pt);
18 double const s2 = robust::OrientedS(p2, p3, pt);
19 double const s3 = robust::OrientedS(p3, p1, pt);
20
21 // In the case of degenerate triangles we need to check that pt lies
22 // on (p1, p2), (p2, p3) or (p3, p1).
23 if (s1 == 0.0 && s2 == 0.0 && s3 == 0.0)
24 return IsPointOnSegment(pt, p1, p2) || IsPointOnSegment(pt, p2, p3) || IsPointOnSegment(pt, p3, p1);
25
26 return ((s1 >= 0.0 && s2 >= 0.0 && s3 >= 0.0) || (s1 <= 0.0 && s2 <= 0.0 && s3 <= 0.0));
27}
28
29bool IsPointStrictlyInsideTriangle(PointD const & pt, PointD const & p1, PointD const & p2, PointD const & p3)
30{

Callers 7

InsertCornersFunction · 0.85
ClipTriangleByRectFunction · 0.85
operator()Method · 0.85
IsPointInsideTrianglesFunction · 0.85
InsideTriangleFunction · 0.85
UNIT_TESTFunction · 0.85
GetMinDistanceMetersFunction · 0.85

Calls 2

OrientedSFunction · 0.85
IsPointOnSegmentFunction · 0.85

Tested by 2

InsideTriangleFunction · 0.68
UNIT_TESTFunction · 0.68