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

Function ProjectPointToTriangles

libs/geometry/triangle2d.cpp:67–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65}
66
67PointD ProjectPointToTriangles(PointD const & pt, std::vector<TriangleD> const & v)
68{
69 if (v.empty())
70 return pt;
71
72 int minT = -1;
73 int minI = -1;
74 double minDist = std::numeric_limits<double>::max();
75 for (int t = 0; t < static_cast<int>(v.size()); t++)
76 {
77 for (int i = 0; i < 3; i++)
78 {
79 ParametrizedSegment<PointD> segment(v[t].m_points[i], v[t].m_points[(i + 1) % 3]);
80 double const dist = segment.SquaredDistanceToPoint(pt);
81 if (dist < minDist)
82 {
83 minDist = dist;
84 minT = t;
85 minI = i;
86 }
87 }
88 }
89 ParametrizedSegment<PointD> segment(v[minT].m_points[minI], v[minT].m_points[(minI + 1) % 3]);
90 return segment.ClosestPointTo(pt);
91}
92} // namespace m2

Callers 1

PullToBoundAreaMethod · 0.85

Calls 4

ClosestPointToMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected