Skip to content

Commit

Permalink
Added optional tolerance argument so exceptions don't get thrown when…
Browse files Browse the repository at this point in the history
… working with non-double-precision inputs.
  • Loading branch information
bsrunnels committed Nov 27, 2023
1 parent 3b7e8d4 commit 51f96b4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ results
run.stdout
run.error
.vscode
wield.code-workspace
wield.code-workspace
doc
6 changes: 3 additions & 3 deletions py/python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ PYBIND11_MODULE(wield,m) {
m.def("createMatrixFromYAngle",&createMatrixFromYAngle,"Generate rotation matrix about y axis");
m.def("createMatrixFromZAngle",&createMatrixFromZAngle,"Generate rotation matrix about z axis");
m.def("createMatrixFromAngle",&createMatrixFromAngle,"Generate rotation matrix about x, y, or z axis");
m.def("createMatrixFromXY",&createMatrixFromXY,"Generate rotation matrix from x axis and y axis");
m.def("createMatrixFromYZ",&createMatrixFromYZ,"Generate rotation matrix from y axis and z axis");
m.def("createMatrixFromZX",&createMatrixFromZX,"Generate rotation matrix from z axis and x axis");
m.def("createMatrixFromXY",&createMatrixFromXY,"Generate rotation matrix from x axis and y axis",pybind11::arg("ex"),pybind11::arg("ey"),pybind11::arg("tolerance")=1E-8);
m.def("createMatrixFromYZ",&createMatrixFromYZ,"Generate rotation matrix from y axis and z axis",pybind11::arg("ey"),pybind11::arg("ez"),pybind11::arg("tolerance")=1E-8);
m.def("createMatrixFromZX",&createMatrixFromZX,"Generate rotation matrix from z axis and x axis",pybind11::arg("ez"),pybind11::arg("ex"),pybind11::arg("tolerance")=1E-8);
m.def("createMatrixFromNormalVector",&createMatrixFromNormalVector,"Generate rotation matrix from normal vector");
m.def("createMatrixFromBungeEulerAngles",&createMatrixFromBungeEulerAngles,"Generate rotation matrix from Bunge Euler Angles");
m.def("createMatrixFromAxisAngle",&createMatrixFromAxisAngle,"Generate rotation matrix from axis-angle pair");
Expand Down
24 changes: 12 additions & 12 deletions src/Utils/wieldRotations.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ Eigen::Matrix3d createMatrixFromAngle(double theta, char axis)
if (axis=='z' || axis=='Z') return createMatrixFromZAngle(theta);
else return Eigen::Matrix3d::Identity();
}
Eigen::Matrix3d createMatrixFromXY(Eigen::Vector3d ex, Eigen::Vector3d ey)
Eigen::Matrix3d createMatrixFromXY(Eigen::Vector3d ex, Eigen::Vector3d ey, double tolerance=1E-8)
{
WIELD_EXCEPTION_TRY;
if (fabs(ex.dot(ey)) > 1E-8)
if (fabs(ex.dot(ey)) > tolerance)
WIELD_EXCEPTION_NEW("ex not orthogonal to ey: ex=[" << ex.transpose() << "]; ey=[" << ey.transpose()<<"]");
if (ex.norm() < 1E-8) WIELD_EXCEPTION_NEW("ex is a zero vector");
if (ey.norm() < 1E-8) WIELD_EXCEPTION_NEW("ey is a zero vector");
if (ex.norm() < tolerance) WIELD_EXCEPTION_NEW("ex is a zero vector");
if (ey.norm() < tolerance) WIELD_EXCEPTION_NEW("ey is a zero vector");
Eigen::Vector3d ez = ex.cross(ey);
Eigen::Matrix3d Omega;
Omega.col(0) = ex / ex.norm();
Expand All @@ -55,13 +55,13 @@ Eigen::Matrix3d createMatrixFromXY(Eigen::Vector3d ex, Eigen::Vector3d ey)
WIELD_EXCEPTION_CATCH;
}

Eigen::Matrix3d createMatrixFromYZ(Eigen::Vector3d ey, Eigen::Vector3d ez)
Eigen::Matrix3d createMatrixFromYZ(Eigen::Vector3d ey, Eigen::Vector3d ez, double tolerance=1E-8)
{
WIELD_EXCEPTION_TRY;
if (fabs(ey.dot(ez)) > 1E-8)
if (fabs(ey.dot(ez)) > tolerance)
WIELD_EXCEPTION_NEW("ey not orthogonal to ez: ey=[" << ey.transpose() << "]; ez=[" << ez.transpose()<<"]");
if (ey.norm() < 1E-8) WIELD_EXCEPTION_NEW("ey is a zero vector");
if (ez.norm() < 1E-8) WIELD_EXCEPTION_NEW("ez is a zero vector");
if (ey.norm() < tolerance) WIELD_EXCEPTION_NEW("ey is a zero vector");
if (ez.norm() < tolerance) WIELD_EXCEPTION_NEW("ez is a zero vector");
Eigen::Vector3d ex = ey.cross(ez);
Eigen::Matrix3d Omega;
Omega.col(0) = ex / ex.norm();
Expand All @@ -71,13 +71,13 @@ Eigen::Matrix3d createMatrixFromYZ(Eigen::Vector3d ey, Eigen::Vector3d ez)
WIELD_EXCEPTION_CATCH;
}

Eigen::Matrix3d createMatrixFromZX(Eigen::Vector3d ez, Eigen::Vector3d ex)
Eigen::Matrix3d createMatrixFromZX(Eigen::Vector3d ez, Eigen::Vector3d ex, double tolerance=1E-8)
{
WIELD_EXCEPTION_TRY;
if (fabs(ez.dot(ex)) > 1E-8)
if (fabs(ez.dot(ex)) > tolerance)
WIELD_EXCEPTION_NEW("ez not orthogonal to ex: ez=[" << ez.transpose() << "]; ex=[" << ex.transpose()<<"]");
if (ez.norm() < 1E-8) WIELD_EXCEPTION_NEW("ez is a zero vector");
if (ex.norm() < 1E-8) WIELD_EXCEPTION_NEW("ex is a zero vector");
if (ez.norm() < tolerance) WIELD_EXCEPTION_NEW("ez is a zero vector");
if (ex.norm() < tolerance) WIELD_EXCEPTION_NEW("ex is a zero vector");
Eigen::Vector3d ey = ez.cross(ex);
Eigen::Matrix3d Omega;
Omega.col(0) = ex / ex.norm();
Expand Down

0 comments on commit 51f96b4

Please sign in to comment.