mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-15 08:59:40 +00:00
Compare commits
No commits in common. "11b801ec4691a4bcf3d46a1be7bf66bc1305fead" and "f564a0f060e7dd802f2ca874d5bee3030e9ee51a" have entirely different histories.
11b801ec46
...
f564a0f060
3 changed files with 67 additions and 76 deletions
|
@ -634,7 +634,7 @@ function path_to_bezpath(path, closed, tangents, uniform=false, size, relsize) =
|
||||||
second + L*tangent2
|
second + L*tangent2
|
||||||
],
|
],
|
||||||
select(path,lastpt)
|
select(path,lastpt)
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -689,8 +689,7 @@ function path_to_bezcornerpath(path, closed, size, relsize) =
|
||||||
sizevect[i], relative),
|
sizevect[i], relative),
|
||||||
[path[pathlen-1]]
|
[path[pathlen-1]]
|
||||||
]
|
]
|
||||||
)
|
) flatten(roundpath);
|
||||||
flatten(roundpath);
|
|
||||||
|
|
||||||
|
|
||||||
/// Internal function: _bez_path_corner()
|
/// Internal function: _bez_path_corner()
|
||||||
|
@ -744,7 +743,9 @@ let(
|
||||||
// bz6 is p3
|
// bz6 is p3
|
||||||
bz3 = p2 + middir * bzdist, // center control point
|
bz3 = p2 + middir * bzdist, // center control point
|
||||||
bz2 = bz3 + midto12unit*(d1<d3 ? cornerlegmin : cornerlegmax),
|
bz2 = bz3 + midto12unit*(d1<d3 ? cornerlegmin : cornerlegmax),
|
||||||
bz1 = p1 - (d1<=d3 ? leglenmin : leglenmax)*p21unit,
|
bz1 = p1 - (d1<=d3 ? leglenmin :
|
||||||
|
leglenmax)*p21unit,
|
||||||
|
//norm(0.333*(bz2-p1)))*p21unit,
|
||||||
bz4 = bz3 - midto12unit*(d3<d1 ? cornerlegmin : cornerlegmax),
|
bz4 = bz3 - midto12unit*(d3<d1 ? cornerlegmin : cornerlegmax),
|
||||||
bz5 = p3 - (d3<=d1 ? leglenmin : leglenmax)*p23unit
|
bz5 = p3 - (d3<=d1 ? leglenmin : leglenmax)*p23unit
|
||||||
) [p1, bz1, bz2, bz3, bz4, bz5]; // do not include last control point
|
) [p1, bz1, bz2, bz3, bz4, bz5]; // do not include last control point
|
||||||
|
|
|
@ -735,20 +735,18 @@ function _rounding_offsets(edgespec,z_dir=1) =
|
||||||
// pts = [[-3.3, 1.7], [-3.7, -2.2], [3.8, -4.8], [-0.9, -2.4]];
|
// pts = [[-3.3, 1.7], [-3.7, -2.2], [3.8, -4.8], [-0.9, -2.4]];
|
||||||
// stroke(smooth_path(pts, uniform=false, relsize=0.1),width=.1);
|
// stroke(smooth_path(pts, uniform=false, relsize=0.1),width=.1);
|
||||||
// color("red")move_copies(pts)circle(r=.15,$fn=12);
|
// color("red")move_copies(pts)circle(r=.15,$fn=12);
|
||||||
module smooth_path(path, tangents, size, relsize, method="edges", splinesteps=10, uniform, closed=false) {no_module();}
|
module smooth_path(path, tangents, size, relsize, method="edges", splinesteps=10, uniform=false, closed=false) {no_module();}
|
||||||
function smooth_path(path, tangents, size, relsize, method="edges", splinesteps=10, uniform, closed) =
|
function smooth_path(path, tangents, size, relsize, method="edges", splinesteps=10, uniform=false, closed) =
|
||||||
is_1region(path)
|
is_1region(path) ? smooth_path(path[0], tangents, size, relsize, method, splinesteps, uniform, default(closed,true)) :
|
||||||
? smooth_path(path[0], tangents, size, relsize, method, splinesteps, uniform, default(closed,true))
|
assert(method=="edges" || method=="corners", "method must be \"edges\" or \"corners\".")
|
||||||
: assert(method=="edges" || method=="corners", "method must be \"edges\" or \"corners\".")
|
assert(method=="edges" || is_undef(tangent), "The tangents parameter is incompatible with method=\"corners\".")
|
||||||
assert(method=="edges" || (is_undef(tangents) && is_undef(uniform)), "The tangents and uniform parameters are incompatible with method=\"corners\".")
|
let (
|
||||||
let (
|
bez = method=="edges" ?
|
||||||
uniform = default(uniform,false),
|
path_to_bezpath(path, tangents=tangents, size=size, relsize=relsize, uniform=uniform, closed=default(closed,false))
|
||||||
bez = method=="edges"
|
|
||||||
? path_to_bezpath(path, tangents=tangents, size=size, relsize=relsize, uniform=uniform, closed=default(closed,false))
|
|
||||||
: path_to_bezcornerpath(path, size=size, relsize=relsize, closed=default(closed,false)),
|
: path_to_bezcornerpath(path, size=size, relsize=relsize, closed=default(closed,false)),
|
||||||
smoothed = bezpath_curve(bez,splinesteps=splinesteps)
|
smoothed = bezpath_curve(bez,splinesteps=splinesteps)
|
||||||
)
|
)
|
||||||
closed ? list_unwrap(smoothed) : smoothed;
|
closed ? list_unwrap(smoothed) : smoothed;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1793,7 +1793,7 @@ module glued_circles(r, spread=10, tangent=30, d, anchor=CENTER, spin=0) {
|
||||||
// Examples(2D):
|
// Examples(2D):
|
||||||
// squircle(size=50, squareness=0.4);
|
// squircle(size=50, squareness=0.4);
|
||||||
// squircle([80,60], 0.7, $fn=64);
|
// squircle([80,60], 0.7, $fn=64);
|
||||||
// Example(3D,VPD=48,VPR=[40,0,40],NoAxes): Corner differences between the three squircle styles for squareness=0.5. Style "superellipse" is pink, "fg" is gold, "bezier" is blue.
|
// Example(2D,VPD=48,VPR=[40,0,40],NoAxes): Corner differences between the three squircle styles for squareness=0.5. Style "superellipse" is pink, "fg" is gold, "bezier" is blue.
|
||||||
// color("pink") squircle(size=50, style="superellipse", squareness=0.5, $fn=256);
|
// color("pink") squircle(size=50, style="superellipse", squareness=0.5, $fn=256);
|
||||||
// color("yellow") up(1) squircle(size=50, style="fg", squareness=0.5, $fn=256);
|
// color("yellow") up(1) squircle(size=50, style="fg", squareness=0.5, $fn=256);
|
||||||
// color("lightblue") up(2) squircle(size=50, style="bezier", squareness=0.5, $fn=256);
|
// color("lightblue") up(2) squircle(size=50, style="bezier", squareness=0.5, $fn=256);
|
||||||
|
@ -1854,11 +1854,9 @@ function _squircle_fg(size, squareness) = [
|
||||||
) p*[cos(theta), aspect*sin(theta)]
|
) p*[cos(theta), aspect*sin(theta)]
|
||||||
];
|
];
|
||||||
|
|
||||||
function squircle_radius_fg(squareness, r, angle) =
|
function squircle_radius_fg(squareness, r, angle) = let(
|
||||||
let(
|
|
||||||
s2a = abs(squareness*sin(2*angle))
|
s2a = abs(squareness*sin(2*angle))
|
||||||
)
|
) s2a>0 ? r*sqrt(2)/s2a * sqrt(1 - sqrt(1 - s2a*s2a)) : r;
|
||||||
s2a>0 ? r*sqrt(2)/s2a * sqrt(1 - sqrt(1 - s2a*s2a)) : r;
|
|
||||||
|
|
||||||
function _linearize_squareness(s) =
|
function _linearize_squareness(s) =
|
||||||
// from Chamberlain Fong (2016). "Squircular Calculations". arXiv.
|
// from Chamberlain Fong (2016). "Squircular Calculations". arXiv.
|
||||||
|
@ -1886,33 +1884,27 @@ function _squircle_se(size, squareness) = [
|
||||||
) [ra*x, rb*y] / r
|
) [ra*x, rb*y] / r
|
||||||
];
|
];
|
||||||
|
|
||||||
function squircle_radius_se(n, r, angle) =
|
function squircle_radius_se(n, r, angle) = let(
|
||||||
let(
|
|
||||||
x = cos(angle),
|
x = cos(angle),
|
||||||
y = sin(angle)
|
y = sin(angle)
|
||||||
)
|
) (abs(x)^n + abs(y)^n)^(1/n) / r;
|
||||||
(abs(x)^n + abs(y)^n)^(1/n) / r;
|
|
||||||
|
|
||||||
function _squircle_se_exponent(squareness) =
|
function _squircle_se_exponent(squareness) = let(
|
||||||
let(
|
|
||||||
// limit squareness; error if >0.99889, limit is smaller for r>1
|
// limit squareness; error if >0.99889, limit is smaller for r>1
|
||||||
s=min(0.998,squareness),
|
s=min(0.998,squareness),
|
||||||
rho = 1 + s*(sqrt(2)-1),
|
rho = 1 + s*(sqrt(2)-1),
|
||||||
x = rho / sqrt(2)
|
x = rho / sqrt(2)
|
||||||
)
|
) log(0.5) / log(x);
|
||||||
log(0.5) / log(x);
|
|
||||||
|
|
||||||
|
|
||||||
/* Bezier squircle function */
|
/* Bezier squircle function */
|
||||||
|
|
||||||
function _squircle_bz(size, squareness) =
|
function _squircle_bz(size, squareness) = let(
|
||||||
let(
|
|
||||||
splinesteps = $fn>=12 ? round($fn/4) : 10,
|
splinesteps = $fn>=12 ? round($fn/4) : 10,
|
||||||
size = is_num(size) ? [size,size] : point2d(size),
|
size = is_num(size) ? [size,size] : point2d(size),
|
||||||
sq = square(size, center=true),
|
sq = square(size, center=true),
|
||||||
bez = path_to_bezcornerpath(sq, relsize=1-squareness, closed=true)
|
bez = path_to_bezcornerpath(sq, relsize=1-squareness, closed=true)
|
||||||
)
|
) bezpath_curve(bez, splinesteps=splinesteps);
|
||||||
bezpath_curve(bez, splinesteps=splinesteps);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue