Skip to content

Commit

Permalink
Add utility function to scale vertices about a point
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi Armstrong authored and Levi-Armstrong committed Feb 18, 2021
1 parent 7239e5e commit f33ba34
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tesseract_collision/include/tesseract_collision/core/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,38 @@ inline tesseract_geometry::ConvexMesh::Ptr makeConvexMesh(const tesseract_geomet
return std::make_shared<tesseract_geometry::ConvexMesh>(ch_vertices, ch_faces, ch_num_faces);
}

/**
* @brief Apply scaling to the geometry coordinates.
* @details Given a scaling factor s, and center c, a given vertice v is transformed according to s (v - c) + c.
* @param vertices The vertices to scale
* @param center The point at which to scale the data about
* @param scale The scale factor to apply to the vertices.
*/
inline void scaleVertices(tesseract_common::VectorVector3d& vertices,
const Eigen::Vector3d& center,
const Eigen::Vector3d& scale)
{
for (auto& v : vertices)
v = scale.cwiseProduct(v - center) + center;
}

/**
* @brief Apply scaling to the geometry coordinates.
* @details Given a scaling factor s, and center c, a given vertice v is transformed according to s (v - c) + c.
* @param vertices The vertices to scale
* @param scale The scale factor to apply to the vertices.
*/
inline void scaleVertices(tesseract_common::VectorVector3d& vertices, const Eigen::Vector3d& scale)
{
Eigen::Vector3d center(0, 0, 0);
for (const auto& v : vertices)
center = center + v;

center = (1.0 / static_cast<double>(vertices.size())) * center;

scaleVertices(vertices, center, scale);
}

/**
* @brief Write a simple ply file given vertices and faces
* @param path The file path
Expand Down

0 comments on commit f33ba34

Please sign in to comment.