From 38d9198eace03d974a9049c99b4c544aa20989cd Mon Sep 17 00:00:00 2001 From: Philip Trettner <Philip.Trettner@rwth-aachen.de> Date: Thu, 18 Jun 2020 17:41:06 +0200 Subject: [PATCH] added 2D line line intersection --- src/typed-geometry/functions/objects/intersection.hh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/typed-geometry/functions/objects/intersection.hh b/src/typed-geometry/functions/objects/intersection.hh index ce0a2fe6..570dae54 100644 --- a/src/typed-geometry/functions/objects/intersection.hh +++ b/src/typed-geometry/functions/objects/intersection.hh @@ -540,6 +540,14 @@ template <class ScalarT> return {}; } +template <class ScalarT> +[[nodiscard]] constexpr pos<2, ScalarT> intersection(line<2, ScalarT> const& l0, line<2, ScalarT> const& l1) +{ + auto M = tg::mat<2, 2, ScalarT>::from_cols(l0.dir, -l1.dir); + auto t = inverse(M) * (l1.pos - l0.pos); + return l0[t.x]; +} + template <int D, class ScalarT> [[nodiscard]] constexpr optional<aabb<D, ScalarT>> intersection(aabb<D, ScalarT> const& a, aabb<D, ScalarT> const& b) { -- GitLab