MCPcopy Create free account
hub / github.com/ANYbotics/grid_map / getCentroid

Method getCentroid

grid_map_core/src/Polygon.cpp:113–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111}
112
113Position Polygon::getCentroid() const
114{
115 Position centroid = Position::Zero();
116 std::vector<Position> vertices = getVertices();
117 vertices.push_back(vertices.at(0));
118 double area = 0.0;
119 for (int i = 0; i < vertices.size() - 1; i++) {
120 const double a = vertices[i].x() * vertices[i+1].y() - vertices[i+1].x() * vertices[i].y();
121 area += a;
122 centroid.x() += a * (vertices[i].x() + vertices[i+1].x());
123 centroid.y() += a * (vertices[i].y() + vertices[i+1].y());
124 }
125 area *= 0.5;
126 centroid /= (6.0 * area);
127 return centroid;
128}
129
130void Polygon::getBoundingBox(Position& center, Length& length) const
131{

Callers 1

TESTFunction · 0.80

Calls 1

atMethod · 0.80

Tested by 1

TESTFunction · 0.64