Open mjm522 opened 2 years ago
Is it because when I call get_oriented_bounding_box, it recalculates the convex-hull and then redo all the computation to get the orientation
Yes, see this cpp implementation:
Eigen::Vector3d mean;
Eigen::Matrix3d cov;
std::tie(mean, cov) = hull_pcd.ComputeMeanAndCovariance();
Eigen::SelfAdjointEigenSolver<Eigen::Matrix3d> es(cov);
Eigen::Vector3d evals = es.eigenvalues();
Eigen::Matrix3d R = es.eigenvectors();
if (evals(1) > evals(0)) {
std::swap(evals(1), evals(0));
Eigen::Vector3d tmp = R.col(1);
R.col(1) = R.col(0);
R.col(0) = tmp;
}
if (evals(2) > evals(0)) {
std::swap(evals(2), evals(0));
Eigen::Vector3d tmp = R.col(2);
R.col(2) = R.col(0);
R.col(0) = tmp;
}
if (evals(2) > evals(1)) {
std::swap(evals(2), evals(1));
Eigen::Vector3d tmp = R.col(2);
R.col(2) = R.col(1);
R.col(1) = tmp;
}
R.col(0) /= R.col(0).norm();
R.col(1) /= R.col(1).norm();
R.col(2) = R.col(0).cross(R.col(1));
The rotation matrix depends on the eigenvector of the covariance, and the order is rearranged based on the magnitude of eigenvalue. I suggest you define a rotation (or transformation) variable (maybe in numpy.ndarray 4x4) in the initial state, then you keep changing this variable once you apply transformation to the mesh, to record and represent the current state of pose.
Checklist
master
branch).My Question
Hi all, I am trying to get a specific orientation for a mesh. For that, once I created the mesh, I multiply by the inverse of the current OBB orientation to make the current orientation unity. The position seems to get centred while the orientation returned is still the same. Is there a way to force or retain the orientation? This does not happen if the box created symmetrical. Is it because when I call get_oriented_bounding_box, it recalculates the convex-hull and then redo all the computation to get the orientation? Below is a code snippet that exhibits this. Probably the mesh is getting rotated, the question will be how to get its current orientation?
The above code produces the following output.