Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Updated Mesh Inertia Calculator to incorporate mesh scale in the calculations #2171

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/MeshInertiaCalculator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ using namespace sim;
//////////////////////////////////////////////////
void MeshInertiaCalculator::GetMeshTriangles(
std::vector<Triangle>& _triangles,
gz::math::Vector3d _meshScale,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it const ref? i.e. const gz::math::Vector3d &_meshScale

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in d892b53

const gz::common::Mesh* _mesh)
{
// Get the vertices & indices of the mesh
Expand All @@ -60,6 +61,12 @@ void MeshInertiaCalculator::GetMeshTriangles(
triangle.v2.X() = vertArray[static_cast<ptrdiff_t>(3 * indArray[i+2])];
triangle.v2.Y() = vertArray[static_cast<ptrdiff_t>(3 * indArray[i+2] + 1)];
triangle.v2.Z() = vertArray[static_cast<ptrdiff_t>(3 * indArray[i+2] + 2)];

// Apply mesh scale to the triangle coordinates
triangle.v0 = triangle.v0 * _meshScale;
triangle.v1 = triangle.v1 * _meshScale;
triangle.v2 = triangle.v2 * _meshScale;

triangle.centroid = (triangle.v0 + triangle.v1 + triangle.v2) / 3;
_triangles.push_back(triangle);
}
Expand Down Expand Up @@ -245,7 +252,7 @@ std::optional<gz::math::Inertiald> MeshInertiaCalculator::operator()
gz::math::Pose3d inertiaOrigin;

// Create a list of Triangle objects from the mesh vertices and indices
this->GetMeshTriangles(meshTriangles, mesh);
this->GetMeshTriangles(meshTriangles, sdfMesh->Scale(), mesh);

// Calculate the mesh centroid and set is as centre of mass
this->CalculateMeshCentroid(centreOfMass, meshTriangles);
Expand Down
1 change: 1 addition & 0 deletions src/MeshInertiaCalculator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ namespace gz
/// \param[in] _mesh Mesh object
public: void GetMeshTriangles(
std::vector<Triangle>& _triangles,
gz::math::Vector3d _meshScale,
const gz::common::Mesh* _mesh);

/// \brief Function to calculate the centroid of the mesh. Since
Expand Down