From 662915c805b7f152ae90f686bd1c7bb5b63a60cf Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Sun, 25 Apr 2021 17:54:05 +0800 Subject: [PATCH] add tri_circumcenter --- src/triangle/tri_circumcenter.scad | 15 +++++++++++++++ src/triangle/tri_circumcircle.scad | 20 -------------------- 2 files changed, 15 insertions(+), 20 deletions(-) create mode 100644 src/triangle/tri_circumcenter.scad delete mode 100644 src/triangle/tri_circumcircle.scad diff --git a/src/triangle/tri_circumcenter.scad b/src/triangle/tri_circumcenter.scad new file mode 100644 index 00000000..93d24079 --- /dev/null +++ b/src/triangle/tri_circumcenter.scad @@ -0,0 +1,15 @@ +function tri_circumcenter(shape_pts) = + let( + p0 = shape_pts[0], + p1 = shape_pts[1], + p2 = shape_pts[2], + v0 = p1 - p0, + d0 = (p1 + p0) / 2 * v0, + v1 = p2 - p1, + d1 = (p2 + p1) / 2 * v1, + det = -cross(v0 , v1) + ) + det == 0 ? undef : [ + (d1 * v0[1] - d0 * v1[1]) / det, + (d0 * v1[0] - d1 * v0[0]) / det + ]; \ No newline at end of file diff --git a/src/triangle/tri_circumcircle.scad b/src/triangle/tri_circumcircle.scad deleted file mode 100644 index d87e9e8b..00000000 --- a/src/triangle/tri_circumcircle.scad +++ /dev/null @@ -1,20 +0,0 @@ -function tri_circumcircle(shape_pts) = - let( - p0 = shape_pts[0], - p1 = shape_pts[1], - p2 = shape_pts[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, - center = [x, y], - v = p0 - center, - r = norm(v) - ) - [center, r]; \ No newline at end of file