mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-15 08:59:40 +00:00
Compare commits
4 commits
453a1cd6f1
...
9477fbed08
Author | SHA1 | Date | |
---|---|---|---|
|
9477fbed08 | ||
|
504c92bba9 | ||
|
72a2c1470a | ||
|
495ebbefd8 |
1 changed files with 12 additions and 8 deletions
|
@ -2003,17 +2003,20 @@ function reuleaux_polygon(n=3, r, d, anchor=CENTER, spin=0) =
|
||||||
// When called as a module, creates a 2D squircle with the desired squareness. Uses "intersect" type anchoring.
|
// When called as a module, creates a 2D squircle with the desired squareness. Uses "intersect" type anchoring.
|
||||||
// When called as a function, returns a 2D path for a squircle.
|
// When called as a function, returns a 2D path for a squircle.
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// squareness = Value between 0 and 1. Controls the shape of the squircle. When `squareness=0` the shape is a circle, and when `squareness=1` the shape is a square. Default: 0.8
|
// squareness = Value between 0 and 1. Controls the shape of the squircle. When `squareness=0` the shape is a circle, and when `squareness=1` the shape is a square. Default: 0.7
|
||||||
// size = Bounding box of the squircle, same as the `size` parameter in `square()`, can be a single number or an `[xsize,ysize]` vector. Default: [10,10]
|
// size = Bounding box of the squircle, same as the `size` parameter in `square()`, can be a single number or an `[xsize,ysize]` vector. Default: [10,10]
|
||||||
// $fn = Number of points. Special variables `$fs` and `$fa` are ignored. If set, `$fn` must be 12 or greater, and is rounded to the nearest multiple of 4. Points are generated non-uniformly around the squircle so they are more dense sharper curves. Default if not set: 40
|
// $fn = Number of points. Special variables `$fs` and `$fa` are ignored. If set, `$fn` must be 12 or greater, and is rounded to the nearest multiple of 4. Points are generated non-uniformly around the squircle so they are more dense sharper curves. Default if not set: 40
|
||||||
// Examples(2D):
|
// Examples(2D):
|
||||||
// squircle(squareness=0.5, size=50);
|
// squircle(squareness=0.4, size=50);
|
||||||
// squircle(0.95, [80,60], $fn=64);
|
// squircle(0.8, [80,60], $fn=64);
|
||||||
|
// Examples(2D): Ten increments of squareness parameter
|
||||||
|
// for(sq=[0:0.1:1])
|
||||||
|
// stroke(squircle(sq, 100, $fn=128), closed=true, width=0.5);
|
||||||
// Examples(2D): Standard vector anchors are based on extents
|
// Examples(2D): Standard vector anchors are based on extents
|
||||||
// squircle(0.8, 50) show_anchors(custom=false);
|
// squircle(0.8, 50) show_anchors(custom=false);
|
||||||
// Examples(2D): Named anchors exist for the sides and corners
|
// Examples(2D): Named anchors exist for the sides and corners
|
||||||
// squircle(0.8, 50) show_anchors(std=false);
|
// squircle(0.8, 50) show_anchors(std=false);
|
||||||
module squircle(squareness=0.8, size=[10,10], anchor=CENTER, spin=0) {
|
module squircle(squareness=0.7, size=[10,10], anchor=CENTER, spin=0) {
|
||||||
check = assert(squareness >= 0 && squareness <= 1);
|
check = assert(squareness >= 0 && squareness <= 1);
|
||||||
bbox = is_num(size) ? [size,size] : point2d(size);
|
bbox = is_num(size) ? [size,size] : point2d(size);
|
||||||
assert(all_positive(bbox), "All components of size must be positive.");
|
assert(all_positive(bbox), "All components of size must be positive.");
|
||||||
|
@ -2021,11 +2024,11 @@ module squircle(squareness=0.8, size=[10,10], anchor=CENTER, spin=0) {
|
||||||
anchors = [
|
anchors = [
|
||||||
for (i = [0:1:3]) let(
|
for (i = [0:1:3]) let(
|
||||||
ca = 360 - i*90,
|
ca = 360 - i*90,
|
||||||
cp = polar_to_xy(squircle_radius(squareness, bbox[0], ca), ca)
|
cp = polar_to_xy(squircle_radius(squareness, bbox[0]/2, ca), ca)
|
||||||
) named_anchor(str("side",i), cp, unit(cp,BACK), 0),
|
) named_anchor(str("side",i), cp, unit(cp,BACK), 0),
|
||||||
for (i = [0:1:3]) let(
|
for (i = [0:1:3]) let(
|
||||||
ca = 360-45 - i*90,
|
ca = 360-45 - i*90,
|
||||||
cp = polar_to_xy(squircle_radius(squareness, bbox[0], ca), ca)
|
cp = polar_to_xy(squircle_radius(squareness, bbox[0]/2, ca), ca)
|
||||||
) named_anchor(str("corner",i), cp, unit(cp,BACK), 0)
|
) named_anchor(str("corner",i), cp, unit(cp,BACK), 0)
|
||||||
];
|
];
|
||||||
attachable(anchor,spin, two_d=true, path=path, extent=false, anchors=anchors) {
|
attachable(anchor,spin, two_d=true, path=path, extent=false, anchors=anchors) {
|
||||||
|
@ -2035,10 +2038,11 @@ module squircle(squareness=0.8, size=[10,10], anchor=CENTER, spin=0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function squircle(squareness=0.8, size=[10,10]) =
|
function squircle(squareness=0.7, size=[10,10]) =
|
||||||
assert(squareness >= 0 && squareness <= 1) [
|
assert(squareness >= 0 && squareness <= 1) [
|
||||||
let(
|
let(
|
||||||
sq = sqrt(squareness), // somewhat linearize the squareness response
|
sqlim = max(0, min(1, squareness)),
|
||||||
|
sq = sqrt(sqlim*(2-sqlim)), // somewhat linearize squareness response
|
||||||
bbox = is_num(size) ? [size,size] : point2d(size),
|
bbox = is_num(size) ? [size,size] : point2d(size),
|
||||||
aspect = bbox[1] / bbox[0],
|
aspect = bbox[1] / bbox[0],
|
||||||
r = 0.5 * bbox[0],
|
r = 0.5 * bbox[0],
|
||||||
|
|
Loading…
Reference in a new issue