mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +00:00
Fixed debug_polygon bug. Tweaked error reporting for round_corners
and added new examples.
This commit is contained in:
parent
3825bd0cc8
commit
ac0293ef74
2 changed files with 22 additions and 2 deletions
|
@ -72,7 +72,7 @@ module trace_path(path, closed=false, showpts=false, N=1, size=1, color="yellow"
|
||||||
// );
|
// );
|
||||||
module debug_polygon(points, paths=undef, convexity=2, size=1)
|
module debug_polygon(points, paths=undef, convexity=2, size=1)
|
||||||
{
|
{
|
||||||
pths = is_undef(paths)? [for (i=[0:1:len(points)-1]) i] : is_num(paths[0])? [paths] : paths;
|
paths = is_undef(paths)? [[for (i=[0:1:len(points)-1]) i]] : is_num(paths[0])? [paths] : paths;
|
||||||
echo(points=points);
|
echo(points=points);
|
||||||
echo(paths=paths);
|
echo(paths=paths);
|
||||||
linear_extrude(height=0.01, convexity=convexity, center=true) {
|
linear_extrude(height=0.01, convexity=convexity, center=true) {
|
||||||
|
|
|
@ -198,6 +198,26 @@ include <structs.scad>
|
||||||
// // Try changing the value to see the effect.
|
// // Try changing the value to see the effect.
|
||||||
// rpath = round_corners(path3d, joint=rounding, k=1, method="smooth", closed=false);
|
// rpath = round_corners(path3d, joint=rounding, k=1, method="smooth", closed=false);
|
||||||
// path_sweep( regular_ngon(n=36, or=.1), rpath);
|
// path_sweep( regular_ngon(n=36, or=.1), rpath);
|
||||||
|
// Example(2D): The rounding invocation that is commented out gives an error because the rounding parameters interfere with each other. The error message gives a list of factors that can help you fix this: [0.852094, 0.852094, 1.85457, 10.1529]
|
||||||
|
// $fn=64;
|
||||||
|
// path = [[0, 0],[10, 0],[20, 20],[30, -10]];
|
||||||
|
// debug_polygon(path);
|
||||||
|
// //polygon(round_corners(path,cut = [1,3,1,1], method="circle"));
|
||||||
|
// Example(2D): The list of factors shows that the problem is in the first two rounding values, because the factors are smaller than one. If we multiply the first two parameters by 0.85 then the roundings fit. The verbose option gives us the same fit factors.
|
||||||
|
// $fn=64;
|
||||||
|
// path = [[0, 0],[10, 0],[20, 20],[30, -10]];
|
||||||
|
// polygon(round_corners(path,cut = [0.85,3*0.85,1,1], method="circle", verbose=true));
|
||||||
|
// Example(2D): From the fit factors we can see that rounding at vertices 2 and 3 could be increased a lot. Applying those factors we get this more rounded shape. The new fit factors show that we can still further increase the rounding parameters if we wish.
|
||||||
|
// $fn=64;
|
||||||
|
// path = [[0, 0],[10, 0],[20, 20],[30, -10]];
|
||||||
|
// polygon(round_corners(path,cut = [0.85,3*0.85,2.13, 10.15], method="circle",verbose=true));
|
||||||
|
// Example(2D): Using the `joint` parameter it's easier to understand whether your roundvers will fit. We can guarantee a fairly large roundover on any path by picking each one to use up half the segment distance along the shorter of its two segments:
|
||||||
|
// $fn=64;
|
||||||
|
// path = [[0, 0],[10, 0],[20, 20],[30, -10]];
|
||||||
|
// path_len = path_segment_lengths(path,closed=true);
|
||||||
|
// halflen = [for(i=idx(path)) min(select(path_len,i-1,i))/2];
|
||||||
|
// polygon(round_corners(path,joint = halflen, method="circle",verbose=true));
|
||||||
|
|
||||||
module round_corners(path, method="circle", radius, cut, joint, k, closed=true, verbose=false) {no_module();}
|
module round_corners(path, method="circle", radius, cut, joint, k, closed=true, verbose=false) {no_module();}
|
||||||
function round_corners(path, method="circle", radius, cut, joint, k, closed=true, verbose=false) =
|
function round_corners(path, method="circle", radius, cut, joint, k, closed=true, verbose=false) =
|
||||||
assert(in_list(method,["circle", "smooth", "chamfer"]), "method must be one of \"circle\", \"smooth\" or \"chamfer\"")
|
assert(in_list(method,["circle", "smooth", "chamfer"]), "method must be one of \"circle\", \"smooth\" or \"chamfer\"")
|
||||||
|
@ -263,7 +283,7 @@ function round_corners(path, method="circle", radius, cut, joint, k, closed=true
|
||||||
],
|
],
|
||||||
dummy = verbose ? echo("Roundover scale factors:",scalefactors) : 0
|
dummy = verbose ? echo("Roundover scale factors:",scalefactors) : 0
|
||||||
)
|
)
|
||||||
assert(min(scalefactors)>=1,"Roundovers are too big for the path")
|
assert(min(scalefactors)>=1,str("Roundovers are too big for the path. If you multitply them by this vector they should fit: ",scalefactors))
|
||||||
[
|
[
|
||||||
for(i=[0:1:len(path)-1]) each
|
for(i=[0:1:len(path)-1]) each
|
||||||
(dk[i][0] == 0)? [path[i]] :
|
(dk[i][0] == 0)? [path[i]] :
|
||||||
|
|
Loading…
Reference in a new issue