diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-05-10 13:00:14 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-05-10 13:00:14 +0100 |
commit | df0c41c0b29ad2507623e86c78f8113aa8024aa0 (patch) | |
tree | 37d168ffd10276b16d39d7127926b277cc3cf2f1 /lib/maths.h | |
parent | Simplified genCurveDef for 1 direction (diff) | |
download | ilt-df0c41c0b29ad2507623e86c78f8113aa8024aa0.tar.bz2 ilt-df0c41c0b29ad2507623e86c78f8113aa8024aa0.tar.xz ilt-df0c41c0b29ad2507623e86c78f8113aa8024aa0.zip |
New genCurveDef for 2 directions
Based on formula/code from https://www.ryanjuckett.com/biarc-interpolation/
Produces smoother curves instead of equal curves. Removes need for that
awful formula for finding the radius of said curves which has a tendency
to blow up to infinity, and if not that then crazy rounding/accuracy
errors.
Diffstat (limited to 'lib/maths.h')
-rw-r--r-- | lib/maths.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/maths.h b/lib/maths.h index 68b45da..2999d01 100644 --- a/lib/maths.h +++ b/lib/maths.h @@ -8,6 +8,7 @@ #include <glm/gtc/constants.hpp> #include <numeric> #include <optional> +#include <ranges> #include <stdexcept> #include <utility> @@ -288,6 +289,15 @@ sq(T value) return value * value; } +template<glm::length_t L, typename T, glm::qualifier Q> +auto +vectorMagSquared(const glm::vec<L, T, Q> & val) +{ + return std::ranges::fold_left(std::views::iota(0, L), T {}, [&val](auto total, auto axis) { + return total + sq(val[axis]); + }); +} + template<glm::qualifier Q = glm::defaultp> constexpr glm::vec<3, int64_t, Q> crossProduct(const glm::vec<3, int64_t, Q> & valueA, const glm::vec<3, int64_t, Q> & valueB) @@ -403,6 +413,15 @@ linesIntersectAt(const glm::vec<2, T, Q> Aabs, const glm::vec<2, T, Q> Babs, con return Aabs + CVec {(b1 * c2) / -determinant, (a1 * c2) / determinant}; } +template<std::floating_point T> constexpr auto EPSILON = 0.0001F; + +template<std::floating_point T> +auto +isWithinLimit(T lhs, T rhs, T limit = EPSILON<T>) +{ + return std::abs(lhs - rhs) <= limit; +} + template<Arithmetic T, glm::qualifier Q = glm::defaultp> std::pair<glm::vec<2, T, Q>, bool> find_arc_centre(glm::vec<2, T, Q> start, Rotation2D startDir, glm::vec<2, T, Q> end, Rotation2D endDir) |