mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +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);
|
// tangents = circle_point_tangents(r|d, cp, pt);
|
||||||
// Description:
|
// Description:
|
||||||
// Given a 2d circle and a 2d point outside that circle, finds the 2d tangent point(s) on the circle for a
|
// 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:
|
// Arguments:
|
||||||
// r = Radius of the circle.
|
// r = Radius of the circle.
|
||||||
// d = Diameter 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.
|
// pt = The coordinates of the 2d external point.
|
||||||
// Example:
|
// Example:
|
||||||
// cp = [-10,-10]; r = 30; pt = [30,10];
|
// 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("yellow") translate(cp) circle(r=r);
|
||||||
// color("cyan") for(tp=tanpts) {stroke([tp,pt]); stroke([tp,cp]);}
|
// color("cyan") for(tp=tanpts) {stroke([tp,pt]); stroke([tp,cp]);}
|
||||||
// color("red") move_copies(tanpts) circle(d=3,$fn=12);
|
// color("red") move_copies(tanpts) circle(d=3,$fn=12);
|
||||||
|
@ -1368,7 +1368,7 @@ function circle_point_tangents(r, d, cp, pt) =
|
||||||
let(
|
let(
|
||||||
relang = acos(r/dist),
|
relang = acos(r/dist),
|
||||||
angs = [baseang + relang, baseang - relang]
|
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()
|
// Function: circle_circle_tangents()
|
||||||
|
|
|
@ -601,13 +601,17 @@ module test_find_circle_3points() {
|
||||||
|
|
||||||
|
|
||||||
module test_circle_point_tangents() {
|
module test_circle_point_tangents() {
|
||||||
tangs = circle_point_tangents(r=50,cp=[0,0],pt=[50*sqrt(2),0]);
|
testvals = [
|
||||||
assert(approx(subindex(tangs,0), [45,-45]));
|
// cp r pt expect
|
||||||
expected = [for (ang=subindex(tangs,0)) polar_to_xy(50,ang)];
|
[[0,0], 50, [50*sqrt(2),0], [polar_to_xy(50,45), polar_to_xy(50,-45)]],
|
||||||
got = subindex(tangs,1);
|
[[5,10], 50, [5+50*sqrt(2),10], [[5,10]+polar_to_xy(50,45), [5,10]+polar_to_xy(50,-45)]],
|
||||||
if (!approx(flatten(got), flatten(expected))) {
|
[[0,0], 50, [0,50*sqrt(2)], [polar_to_xy(50,135), polar_to_xy(50,45)]],
|
||||||
echo("TAN_PTS:", got=got, expected=expected, delta=got-expected);
|
[[5,10], 50, [5,10+50*sqrt(2)], [[5,10]+polar_to_xy(50,135), [5,10]+polar_to_xy(50,45)]]
|
||||||
assert(approx(flatten(got), flatten(expected)));
|
];
|
||||||
|
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();
|
*test_circle_point_tangents();
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
BOSL_VERSION = [2,0,428];
|
BOSL_VERSION = [2,0,429];
|
||||||
|
|
||||||
|
|
||||||
// Section: BOSL Library Version Functions
|
// Section: BOSL Library Version Functions
|
||||||
|
|
Loading…
Reference in a new issue