From 51f96b43445bc8eb77a2e78dea83aa06a14ae44a Mon Sep 17 00:00:00 2001 From: Brandon Runnels Date: Mon, 27 Nov 2023 11:13:10 -0600 Subject: [PATCH] Added optional tolerance argument so exceptions don't get thrown when working with non-double-precision inputs. --- .gitignore | 3 ++- py/python.cpp | 6 +++--- src/Utils/wieldRotations.h | 24 ++++++++++++------------ 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 85111a6..43b3ab9 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,5 @@ results run.stdout run.error .vscode -wield.code-workspace \ No newline at end of file +wield.code-workspace +doc diff --git a/py/python.cpp b/py/python.cpp index e6c62a3..e4bdafc 100644 --- a/py/python.cpp +++ b/py/python.cpp @@ -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"); diff --git a/src/Utils/wieldRotations.h b/src/Utils/wieldRotations.h index 27de7cc..d277ec8 100644 --- a/src/Utils/wieldRotations.h +++ b/src/Utils/wieldRotations.h @@ -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(); @@ -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(); @@ -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();