From 4f88775ef9de4256e84b06afdea6f147b2b779cd Mon Sep 17 00:00:00 2001 From: Garth Minette Date: Thu, 24 Sep 2020 17:09:06 -0700 Subject: [PATCH] Changed circle_point_tangents() to return just a list of 2D tangent points. --- geometry.scad | 6 +++--- tests/test_geometry.scad | 18 +++++++++++------- version.scad | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/geometry.scad b/geometry.scad index 97564db..b09c05b 100644 --- a/geometry.scad +++ b/geometry.scad @@ -1342,7 +1342,7 @@ function find_circle_3points(pt1, pt2, pt3) = // tangents = circle_point_tangents(r|d, cp, pt); // Description: // Given a 2d circle and a 2d point outside that circle, finds the 2d tangent point(s) on the circle for a -// line passing through the point. Returns list of zero or more sublists of [ANG, TANGPT] +// line passing through the point. Returns a list of zero or more 2D tangent points. // Arguments: // r = Radius of the circle. // d = Diameter of the circle. @@ -1350,7 +1350,7 @@ function find_circle_3points(pt1, pt2, pt3) = // pt = The coordinates of the 2d external point. // Example: // cp = [-10,-10]; r = 30; pt = [30,10]; -// tanpts = subindex(circle_point_tangents(r=r, cp=cp, pt=pt),1); +// tanpts = circle_point_tangents(r=r, cp=cp, pt=pt); // color("yellow") translate(cp) circle(r=r); // color("cyan") for(tp=tanpts) {stroke([tp,pt]); stroke([tp,cp]);} // color("red") move_copies(tanpts) circle(d=3,$fn=12); @@ -1368,7 +1368,7 @@ function circle_point_tangents(r, d, cp, pt) = let( relang = acos(r/dist), angs = [baseang + relang, baseang - relang] - ) [for (ang=angs) [ang, cp + r*[cos(ang),sin(ang)]]]; + ) [for (ang=angs) cp + r*[cos(ang),sin(ang)]]; // Function: circle_circle_tangents() diff --git a/tests/test_geometry.scad b/tests/test_geometry.scad index 84dd814..bf49f0f 100644 --- a/tests/test_geometry.scad +++ b/tests/test_geometry.scad @@ -601,13 +601,17 @@ module test_find_circle_3points() { module test_circle_point_tangents() { - tangs = circle_point_tangents(r=50,cp=[0,0],pt=[50*sqrt(2),0]); - assert(approx(subindex(tangs,0), [45,-45])); - expected = [for (ang=subindex(tangs,0)) polar_to_xy(50,ang)]; - got = subindex(tangs,1); - if (!approx(flatten(got), flatten(expected))) { - echo("TAN_PTS:", got=got, expected=expected, delta=got-expected); - assert(approx(flatten(got), flatten(expected))); + testvals = [ + // cp r pt expect + [[0,0], 50, [50*sqrt(2),0], [polar_to_xy(50,45), polar_to_xy(50,-45)]], + [[5,10], 50, [5+50*sqrt(2),10], [[5,10]+polar_to_xy(50,45), [5,10]+polar_to_xy(50,-45)]], + [[0,0], 50, [0,50*sqrt(2)], [polar_to_xy(50,135), polar_to_xy(50,45)]], + [[5,10], 50, [5,10+50*sqrt(2)], [[5,10]+polar_to_xy(50,135), [5,10]+polar_to_xy(50,45)]] + ]; + for (v = testvals) { + cp = v[0]; r = v[1]; pt = v[2]; expect = v[3]; + info = str("cp=",cp, ", r=",r, ", pt=",pt); + assert_approx(circle_point_tangents(r=r,cp=cp,pt=pt), expect, info); } } *test_circle_point_tangents(); diff --git a/version.scad b/version.scad index 975eb67..ba38fd3 100644 --- a/version.scad +++ b/version.scad @@ -8,7 +8,7 @@ ////////////////////////////////////////////////////////////////////// -BOSL_VERSION = [2,0,428]; +BOSL_VERSION = [2,0,429]; // Section: BOSL Library Version Functions