mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +00:00
Renamed place_copies() to move_copies()
This commit is contained in:
parent
6183e6d0d2
commit
971c1e795f
13 changed files with 45 additions and 46 deletions
10
beziers.scad
10
beziers.scad
|
@ -82,15 +82,15 @@ function bez_point(curve,u)=
|
|||
// n = The number of points to generate along the bezier curve.
|
||||
// Example(2D): Quadratic (Degree 2) Bezier.
|
||||
// bez = [[0,0], [30,30], [80,0]];
|
||||
// place_copies(bezier_curve(bez, 16)) sphere(r=1);
|
||||
// move_copies(bezier_curve(bez, 16)) sphere(r=1);
|
||||
// trace_bezier(bez, N=len(bez)-1);
|
||||
// Example(2D): Cubic (Degree 3) Bezier
|
||||
// bez = [[0,0], [5,35], [60,-25], [80,0]];
|
||||
// place_copies(bezier_curve(bez, 16)) sphere(r=1);
|
||||
// move_copies(bezier_curve(bez, 16)) sphere(r=1);
|
||||
// trace_bezier(bez, N=len(bez)-1);
|
||||
// Example(2D): Degree 4 Bezier.
|
||||
// bez = [[0,0], [5,15], [40,20], [60,-15], [80,0]];
|
||||
// place_copies(bezier_curve(bez, 16)) sphere(r=1);
|
||||
// move_copies(bezier_curve(bez, 16)) sphere(r=1);
|
||||
// trace_bezier(bez, N=len(bez)-1);
|
||||
function bezier_curve(curve,n) = [for(i=[0:1:n-1]) bez_point(curve, i/(n-1))];
|
||||
|
||||
|
@ -1006,7 +1006,7 @@ module trace_bezier_patches(patches=[], size=1, showcps=false, splinesteps=16)
|
|||
{
|
||||
if (showcps) {
|
||||
for (patch = patches) {
|
||||
place_copies(flatten(patch)) color("red") sphere(d=size*2);
|
||||
move_copies(flatten(patch)) color("red") sphere(d=size*2);
|
||||
color("cyan")
|
||||
if (is_tripatch(patch)) {
|
||||
for (i=[0:1:len(patch)-2], j=[0:1:len(patch[i])-2]) {
|
||||
|
@ -1021,7 +1021,7 @@ module trace_bezier_patches(patches=[], size=1, showcps=false, splinesteps=16)
|
|||
}
|
||||
}
|
||||
vnf = bezier_patch(patch, splinesteps=splinesteps);
|
||||
color("blue") place_copies(vnf[0]) sphere(d=size);
|
||||
color("blue") move_copies(vnf[0]) sphere(d=size);
|
||||
}
|
||||
}
|
||||
bezier_polyhedron(patches=patches, splinesteps=splinesteps);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
module translate_copies(a=[[0,0,0]]) place_copies(a) children();
|
||||
module translate_copies(a=[[0,0,0]]) move_copies(a) children();
|
||||
module xmove(x) right(x) children();
|
||||
module ymove(y) back(y) children();
|
||||
module zmove(z) up(z) children();
|
||||
|
|
|
@ -13,13 +13,13 @@
|
|||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// Module: place_copies()
|
||||
// Module: move_copies()
|
||||
//
|
||||
// Description:
|
||||
// Makes copies of the given children at each of the given offsets.
|
||||
// Translates copies of all children to each given translation offset.
|
||||
//
|
||||
// Usage:
|
||||
// place_copies(a) ...
|
||||
// move_copies(a) ...
|
||||
//
|
||||
// Arguments:
|
||||
// a = Array of XYZ offset vectors. Default `[[0,0,0]]`
|
||||
|
@ -30,8 +30,8 @@
|
|||
//
|
||||
// Example:
|
||||
// #sphere(r=10);
|
||||
// place_copies([[-25,-25,0], [25,-25,0], [0,0,50], [0,25,0]]) sphere(r=10);
|
||||
module place_copies(a=[[0,0,0]])
|
||||
// move_copies([[-25,-25,0], [25,-25,0], [0,0,50], [0,25,0]]) sphere(r=10);
|
||||
module move_copies(a=[[0,0,0]])
|
||||
{
|
||||
assert(is_list(a));
|
||||
for ($idx = idx(a)) {
|
||||
|
|
|
@ -113,7 +113,7 @@ function distance_from_line(line, pt) =
|
|||
// n = line_normal(p1,p2);
|
||||
// stroke([p1,p2], endcap2="arrow2");
|
||||
// color("green") stroke([p1,p1+10*n], endcap2="arrow2");
|
||||
// color("blue") place_copies([p1,p2]) circle(d=2, $fn=12);
|
||||
// color("blue") move_copies([p1,p2]) circle(d=2, $fn=12);
|
||||
function line_normal(p1,p2) =
|
||||
is_undef(p2)? line_normal(p1[0],p1[1]) :
|
||||
unit([p1.y-p2.y,p2.x-p1.x]);
|
||||
|
@ -895,7 +895,7 @@ function in_front_of_plane(plane, point) =
|
|||
// stroke([[0,0],rad*[cos(315),sin(315)]]);
|
||||
// }
|
||||
// }
|
||||
// place_copies(pts) color("blue") circle(d=2, $fn=12);
|
||||
// move_copies(pts) color("blue") circle(d=2, $fn=12);
|
||||
// translate(circ[0]) color("red") circle(d=2, $fn=12);
|
||||
// labels = [[pts[0], "pt1"], [pts[1],"pt2"], [pts[2],"pt3"], [circ[0], "CP"], [circ[0]+[cos(315),sin(315)]*rad*0.7, "r"]];
|
||||
// for(l=labels) translate(l[0]+[0,2]) color("black") text(text=l[1], size=2.5, halign="center");
|
||||
|
@ -935,7 +935,7 @@ function find_circle_2tangents(pt1, pt2, pt3, r=undef, d=undef) =
|
|||
// circ = find_circle_3points(pts[0], pts[1], pts[2]);
|
||||
// translate(circ[0]) color("green") stroke(circle(r=circ[1]),closed=true,$fn=72);
|
||||
// translate(circ[0]) color("red") circle(d=3, $fn=12);
|
||||
// place_copies(pts) color("blue") circle(d=3, $fn=12);
|
||||
// move_copies(pts) color("blue") circle(d=3, $fn=12);
|
||||
function find_circle_3points(pt1, pt2, pt3) =
|
||||
(is_undef(pt2) && is_undef(pt3) && is_list(pt1))? find_circle_3points(pt1[0], pt1[1], pt1[2]) :
|
||||
collinear(pt1,pt2,pt3)? [undef,undef,undef] :
|
||||
|
@ -984,8 +984,8 @@ function find_circle_3points(pt1, pt2, pt3) =
|
|||
// tanpts = subindex(find_circle_tangents(r=r, cp=cp, pt=pt),1);
|
||||
// color("yellow") translate(cp) circle(r=r);
|
||||
// color("cyan") for(tp=tanpts) {stroke([tp,pt]); stroke([tp,cp]);}
|
||||
// color("red") place_copies(tanpts) circle(d=3,$fn=12);
|
||||
// color("blue") place_copies([cp,pt]) circle(d=3,$fn=12);
|
||||
// color("red") move_copies(tanpts) circle(d=3,$fn=12);
|
||||
// color("blue") move_copies([cp,pt]) circle(d=3,$fn=12);
|
||||
function find_circle_tangents(r, d, cp, pt) =
|
||||
assert(is_num(r) || is_num(d))
|
||||
assert(is_vector(cp))
|
||||
|
@ -1159,15 +1159,15 @@ function polygon_shift_to_closest_point(path, pt) =
|
|||
// pent = subdivide_path([for(i=[0:4])[sin(72*i),cos(72*i)]],30);
|
||||
// circ = circle($fn=30,r=2.2);
|
||||
// reindexed = reindex_polygon(circ,pent);
|
||||
// place_copies(concat(circ,pent)) circle(r=.1,$fn=32);
|
||||
// color("red") place_copies([pent[0],circ[0]]) circle(r=.1,$fn=32);
|
||||
// move_copies(concat(circ,pent)) circle(r=.1,$fn=32);
|
||||
// color("red") move_copies([pent[0],circ[0]]) circle(r=.1,$fn=32);
|
||||
// color("blue") translate(reindexed[0])circle(r=.1,$fn=32);
|
||||
// Example(2D): The indexing that minimizes the total distance will not necessarily associate the nearest point of `poly` with the reference, as in this example where again the blue dot indicates the 0th entry in the reindexed result.
|
||||
// pent = move([3.5,-1],p=subdivide_path([for(i=[0:4])[sin(72*i),cos(72*i)]],30));
|
||||
// circ = circle($fn=30,r=2.2);
|
||||
// reindexed = reindex_polygon(circ,pent);
|
||||
// place_copies(concat(circ,pent)) circle(r=.1,$fn=32);
|
||||
// color("red") place_copies([pent[0],circ[0]]) circle(r=.1,$fn=32);
|
||||
// move_copies(concat(circ,pent)) circle(r=.1,$fn=32);
|
||||
// color("red") move_copies([pent[0],circ[0]]) circle(r=.1,$fn=32);
|
||||
// color("blue") translate(reindexed[0])circle(r=.1,$fn=32);
|
||||
function reindex_polygon(reference, poly, return_error=false) =
|
||||
assert(is_path(reference) && is_path(poly))
|
||||
|
@ -1213,8 +1213,8 @@ function reindex_polygon(reference, poly, return_error=false) =
|
|||
// $fn=32;
|
||||
// pentagon = subdivide_path(pentagon(side=2),60);
|
||||
// hexagon = subdivide_path(hexagon(side=2.7),60);
|
||||
// color("red") place_copies(scale(1.4,p=align_polygon(pentagon,hexagon,[0:10:359]))) circle(r=.1);
|
||||
// place_copies(concat(pentagon,hexagon))circle(r=.1);
|
||||
// color("red") move_copies(scale(1.4,p=align_polygon(pentagon,hexagon,[0:10:359]))) circle(r=.1);
|
||||
// move_copies(concat(pentagon,hexagon))circle(r=.1);
|
||||
function align_polygon(reference, poly, angles, cp) =
|
||||
assert(is_path(reference) && is_path(poly))
|
||||
assert(len(reference)==len(poly), "Polygons must be the same length to be aligned in align_polygon")
|
||||
|
|
|
@ -83,7 +83,7 @@ module hull_points(points, fast=false) {
|
|||
// Example(2D):
|
||||
// pts = [[-10,-10], [0,10], [10,10], [12,-10]];
|
||||
// path = hull2d_path(pts);
|
||||
// place_copies(pts) color("red") sphere(1);
|
||||
// move_copies(pts) color("red") sphere(1);
|
||||
// polygon(points=pts, paths=[path]);
|
||||
function hull2d_path(points) =
|
||||
(len(points) < 3)? [] : let(
|
||||
|
@ -156,7 +156,7 @@ function _remove_conflicts_and_insert_point(polygon, conflicts, point) =
|
|||
// Example(3D):
|
||||
// pts = [[-20,-20,0], [20,-20,0], [0,20,5], [0,0,20]];
|
||||
// faces = hull3d_faces(pts);
|
||||
// place_copies(pts) color("red") sphere(1);
|
||||
// move_copies(pts) color("red") sphere(1);
|
||||
// %polyhedron(points=pts, faces=faces);
|
||||
function hull3d_faces(points) =
|
||||
(len(points) < 3)? list_range(len(points)) : let (
|
||||
|
|
20
paths.scad
20
paths.scad
|
@ -1133,34 +1133,34 @@ function _sum_preserving_round(data, index=0) =
|
|||
// method = One of `"length"` or `"segment"`. If `"length"`, adds vertices evenly along the total path length. If `"segment"`, adds points evenly among the segments. Default: `"length"`
|
||||
// Example(2D):
|
||||
// mypath = subdivide_path(square([2,2],center=true), 12);
|
||||
// place_copies(mypath)circle(r=.1,$fn=32);
|
||||
// move_copies(mypath)circle(r=.1,$fn=32);
|
||||
// Example(2D):
|
||||
// mypath = subdivide_path(square([8,2],center=true), 12);
|
||||
// place_copies(mypath)circle(r=.2,$fn=32);
|
||||
// move_copies(mypath)circle(r=.2,$fn=32);
|
||||
// Example(2D):
|
||||
// mypath = subdivide_path(square([8,2],center=true), 12, method="segment");
|
||||
// place_copies(mypath)circle(r=.2,$fn=32);
|
||||
// move_copies(mypath)circle(r=.2,$fn=32);
|
||||
// Example(2D):
|
||||
// mypath = subdivide_path(square([2,2],center=true), 17, closed=false);
|
||||
// place_copies(mypath)circle(r=.1,$fn=32);
|
||||
// move_copies(mypath)circle(r=.1,$fn=32);
|
||||
// Example(2D): Specifying different numbers of points on each segment
|
||||
// mypath = subdivide_path(hexagon(side=2), [2,3,4,5,6,7], method="segment");
|
||||
// place_copies(mypath)circle(r=.1,$fn=32);
|
||||
// move_copies(mypath)circle(r=.1,$fn=32);
|
||||
// Example(2D): Requested point total is 14 but 15 points output due to extra end point
|
||||
// mypath = subdivide_path(pentagon(side=2), [3,4,3,4], method="segment", closed=false);
|
||||
// place_copies(mypath)circle(r=.1,$fn=32);
|
||||
// move_copies(mypath)circle(r=.1,$fn=32);
|
||||
// Example(2D): Since 17 is not divisible by 5, a completely uniform distribution is not possible.
|
||||
// mypath = subdivide_path(pentagon(side=2), 17);
|
||||
// place_copies(mypath)circle(r=.1,$fn=32);
|
||||
// move_copies(mypath)circle(r=.1,$fn=32);
|
||||
// Example(2D): With `exact=false` a uniform distribution, but only 15 points
|
||||
// mypath = subdivide_path(pentagon(side=2), 17, exact=false);
|
||||
// place_copies(mypath)circle(r=.1,$fn=32);
|
||||
// move_copies(mypath)circle(r=.1,$fn=32);
|
||||
// Example(2D): With `exact=false` you can also get extra points, here 20 instead of requested 18
|
||||
// mypath = subdivide_path(pentagon(side=2), 18, exact=false);
|
||||
// place_copies(mypath)circle(r=.1,$fn=32);
|
||||
// move_copies(mypath)circle(r=.1,$fn=32);
|
||||
// Example(FlatSpin): Three-dimensional paths also work
|
||||
// mypath = subdivide_path([[0,0,0],[2,0,1],[2,3,2]], 12);
|
||||
// place_copies(mypath)sphere(r=.1,$fn=32);
|
||||
// move_copies(mypath)sphere(r=.1,$fn=32);
|
||||
function subdivide_path(path, N, closed=true, exact=true, method="length") =
|
||||
assert(is_path(path))
|
||||
assert(method=="length" || method=="segment")
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
// Example(2D): Called as Function
|
||||
// path = square([40,30], chamfer=5, anchor=FRONT, spin=30);
|
||||
// stroke(path, closed=true);
|
||||
// place_copies(path) color("blue") circle(d=2,$fn=8);
|
||||
// move_copies(path) color("blue") circle(d=2,$fn=8);
|
||||
module square(size=1, center, rounding=0, chamfer=0, anchor, spin=0) {
|
||||
size = is_num(size)? [size,size] : point2d(size);
|
||||
anchor = get_anchor(anchor, center, FRONT+LEFT, FRONT+LEFT);
|
||||
|
|
|
@ -445,11 +445,11 @@ function _rounding_offsets(edgespec,z_dir=1) =
|
|||
// Example(2D): The curve passes through all the points, but features some unexpected wiggles. These occur because the curvature is too low to change fast enough.
|
||||
// path = [[0,0], [0,3], [.5,2.8], [1,2.2], [1,0]];
|
||||
// polygon(smooth_path(path));
|
||||
// color("red") place_copies(path)circle(r=.1,$fn=16);
|
||||
// color("red") move_copies(path)circle(r=.1,$fn=16);
|
||||
// Example(2D): Using the k parameter is one way to fix this problem. By allowing sharper curvature (k<1) at the two points next to the problematic point we can achieve a smoother result. The other fix is to move your points.
|
||||
// path = [[0,0], [0,3], [.5,2.8], [1,2.2], [1,0]];
|
||||
// polygon(smooth_path(path,k=[1,.5,1,.5,1]));
|
||||
// color("red") place_copies(path)circle(r=.1,$fn=16);
|
||||
// color("red") move_copies(path)circle(r=.1,$fn=16);
|
||||
function smooth_path(path, tangents, k, splinesteps=10, closed=false) =
|
||||
let (
|
||||
bez = path_to_bezier(path, tangents, k=k, closed=closed)
|
||||
|
|
|
@ -665,7 +665,6 @@ module cyl(
|
|||
rotate_extrude(convexity=2) {
|
||||
polygon(path);
|
||||
}
|
||||
//!place_copies(path) sphere(d=1);
|
||||
}
|
||||
}
|
||||
children();
|
||||
|
|
|
@ -9,17 +9,17 @@ if (true) {
|
|||
// Display of all solids with insphere, midsphere and circumsphere
|
||||
|
||||
for(i=[0:len(_polyhedra_)-1]) {
|
||||
place_copies([[3*i,0,0]]) // Plain polyhedron
|
||||
move_copies([[3*i,0,0]]) // Plain polyhedron
|
||||
regular_polyhedron(index=i, mr=1,facedown=true);
|
||||
place_copies([[3*i,3.5,0]]){ // Inner radius means sphere touches faces of the polyhedron
|
||||
move_copies([[3*i,3.5,0]]){ // Inner radius means sphere touches faces of the polyhedron
|
||||
sphere(r=1.005); // Sphere is slightly oversized so you can see it poking out from each face
|
||||
%regular_polyhedron(index=i, ir=1,facedown=true);
|
||||
}
|
||||
place_copies([[3*i,7,0]]){ // Mid radius means the sphere touches the center of each edge
|
||||
move_copies([[3*i,7,0]]){ // Mid radius means the sphere touches the center of each edge
|
||||
sphere(r=1);
|
||||
%regular_polyhedron(index=i, mr=1,facedown=true);
|
||||
}
|
||||
place_copies([[3*i,11,0]]){ // outer radius means points of the polyhedron are on the sphere
|
||||
move_copies([[3*i,11,0]]){ // outer radius means points of the polyhedron are on the sphere
|
||||
%sphere(r=.99); // Slightly undersized sphere means the points poke out a bit
|
||||
regular_polyhedron(index=i, or=1,facedown=true);
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@
|
|||
// mat3d = move([2,3,4]); // Returns: [[1,0,0,2],[0,1,0,3],[0,0,1,4],[0,0,0,1]]
|
||||
module move(v=[0,0,0], x=0, y=0, z=0)
|
||||
{
|
||||
translate(v+[x,y,z]) children();
|
||||
translate(point3d(v)+[x,y,z]) children();
|
||||
}
|
||||
|
||||
function move(v=[0,0,0], p=undef, x=0, y=0, z=0) =
|
||||
|
@ -909,7 +909,7 @@ function zflip(z=0,p) =
|
|||
// Example(2D): Calling as a 2D Function
|
||||
// pts = skew(p=square(40,center=true), sxy=0.5);
|
||||
// color("yellow") stroke(pts, closed=true);
|
||||
// color("blue") place_copies(pts) circle(d=3, $fn=8);
|
||||
// color("blue") move_copies(pts) circle(d=3, $fn=8);
|
||||
// Example(FlatSpin): Calling as a 3D Function
|
||||
// pts = skew(p=path3d(square(40,center=true)), szx=0.5, szy=0.3);
|
||||
// trace_polyline(close_path(pts), showpts=true);
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
BOSL_VERSION = [2,0,222];
|
||||
BOSL_VERSION = [2,0,223];
|
||||
|
||||
|
||||
// Section: BOSL Library Version Functions
|
||||
|
|
2
vnf.scad
2
vnf.scad
|
@ -656,7 +656,7 @@ module vnf_validate(vnf, size=1, show_warns=true, check_isects=false) {
|
|||
stroke(pts, width=size, closed=true);
|
||||
polyhedron(pts,[[for (i=idx(pts)) i]]);
|
||||
} else {
|
||||
place_copies(pts) sphere(d=size*3, $fn=18);
|
||||
move_copies(pts) sphere(d=size*3, $fn=18);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue