mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-09-03 03:42:37 +02:00
Fixed errors in ruler(). Moved trace_polyline() to debug.scad.
This commit is contained in:
104
paths.scad
104
paths.scad
@@ -847,110 +847,6 @@ module path_extrude(path, convexity=10, clipsize=100) {
|
||||
}
|
||||
|
||||
|
||||
// Module: trace_polyline()
|
||||
// Description:
|
||||
// Renders lines between each point of a polyline path.
|
||||
// Can also optionally show the individual vertex points.
|
||||
// Arguments:
|
||||
// pline = The array of points in the polyline.
|
||||
// closed = If true, draw the segment from the last vertex to the first. Default: false
|
||||
// showpts = If true, draw vertices and control points.
|
||||
// N = Mark the first and every Nth vertex after in a different color and shape.
|
||||
// size = Diameter of the lines drawn.
|
||||
// color = Color to draw the lines (but not vertices) in.
|
||||
// Example(FlatSpin):
|
||||
// polyline = [for (a=[0:30:210]) 10*[cos(a), sin(a), sin(a)]];
|
||||
// trace_polyline(polyline, showpts=true, size=0.5, color="lightgreen");
|
||||
module trace_polyline(pline, closed=false, showpts=false, N=1, size=1, color="yellow") {
|
||||
assert(is_path(pline),"Input pline is not a path");
|
||||
sides = segs(size/2);
|
||||
pline = closed? close_path(pline) : pline;
|
||||
if (showpts) {
|
||||
for (i = [0:1:len(pline)-1]) {
|
||||
translate(pline[i]) {
|
||||
if (i%N == 0) {
|
||||
color("blue") sphere(d=size*2.5, $fn=8);
|
||||
} else {
|
||||
color("red") {
|
||||
cylinder(d=size/2, h=size*3, center=true, $fn=8);
|
||||
xrot(90) cylinder(d=size/2, h=size*3, center=true, $fn=8);
|
||||
yrot(90) cylinder(d=size/2, h=size*3, center=true, $fn=8);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (N!=3) {
|
||||
color(color) path_sweep(circle(d=size,$fn=sides), path3d(pline));
|
||||
} else {
|
||||
for (i = [0:1:len(pline)-2]) {
|
||||
if (N!=3 || (i%N) != 1) {
|
||||
color(color) extrude_from_to(pline[i], pline[i+1]) circle(d=size, $fn=sides);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Module: debug_polygon()
|
||||
// Description: A drop-in replacement for `polygon()` that renders and labels the path points.
|
||||
// Arguments:
|
||||
// points = The array of 2D polygon vertices.
|
||||
// paths = The path connections between the vertices.
|
||||
// convexity = The max number of walls a ray can pass through the given polygon paths.
|
||||
// Example(Big2D):
|
||||
// debug_polygon(
|
||||
// points=concat(
|
||||
// regular_ngon(or=10, n=8),
|
||||
// regular_ngon(or=8, n=8)
|
||||
// ),
|
||||
// paths=[
|
||||
// [for (i=[0:7]) i],
|
||||
// [for (i=[15:-1:8]) i]
|
||||
// ]
|
||||
// );
|
||||
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;
|
||||
echo(points=points);
|
||||
echo(paths=paths);
|
||||
linear_extrude(height=0.01, convexity=convexity, center=true) {
|
||||
polygon(points=points, paths=paths, convexity=convexity);
|
||||
}
|
||||
for (i = [0:1:len(points)-1]) {
|
||||
color("red") {
|
||||
up(0.2) {
|
||||
translate(points[i]) {
|
||||
linear_extrude(height=0.1, convexity=10, center=true) {
|
||||
text(text=str(i), size=size, halign="center", valign="center");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (j = [0:1:len(paths)-1]) {
|
||||
path = paths[j];
|
||||
translate(points[path[0]]) {
|
||||
color("cyan") up(0.1) cylinder(d=size*1.5, h=0.01, center=false, $fn=12);
|
||||
}
|
||||
translate(points[path[len(path)-1]]) {
|
||||
color("pink") up(0.11) cylinder(d=size*1.5, h=0.01, center=false, $fn=4);
|
||||
}
|
||||
for (i = [0:1:len(path)-1]) {
|
||||
midpt = (points[path[i]] + points[path[(i+1)%len(path)]])/2;
|
||||
color("blue") {
|
||||
up(0.2) {
|
||||
translate(midpt) {
|
||||
linear_extrude(height=0.1, convexity=10, center=true) {
|
||||
text(text=str(chr(65+j),i), size=size/2, halign="center", valign="center");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Module: path_spread()
|
||||
//
|
||||
// Description:
|
||||
|
Reference in New Issue
Block a user