Skip to content

Commit c034c95

Browse files
committed
Added catenary_path().
1 parent 46f7835 commit c034c95

File tree

3 files changed

+80
-36
lines changed

3 files changed

+80
-36
lines changed

.github/workflows/main.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ name: Checks
22
on: [pull_request]
33

44
jobs:
5+
VersionCheck:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Checkout
9+
uses: actions/checkout@v3
10+
11+
- name: Verify Version Bump
12+
run: |
13+
git fetch origin master
14+
git diff --summary FETCH_HEAD version.scad | grep -q '^BOSL_VERSION'
15+
516
Regressions:
617
runs-on: ubuntu-latest
718
steps:

.github/workflows/pr_merge.yml

Lines changed: 0 additions & 36 deletions
This file was deleted.

drawing.scad

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,75 @@ module arc(n, r, angle, d, cp, points, corner, width, thickness, start, wedge=fa
863863
}
864864

865865

866+
// Function: catenary_path()
867+
// Synopsis: Returns a 2D Catenary chain or arch path.
868+
// SynTags: Path
869+
// Topics: Paths
870+
// See Also: circle(), stroke()
871+
// Usage:
872+
// path = catenary_path(width, droop=|angle=, n=);
873+
// Description:
874+
// Returns a 2D Catenary path, which is the path a chain held at both ends will take.
875+
// The path will have the endpoints at `[±width/2, 0]`, and the middle of the path will droop
876+
// towards Y- if the given droop= or angle= is positive. It will droop towards Y+ if the
877+
// droop= or angle= is negative. You *must* specify one of droop= or angle=.
878+
// Arguments:
879+
// width = The straight-line distance between the endpoints of the path.
880+
// droop = If given, specifies the height difference between the endpoints and the hanging middle of the path. If given a negative value, returns an arch *above* the Y axis.
881+
// n = The number of points to return in the path. Default: 100
882+
// ---
883+
// angle = If given, specifies the angle that the path will droop by at the endpoints. If given a negative value, returns an arch *above* the Y axis.
884+
// Example(2D): By Droop
885+
// stroke(catenary_path(100, droop=30));
886+
// Example(2D): By Angle
887+
// stroke(catenary_path(100, angle=30));
888+
// Example(2D): Upwards Arch by Angle
889+
// stroke(catenary_path(100, angle=30));
890+
// Example(2D): Upwards Arch by Height Delta
891+
// stroke(catenary_path(100, droop=-30));
892+
// Example(2D): Specifying Vertex Count
893+
// stroke(catenary_path(100, angle=-85, n=11), dots="dot");
894+
// Example: Sweeping a Catenary Path
895+
// path = xrot(90, p=path3d(catenary_path(100, droop=20, n=41)));
896+
// path_sweep(circle(r=1.5, $fn=24), path);
897+
function catenary_path(width, droop, n=100, angle) =
898+
assert(one_defined([droop, angle],"droop,angle"))
899+
let(
900+
sgn = is_undef(droop)? sign(angle) : sign(droop),
901+
droop = droop==undef? undef : abs(droop),
902+
angle = angle==undef? undef : abs(angle)
903+
)
904+
assert(is_finite(width) && width>0, "Bad width= value.")
905+
assert(is_integer(n) && n>0, "Bad n= value. Must be a positive integer.")
906+
assert(is_undef(droop) || is_finite(droop), "Bad droop= value.")
907+
assert(is_undef(angle) || (is_finite(angle) && angle != 0 && abs(angle) < 90), "Bad angle= value.")
908+
let(
909+
lup = is_undef(droop)
910+
? [
911+
for (x=[0:0.01:10])
912+
let(
913+
p1 = [x-0.001, cosh(x-0.001)-1],
914+
p2 = [x+0.001, cosh(x+0.001)-1],
915+
delta = p2-p1,
916+
ang = atan2(delta.y, delta.x)
917+
)
918+
[ang, x]
919+
]
920+
: [ for (x=[0.001:0.1:10]) [(cosh(x)-1)/x, x] ],
921+
lval = is_undef(droop)
922+
? angle
923+
: droop / (width/2),
924+
scx = lookup(lval, lup),
925+
droop = !is_undef(droop)? droop :
926+
(cosh(scx)-1) * width/2 / scx,
927+
path = [
928+
for (x = lerpn(-scx,scx,n))
929+
[x, cosh(x)-1] * width/2 / scx - [0,droop]
930+
],
931+
out = sgn>0? path : yflip(p=path)
932+
) out;
933+
934+
866935
// Function: helix()
867936
// Synopsis: Creates a 2d spiral or 3d helical path.
868937
// SynTags: Path

0 commit comments

Comments
 (0)