mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-08-29 22:40:15 +02:00
make functions in edges.scad internal
move some stuff from paths to mutators to get like stuff all together
This commit is contained in:
186
paths.scad
186
paths.scad
@@ -1215,190 +1215,4 @@ function resample_path(path, N, spacing, closed=false) =
|
||||
];
|
||||
|
||||
|
||||
|
||||
// Section: 3D Modules
|
||||
|
||||
|
||||
// Module: extrude_from_to()
|
||||
// Description:
|
||||
// Extrudes a 2D shape between the 3d points pt1 and pt2. Takes as children a set of 2D shapes to extrude.
|
||||
// Arguments:
|
||||
// pt1 = starting point of extrusion.
|
||||
// pt2 = ending point of extrusion.
|
||||
// convexity = max number of times a line could intersect a wall of the 2D shape being extruded.
|
||||
// twist = number of degrees to twist the 2D shape over the entire extrusion length.
|
||||
// scale = scale multiplier for end of extrusion compared the start.
|
||||
// slices = Number of slices along the extrusion to break the extrusion into. Useful for refining `twist` extrusions.
|
||||
// Example(FlatSpin,VPD=200,VPT=[0,0,15]):
|
||||
// extrude_from_to([0,0,0], [10,20,30], convexity=4, twist=360, scale=3.0, slices=40) {
|
||||
// xcopies(3) circle(3, $fn=32);
|
||||
// }
|
||||
module extrude_from_to(pt1, pt2, convexity, twist, scale, slices) {
|
||||
assert(is_vector(pt1));
|
||||
assert(is_vector(pt2));
|
||||
pt1 = point3d(pt1);
|
||||
pt2 = point3d(pt2);
|
||||
rtp = xyz_to_spherical(pt2-pt1);
|
||||
translate(pt1) {
|
||||
rotate([0, rtp[2], rtp[1]]) {
|
||||
if (rtp[0] > 0) {
|
||||
linear_extrude(height=rtp[0], convexity=convexity, center=false, slices=slices, twist=twist, scale=scale) {
|
||||
children();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Module: spiral_sweep()
|
||||
// Description:
|
||||
// Takes a closed 2D polygon path, centered on the XY plane, and sweeps/extrudes it along a 3D spiral path
|
||||
// of a given radius, height and twist. The origin in the profile traces out the helix of the specified radius.
|
||||
// If twist is positive the path will be right-handed; if twist is negative the path will be left-handed.
|
||||
// .
|
||||
// Higbee specifies tapering applied to the ends of the extrusion and is given as the linear distance
|
||||
// over which to taper.
|
||||
// Arguments:
|
||||
// poly = Array of points of a polygon path, to be extruded.
|
||||
// h = height of the spiral to extrude along.
|
||||
// r = Radius of the spiral to extrude along. Default: 50
|
||||
// twist = number of degrees of rotation to spiral up along height.
|
||||
// ---
|
||||
// d = Diameter of the spiral to extrude along.
|
||||
// higbee = Length to taper thread ends over.
|
||||
// higbee1 = Taper length at start
|
||||
// higbee2 = Taper length at end
|
||||
// internal = direction to taper the threads with higbee. If true threads taper outward; if false they taper inward. Default: false
|
||||
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER`
|
||||
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0`
|
||||
// orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#orient). Default: `UP`
|
||||
// center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=BOTTOM`.
|
||||
// Example:
|
||||
// poly = [[-10,0], [-3,-5], [3,-5], [10,0], [0,-30]];
|
||||
// spiral_sweep(poly, h=200, r=50, twist=1080, $fn=36);
|
||||
module spiral_sweep(poly, h, r, twist=360, higbee, center, r1, r2, d, d1, d2, higbee1, higbee2, internal=false, anchor, spin=0, orient=UP) {
|
||||
higsample = 10; // Oversample factor for higbee tapering
|
||||
dummy1=assert(is_num(twist) && twist != 0);
|
||||
bounds = pointlist_bounds(poly);
|
||||
yctr = (bounds[0].y+bounds[1].y)/2;
|
||||
xmin = bounds[0].x;
|
||||
xmax = bounds[1].x;
|
||||
poly = path3d(clockwise_polygon(poly));
|
||||
anchor = get_anchor(anchor,center,BOT,BOT);
|
||||
r1 = get_radius(r1=r1, r=r, d1=d1, d=d, dflt=50);
|
||||
r2 = get_radius(r1=r2, r=r, d1=d2, d=d, dflt=50);
|
||||
sides = segs(max(r1,r2));
|
||||
dir = sign(twist);
|
||||
ang_step = 360/sides*dir;
|
||||
anglist = [for(ang = [0:ang_step:twist-EPSILON]) ang,
|
||||
twist];
|
||||
higbee1 = first_defined([higbee1, higbee, 0]);
|
||||
higbee2 = first_defined([higbee2, higbee, 0]);
|
||||
higang1 = 360 * higbee1 / (2 * r1 * PI);
|
||||
higang2 = 360 * higbee2 / (2 * r2 * PI);
|
||||
dummy2=assert(higbee1>=0 && higbee2>=0)
|
||||
assert(higang1 < dir*twist/2,"Higbee1 is more than half the threads")
|
||||
assert(higang2 < dir*twist/2,"Higbee2 is more than half the threads");
|
||||
function polygon_r(N,theta) =
|
||||
let( alpha = 360/N )
|
||||
cos(alpha/2)/(cos(posmod(theta,alpha)-alpha/2));
|
||||
higofs = pow(0.05,2); // Smallest hig scale is the square root of this value
|
||||
function taperfunc(x) = sqrt((1-higofs)*x+higofs);
|
||||
interp_ang = [
|
||||
for(i=idx(anglist,e=-2))
|
||||
each lerpn(anglist[i],anglist[i+1],
|
||||
(higang1>0 && higang1>dir*anglist[i+1]
|
||||
|| (higang2>0 && higang2>dir*(twist-anglist[i]))) ? ceil((anglist[i+1]-anglist[i])/ang_step*higsample)
|
||||
: 1,
|
||||
endpoint=false),
|
||||
last(anglist)
|
||||
];
|
||||
skewmat = affine3d_skew_xz(xa=atan2(r2-r1,h));
|
||||
points = [
|
||||
for (a = interp_ang) let (
|
||||
hsc = dir*a<higang1 ? taperfunc(dir*a/higang1)
|
||||
: dir*(twist-a)<higang2 ? taperfunc(dir*(twist-a)/higang2)
|
||||
: 1,
|
||||
u = a/twist,
|
||||
r = lerp(r1,r2,u),
|
||||
mat = affine3d_zrot(a)
|
||||
* affine3d_translate([polygon_r(sides,a)*r, 0, h * (u-0.5)])
|
||||
* affine3d_xrot(90)
|
||||
* skewmat
|
||||
* scale([hsc,lerp(hsc,1,0.25),1], cp=[internal ? xmax : xmin, yctr, 0]),
|
||||
pts = apply(mat, poly)
|
||||
) pts
|
||||
];
|
||||
|
||||
vnf = vnf_vertex_array(
|
||||
points, col_wrap=true, caps=true, reverse=dir>0?true:false,
|
||||
style=higbee1>0 || higbee2>0 ? "quincunx" : "alt"
|
||||
);
|
||||
|
||||
attachable(anchor,spin,orient, r1=r1, r2=r2, l=h) {
|
||||
vnf_polyhedron(vnf, convexity=ceil(2*dir*twist/360));
|
||||
children();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Module: path_extrude()
|
||||
// Description:
|
||||
// Extrudes 2D children along a 3D path. This may be slow.
|
||||
// Arguments:
|
||||
// path = array of points for the bezier path to extrude along.
|
||||
// convexity = maximum number of walls a ran can pass through.
|
||||
// clipsize = increase if artifacts are left. Default: 1000
|
||||
// Example(FlatSpin,VPD=600,VPT=[75,16,20]):
|
||||
// path = [ [0, 0, 0], [33, 33, 33], [66, 33, 40], [100, 0, 0], [150,0,0] ];
|
||||
// path_extrude(path) circle(r=10, $fn=6);
|
||||
module path_extrude(path, convexity=10, clipsize=100) {
|
||||
function polyquats(path, q=q_ident(), v=[0,0,1], i=0) = let(
|
||||
v2 = path[i+1] - path[i],
|
||||
ang = vector_angle(v,v2),
|
||||
axis = ang>0.001? unit(cross(v,v2)) : [0,0,1],
|
||||
newq = q_mul(quat(axis, ang), q),
|
||||
dist = norm(v2)
|
||||
) i < (len(path)-2)?
|
||||
concat([[dist, newq, ang]], polyquats(path, newq, v2, i+1)) :
|
||||
[[dist, newq, ang]];
|
||||
|
||||
epsilon = 0.0001; // Make segments ever so slightly too long so they overlap.
|
||||
ptcount = len(path);
|
||||
pquats = polyquats(path);
|
||||
for (i = [0:1:ptcount-2]) {
|
||||
pt1 = path[i];
|
||||
pt2 = path[i+1];
|
||||
dist = pquats[i][0];
|
||||
q = pquats[i][1];
|
||||
difference() {
|
||||
translate(pt1) {
|
||||
q_rot(q) {
|
||||
down(clipsize/2/2) {
|
||||
if ((dist+clipsize/2) > 0) {
|
||||
linear_extrude(height=dist+clipsize/2, convexity=convexity) {
|
||||
children();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
translate(pt1) {
|
||||
hq = (i > 0)? q_slerp(q, pquats[i-1][1], 0.5) : q;
|
||||
q_rot(hq) down(clipsize/2+epsilon) cube(clipsize, center=true);
|
||||
}
|
||||
translate(pt2) {
|
||||
hq = (i < ptcount-2)? q_slerp(q, pquats[i+1][1], 0.5) : q;
|
||||
q_rot(hq) up(clipsize/2+epsilon) cube(clipsize, center=true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
|
||||
|
Reference in New Issue
Block a user