diff --git a/wpimath/src/main/java/edu/wpi/first/math/geometry/Rotation3d.java b/wpimath/src/main/java/edu/wpi/first/math/geometry/Rotation3d.java index bd39ecac6f..3226e31f06 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/geometry/Rotation3d.java +++ b/wpimath/src/main/java/edu/wpi/first/math/geometry/Rotation3d.java @@ -101,7 +101,7 @@ public class Rotation3d implements Interpolatable { // Require that the rotation matrix is special orthogonal. This is true if // the matrix is orthogonal (RRᵀ = I) and normalized (determinant is 1). - if (!R.times(R.transpose()).equals(Matrix.eye(Nat.N3()))) { + if (R.times(R.transpose()).minus(Matrix.eye(Nat.N3())).normF() > 1e-9) { var builder = new StringBuilder("Rotation matrix isn't orthogonal\n\nR =\n"); builder.append(R.getStorage().toString()).append('\n'); @@ -109,7 +109,7 @@ public class Rotation3d implements Interpolatable { MathSharedStore.reportError(msg, Thread.currentThread().getStackTrace()); throw new IllegalArgumentException(msg); } - if (R.det() != 1.0) { + if (Math.abs(R.det() - 1.0) > 1e-9) { var builder = new StringBuilder("Rotation matrix is orthogonal but not special orthogonal\n\nR =\n"); builder.append(R.getStorage().toString()).append('\n'); diff --git a/wpimath/src/main/native/cpp/geometry/Rotation3d.cpp b/wpimath/src/main/native/cpp/geometry/Rotation3d.cpp index bf27407313..298f0e6740 100644 --- a/wpimath/src/main/native/cpp/geometry/Rotation3d.cpp +++ b/wpimath/src/main/native/cpp/geometry/Rotation3d.cpp @@ -54,14 +54,14 @@ Rotation3d::Rotation3d(const Matrixd<3, 3>& rotationMatrix) { // Require that the rotation matrix is special orthogonal. This is true if the // matrix is orthogonal (RRᵀ = I) and normalized (determinant is 1). - if (R * R.transpose() != Matrixd<3, 3>::Identity()) { + if ((R * R.transpose() - Matrixd<3, 3>::Identity()).norm() > 1e-9) { std::string msg = fmt::format("Rotation matrix isn't orthogonal\n\nR =\n{}\n", R); wpi::math::MathSharedStore::ReportError(msg); throw std::domain_error(msg); } - if (R.determinant() != 1.0) { + if (std::abs(R.determinant() - 1.0) > 1e-9) { std::string msg = fmt::format( "Rotation matrix is orthogonal but not special orthogonal\n\nR =\n{}\n", R);