From 211146e5dead64c14459c0eb872c2ff2b7ee8890 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Wed, 27 Sep 2023 14:37:00 +0200 Subject: [PATCH] Fix calculation of up vector angle. --- src/libslic3r/Emboss.cpp | 11 +++-------- src/libslic3r/Geometry.hpp | 3 ++- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/libslic3r/Emboss.cpp b/src/libslic3r/Emboss.cpp index 0fed283a0c..7afccda67e 100644 --- a/src/libslic3r/Emboss.cpp +++ b/src/libslic3r/Emboss.cpp @@ -1647,22 +1647,17 @@ std::optional Emboss::calc_up(const Transform3d &tr, double up_limit) Vec3d normal = tr_linear.col(2); // scaled matrix has base with different size normal.normalize(); - Vec3d suggested = suggest_up(normal); + Vec3d suggested = suggest_up(normal, up_limit); assert(is_approx(suggested.squaredNorm(), 1.)); Vec3d up = tr_linear.col(1); // tr * UnitY() - up.normalize(); - - double dot = suggested.dot(up); - if (dot >= 1. || dot <= -1.) - return {}; // zero angle - + up.normalize(); Matrix3d m; m.row(0) = up; m.row(1) = suggested; m.row(2) = normal; double det = m.determinant(); - + double dot = suggested.dot(up); return -atan2(det, dot); } diff --git a/src/libslic3r/Geometry.hpp b/src/libslic3r/Geometry.hpp index 0d6e921d5c..c5d81bda54 100644 --- a/src/libslic3r/Geometry.hpp +++ b/src/libslic3r/Geometry.hpp @@ -317,9 +317,10 @@ template T angle_to_0_2PI(T angle) return angle; } template void to_range_pi_pi(T &angle){ - if (angle > T(PI) || angle < -T(PI)) { + if (angle > T(PI) || angle <= -T(PI)) { int count = static_cast(std::round(angle / (2 * PI))); angle -= static_cast(count * 2 * PI); + assert(angle <= T(PI) && angle > -T(PI)); } }