From 0eb2e4f974835eaaec0d493c486e05b75af0b9fe Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Tue, 25 Feb 2020 10:30:12 +0800 Subject: [PATCH] add tri_circumcircle --- src/experimental/tri_circumcircle.scad | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/experimental/tri_circumcircle.scad diff --git a/src/experimental/tri_circumcircle.scad b/src/experimental/tri_circumcircle.scad new file mode 100644 index 00000000..4b561d3e --- /dev/null +++ b/src/experimental/tri_circumcircle.scad @@ -0,0 +1,18 @@ +function tri_circumcircle(points) = + let( + p0 = points[0], + p1 = points[1], + p2 = points[2], + v0 = p1 - p0, + d0 = (p1 + p0) / 2 * v0, + v1 = p2 - p1, + d1 = (p2 + p1) / 2 * v1, + det = -cross(v0 , v1) + ) + det == 0? undef : + let( + x = (d1 * v0[1] - d0 * v1[1]) / det, + y = (d0 * v1[0] - d1 * v0[0]) / det, + r = norm(p0 - [x,y]) + ) + [[x,y], r]; \ No newline at end of file