From ea0453f520a787dddff11d389683a255aed73ca7 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 10 May 2025 12:52:50 +0100 Subject: Simplified genCurveDef for 1 direction Uses new find_arc_centre for 1 direction which doesn't break for 180 degree solutions. --- lib/maths.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib/maths.h') diff --git a/lib/maths.h b/lib/maths.h index 43d6dcd..68b45da 100644 --- a/lib/maths.h +++ b/lib/maths.h @@ -426,6 +426,21 @@ find_arc_centre(glm::vec<2, T, Q> start, Angle entrys, glm::vec<2, T, Q> end, An return find_arc_centre(start, sincos(entrys + half_pi), end, sincos(entrye - half_pi)); } +template +std::pair, bool> +find_arc_centre(glm::vec<2, T, Q> start, Angle entrys, glm::vec<2, T, Q> end) +{ + if (start == end) { + return {start, false}; + } + const auto startNormal = vector_normal(sincos(entrys) * 10'000.F); + const auto diffEnds = difference(end, start); + const auto midEnds = start + ((end - start) / 2); + const auto diffNormal = vector_normal(diffEnds); + const auto centre = linesIntersectAt(start, start + startNormal, midEnds, midEnds + diffNormal); + return {*centre, normalize(vector_yaw(diffEnds) - entrys) < 0}; +} + template Angle find_arcs_radius(glm::vec<2, T, Q> start, Rotation2D ad, glm::vec<2, T, Q> end, Rotation2D bd) -- cgit v1.2.3