mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-28 15:59:45 +00:00
Changed circle_point_tangents() to return just a list of 2D tangent points.
This commit is contained in:
parent
02b765aae0
commit
4f88775ef9
3 changed files with 15 additions and 11 deletions
|
@ -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()
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
BOSL_VERSION = [2,0,428];
|
||||
BOSL_VERSION = [2,0,429];
|
||||
|
||||
|
||||
// Section: BOSL Library Version Functions
|
||||
|
|
Loading…
Reference in a new issue