From d10bc5152eda4f0426325bf4b281ee81ddc92216 Mon Sep 17 00:00:00 2001 From: Noobie99 Date: Sat, 20 May 2023 16:24:33 +0200 Subject: fix outcenter (circumcenter) --- geometry/triangle.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'geometry/triangle.cpp') diff --git a/geometry/triangle.cpp b/geometry/triangle.cpp index ebbbc88..aeffa46 100644 --- a/geometry/triangle.cpp +++ b/geometry/triangle.cpp @@ -19,13 +19,12 @@ pt inCenter(pt a, pt b, pt c) { } // Zentrum des Kreises durch alle Eckpunkte -pt outCenter(pt a, pt b, pt c) { - double d = 2.0 * (real(a) * imag(b-c) + - real(b) * imag(c-a) + - real(c) * imag(a-b)); - return (a*conj(a)*conj(b-c) + - b*conj(b)*conj(c-a) + - c*conj(c)*conj(a-b)) / d; +// a, b und c nicht kollinear +pt circumCenter(pt a, pt b, pt c) { + b = b - a, c = c - a; + pt d = b * norm(c) - c * norm(b); + d = {-d.imag(), d.real()}; + return a + d / cross(b, c) / 2.0; } // 1 => p außerhalb Kreis durch a,b,c -- cgit v1.2.3