diff --git a/affine.scad b/affine.scad index 422ee1f..c7de834 100644 --- a/affine.scad +++ b/affine.scad @@ -83,7 +83,7 @@ function affine2d_zrot(ang) = [ // Arguments: // v = The normal vector of the line to reflect across. function affine2d_mirror(v) = - let(v=normalize(point2d(v)), a=v.x, b=v.y) + let(v=unit(point2d(v)), a=v.x, b=v.y) [ [1-2*a*a, 0-2*a*b, 0], [0-2*a*b, 1-2*b*b, 0], @@ -225,7 +225,7 @@ function affine3d_zrot(ang) = [ // u = 3D axis vector to rotate around. // ang = number of degrees to rotate. function affine3d_rot_by_axis(u, ang) = let( - u = normalize(u), + u = unit(u), c = cos(ang), c2 = 1-c, s = sin(ang) @@ -290,9 +290,9 @@ function affine_frame_map(x,y,z, reverse=false) = assert(yvalid,"Input y must be a length 3 vector") assert(zvalid,"Input z must be a length 3 vector") let( - x = is_def(x) ? normalize(x) : undef, - y = is_def(y) ? normalize(y) : undef, - z = is_def(z) ? normalize(z) : undef, + x = is_def(x) ? unit(x) : undef, + y = is_def(y) ? unit(y) : undef, + z = is_def(z) ? unit(z) : undef, map = is_undef(x) ? [cross(y,z), y, z] : is_undef(y) ? [x, cross(z,x), z] : is_undef(z) ? [x, y, cross(x,y)] : @@ -310,7 +310,7 @@ function affine_frame_map(x,y,z, reverse=false) = // Arguments: // v = The normal vector of the plane to reflect across. function affine3d_mirror(v) = - let(v=normalize(point3d(v)), a=v.x, b=v.y, c=v.z) + let(v=unit(point3d(v)), a=v.x, b=v.y, c=v.z) [ [1-2*a*a, -2*a*b, -2*a*c, 0], [ -2*b*a, 1-2*b*b, -2*b*c, 0], diff --git a/attachments.scad b/attachments.scad index 7404b98..9a46040 100644 --- a/attachments.scad +++ b/attachments.scad @@ -197,32 +197,32 @@ function find_anchor(anchor, geom) = bot = point3d(vmul(point2d(size)/2,axy),-h/2), top = point3d(vmul(point2d(size2)/2,axy)+shift,h/2), pos = lerp(bot,top,u)+offset, - sidevec = normalize(rot(from=UP, to=top-bot, p=point3d(axy))), - vvec = normalize([0,0,anchor.z]), + sidevec = unit(rot(from=UP, to=top-bot, p=point3d(axy))), + vvec = unit([0,0,anchor.z]), vec = anchor==CENTER? UP : - approx(axy,[0,0])? normalize(anchor) : + approx(axy,[0,0])? unit(anchor) : approx(anchor.z,0)? sidevec : - normalize((sidevec+vvec)/2) + unit((sidevec+vvec)/2) ) [anchor, pos, vec, oang] ) : type == "cyl"? ( //r1, r2, l, shift let( r1=geom[1], r2=geom[2], l=geom[3], shift=point2d(geom[4]), u = (anchor.z+1)/2, - axy = normalize(point2d(anchor)), + axy = unit(point2d(anchor)), bot = point3d(r1*axy,-l/2), top = point3d(r2*axy+shift, l/2), pos = lerp(bot,top,u)+offset, sidevec = rot(from=UP, to=top-bot, p=point3d(axy)), - vvec = normalize([0,0,anchor.z]), + vvec = unit([0,0,anchor.z]), vec = anchor==CENTER? UP : - approx(axy,[0,0])? normalize(anchor) : + approx(axy,[0,0])? unit(anchor) : approx(anchor.z,0)? sidevec : - normalize((sidevec+vvec)/2) + unit((sidevec+vvec)/2) ) [anchor, pos, vec, oang] ) : type == "spheroid"? ( //r let( r=geom[1] - ) [anchor, r*normalize(anchor)+offset, normalize(anchor), oang] + ) [anchor, r*unit(anchor)+offset, unit(anchor), oang] ) : type == "vnf_isect"? ( //vnf let( vnf=geom[1], @@ -252,7 +252,7 @@ function find_anchor(anchor, geom) = pos = hits[furthest][2], dist = hits[furthest][0], nfaces = [for (hit = hits) if(approx(hit[0],dist,eps=eps)) hit[1]], - n = normalize( + n = unit( sum([ for (i = nfaces) let( faceverts = select(vnf[0],vnf[1][i]), @@ -281,12 +281,12 @@ function find_anchor(anchor, geom) = frpt = [size.x/2*anchor.x, -size.y/2], bkpt = [size2/2*anchor.x, size.y/2], pos = lerp(frpt, bkpt, u), - vec = normalize(rot(from=BACK, to=bkpt-frpt, p=anchor)) + vec = unit(rot(from=BACK, to=bkpt-frpt, p=anchor)) ) [anchor, pos, vec, 0] ) : type == "circle"? ( //r let( r=geom[1], - anchor = normalize(point2d(anchor)) + anchor = unit(point2d(anchor)) ) [anchor, r*anchor+offset, anchor, 0] ) : type == "path_isect"? ( //path let( @@ -299,7 +299,7 @@ function find_anchor(anchor, geom) = isect = ray_segment_intersection([[0,0],anchor], seg1), n = is_undef(isect)? [0,1] : !approx(isect, t[1])? line_normal(seg1) : - normalize((line_normal(seg1)+line_normal(seg2))/2), + unit((line_normal(seg1)+line_normal(seg2))/2), n2 = vector_angle(anchor,n)>90? -n : n ) if(!is_undef(isect) && !approx(isect,t[0])) [norm(isect), isect, n2] @@ -307,7 +307,7 @@ function find_anchor(anchor, geom) = maxidx = max_index(subindex(isects,0)), isect = isects[maxidx], pos = isect[1], - vec = normalize(isect[2]) + vec = unit(isect[2]) ) [anchor, pos, vec, 0] ) : type == "path_extent"? ( //path let( diff --git a/beziers.scad b/beziers.scad index 27963ee..801afde 100644 --- a/beziers.scad +++ b/beziers.scad @@ -198,9 +198,9 @@ function bezier_segment_length(curve, start_u=0, end_u=1, max_deflect=0.01) = // fbez = fillet3pts(p0,p1,p2, 10); // trace_bezier(slice(fbez, 1, -2), size=1); function fillet3pts(p0, p1, p2, r, maxerr=0.1, w=0.5, dw=0.25) = let( - v0 = normalize(p0-p1), - v1 = normalize(p2-p1), - midv = normalize((v0+v1)/2), + v0 = unit(p0-p1), + v1 = unit(p2-p1), + midv = unit((v0+v1)/2), a = vector_angle(v0,v1), tanr = min(r/tan(a/2), norm(p0-p1)*0.99, norm(p2-p1)*0.99), tp0 = p1+v0*tanr, diff --git a/coords.scad b/coords.scad index 0762858..500949e 100644 --- a/coords.scad +++ b/coords.scad @@ -251,10 +251,10 @@ function project_plane(point, a, b, c) = assert(is_vector(c)) assert(is_vector(point)||is_path(point)) let( - u = normalize(b-a), - v = normalize(c-a), - n = normalize(cross(u,v)), - w = normalize(cross(n,u)), + u = unit(b-a), + v = unit(c-a), + n = unit(cross(u,v)), + w = unit(cross(n,u)), relpoint = is_vector(point)? (point-a) : translate_points(point,-a) ) relpoint * transpose([w,u]); @@ -281,10 +281,10 @@ function lift_plane(point, a, b, c) = assert(is_vector(c)) assert(is_vector(point)||is_path(point)) let( - u = normalize(b-a), - v = normalize(c-a), - n = normalize(cross(u,v)), - w = normalize(cross(n,u)), + u = unit(b-a), + v = unit(c-a), + n = unit(cross(u,v)), + w = unit(cross(n,u)), remapped = point*[w,u] ) is_vector(remapped)? (a+remapped) : translate_points(remapped,a); diff --git a/debug.scad b/debug.scad index 356bb09..6cff32f 100644 --- a/debug.scad +++ b/debug.scad @@ -85,11 +85,11 @@ module debug_faces(vertices, faces, size=1, disabled=false) { v1 = vertices[face[1]]; v2 = vertices[face[2]]; c = (v0 + v1 + v2) / 3; - dv0 = normalize(v1 - v0); - dv1 = normalize(v2 - v0); - nrm0 = normalize(cross(dv0, dv1)); + dv0 = unit(v1 - v0); + dv1 = unit(v2 - v0); + nrm0 = unit(cross(dv0, dv1)); nrm1 = [0, 0, 1]; - axis = normalize(cross(nrm0, nrm1)); + axis = unit(cross(nrm0, nrm1)); ang = vector_angle(nrm0, nrm1); theta = atan2(nrm0[1], nrm0[0]); translate(c) { diff --git a/distributors.scad b/distributors.scad index dc45ed9..f1b038a 100644 --- a/distributors.scad +++ b/distributors.scad @@ -444,7 +444,7 @@ module zdistribute(spacing=10, sizes=undef, l=undef) // grid2d(spacing=10, stagger=true, in_poly=hexregion) { // // Note: You must use for(var=[val]) or let(var=val) // // to set vars from $pos or other special vars in this scope. -// let (ref_v = (normalize([0,0,50]-point3d($pos)) + UP)/2) +// let (ref_v = (unit([0,0,50]-point3d($pos)) + UP)/2) // half_of(v=-ref_v, cp=[0,0,5]) // zrot(180/6) // cylinder(h=20, d=10/cos(180/6)+0.01, $fn=6); @@ -920,7 +920,7 @@ module arc_of( // // Example: // ovoid_spread(n=500, d=100, cone_ang=180) -// color(normalize(point3d(vabs($pos)))) +// color(unit(point3d(vabs($pos)))) // cylinder(d=8, h=10, center=false); module ovoid_spread(r=undef, d=undef, n=100, cone_ang=90, scale=[1,1,1], perp=true) { diff --git a/geometry.scad b/geometry.scad index a1ac969..f8ab499 100644 --- a/geometry.scad +++ b/geometry.scad @@ -94,7 +94,7 @@ function collinear_indexed(points, a, b, c, eps=EPSILON) = // Example: // distance_from_line([[-10,0], [10,0]], [3,8]); // Returns: 8 function distance_from_line(line, pt) = - let(a=line[0], n=normalize(line[1]-a), d=a-pt) + let(a=line[0], n=unit(line[1]-a), d=a-pt) norm(d - ((d * n) * n)); @@ -116,7 +116,7 @@ function distance_from_line(line, pt) = // color("blue") place_copies([p1,p2]) circle(d=2, $fn=12); function line_normal(p1,p2) = is_undef(p2)? line_normal(p1[0],p1[1]) : - normalize([p1.y-p2.y,p2.x-p1.x]); + unit([p1.y-p2.y,p2.x-p1.x]); // 2D Line intersection from two segments. @@ -558,7 +558,7 @@ function plane3pt(p1, p2, p3) = p1=point3d(p1), p2=point3d(p2), p3=point3d(p3), - normal = normalize(cross(p3-p1, p2-p1)) + normal = unit(cross(p3-p1, p2-p1)) ) concat(normal, [normal*p1]); @@ -636,7 +636,7 @@ function distance_from_plane(plane, point) = // point = The 3D point to find the closest point to. function closest_point_on_plane(plane, point) = let( - n = normalize(plane_normal(plane)), + n = unit(plane_normal(plane)), d = distance_from_plane(plane, point) ) point - n*d; @@ -796,13 +796,13 @@ function find_circle_2tangents(pt1, pt2, pt3, r=undef, d=undef) = assert(r!=undef, "Must specify either r or d.") (is_undef(pt2) && is_undef(pt3) && is_list(pt1))? find_circle_2tangents(pt1[0], pt1[1], pt1[2], r=r) : let( - v1 = normalize(pt1 - pt2), - v2 = normalize(pt3 - pt2) + v1 = unit(pt1 - pt2), + v2 = unit(pt3 - pt2) ) approx(norm(v1+v2))? undef : let( a = vector_angle(v1,v2), n = vector_axis(v1,v2), - v = normalize(mean([v1,v2])), + v = unit(mean([v1,v2])), s = r/sin(a/2), cp = pt2 + s*v/norm(v) ) [cp, n]; diff --git a/mutators.scad b/mutators.scad index e53932e..0868994 100644 --- a/mutators.scad +++ b/mutators.scad @@ -33,7 +33,7 @@ // half_of([1,1], planar=true) circle(d=50); module half_of(v=UP, cp=[0,0,0], s=1000, planar=false) { - cp = is_num(cp)? cp*normalize(v) : cp; + cp = is_num(cp)? cp*unit(v) : cp; if (cp != [0,0,0]) { translate(cp) half_of(v=v, s=s, planar=planar) translate(-cp) children(); } else if (planar) { diff --git a/paths.scad b/paths.scad index 2688f03..b4d6889 100644 --- a/paths.scad +++ b/paths.scad @@ -219,7 +219,7 @@ function path_trim_start(path,trim,_d=0,_i=0) = _i >= len(path)-1? [] : let (l = norm(path[_i+1]-path[_i])) _d+l <= trim? path_trim_start(path,trim,_d+l,_i+1) : - let (v = normalize(path[_i+1]-path[_i])) + let (v = unit(path[_i+1]-path[_i])) concat( [path[_i+1]-v*(l-(trim-_d))], [for (i=[_i+1:1:len(path)-1]) path[i]] @@ -246,7 +246,7 @@ function path_trim_end(path,trim,_d=0,_i=undef) = _i <= 0? [] : let (l = norm(path[_i]-path[_i-1])) _d+l <= trim? path_trim_end(path,trim,_d+l,_i-1) : - let (v = normalize(path[_i]-path[_i-1])) + let (v = unit(path[_i]-path[_i-1])) concat( [for (i=[0:1:_i-1]) path[i]], [path[_i-1]+v*(l-(trim-_d))] @@ -284,7 +284,7 @@ function path_closest_point(path, pt) = // The returns vectors will be normalized to length 1. function path_tangents(path, closed=false) = assert(is_path(path)) - [for(t=deriv(path)) normalize(t)]; + [for(t=deriv(path)) unit(t)]; // Function: path_normals() @@ -303,7 +303,7 @@ function path_normals(path, tangents, closed=false) = pts = i==0? (closed? select(path,-1,1) : select(path,0,2)) : i==len(path)-1? (closed? select(path,i-1,i+1) : select(path,i-2,i)) : select(path,i-1,i+1) - ) normalize(cross( + ) unit(cross( cross(pts[1]-pts[0], pts[2]-pts[0]), tangents[i] )) @@ -392,8 +392,8 @@ function points_along_path3d( n=0 // Used in recursion ) = let( end = len(path)-1, - v1 = (n == 0)? [0, 0, 1] : normalize(path[n]-path[n-1]), - v2 = (n == end)? normalize(path[n]-path[n-1]) : normalize(path[n+1]-path[n]), + v1 = (n == 0)? [0, 0, 1] : unit(path[n]-path[n-1]), + v2 = (n == end)? unit(path[n]-path[n-1]) : unit(path[n+1]-path[n]), crs = cross(v1, v2), axis = norm(crs) <= 0.001? [0, 0, 1] : crs, ang = vector_angle(v1, v2), @@ -806,7 +806,7 @@ 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? normalize(cross(v,v2)) : [0,0,1], + 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)? @@ -1143,8 +1143,8 @@ function _path_cuts_normals(path, cuts, dirs, closed=false) = let(start = max(min(cuts[i][1],len(path)-1),2)) _path_plane(path, start, start-2) ) plane==undef? - normalize([-dirs[i].y, dirs[i].x,0]) : - normalize(cross(dirs[i],cross(plane[0],plane[1]))) + unit([-dirs[i].y, dirs[i].x,0]) : + unit(cross(dirs[i],cross(plane[0],plane[1]))) ) ]; @@ -1161,15 +1161,15 @@ function _path_cuts_dir(path, cuts, closed=false, eps=1e-2) = [for(ind=[0:len(cuts)-1]) let( nextind = cuts[ind][1], - nextpath = normalize(select(path, nextind+1)-select(path, nextind)), - thispath = normalize(select(path, nextind) - path[nextind-1]), - lastpath = normalize(path[nextind-1] - select(path, nextind-2)), + nextpath = unit(select(path, nextind+1)-select(path, nextind)), + thispath = unit(select(path, nextind) - path[nextind-1]), + lastpath = unit(path[nextind-1] - select(path, nextind-2)), nextdir = nextind==len(path) && !closed? lastpath : (nextind<=len(path)-2 || closed) && approx(cuts[ind][0], path[nextind],eps)? - normalize(nextpath+thispath) : + unit(nextpath+thispath) : (nextind>1 || closed) && approx(cuts[ind][0],path[nextind-1],eps)? - normalize(thispath+lastpath) : + unit(thispath+lastpath) : thispath ) nextdir ]; diff --git a/polyhedra.scad b/polyhedra.scad index c8d9ca2..9e10b50 100644 --- a/polyhedra.scad +++ b/polyhedra.scad @@ -758,7 +758,7 @@ function trapezohedron(faces, r, side, longside, h) = ]; -function _facenormal(pts, face) = normalize(cross(pts[face[2]]-pts[face[0]], pts[face[1]]-pts[face[0]])); +function _facenormal(pts, face) = unit(cross(pts[face[2]]-pts[face[0]], pts[face[1]]-pts[face[0]])); // hull() function returns triangulated faces. This function identifies the vertices that belong to each face // by grouping together the face triangles that share normal vectors. The output gives the face polygon diff --git a/primitives.scad b/primitives.scad index f593c01..e1fb39d 100644 --- a/primitives.scad +++ b/primitives.scad @@ -142,7 +142,7 @@ function circle(r, d, realign=false, circum=false, anchor=CENTER, spin=0) = offset = realign? 180/sides : 0, rr = r / (circum? cos(180/sides) : 1), pts = [for (i=[0:1:sides-1]) let(a=360-offset-i*360/sides) rr*[cos(a),sin(a)]] - ) rot(spin, p=move(-normalize(anchor)*rr, p=pts)); + ) rot(spin, p=move(-unit(anchor)*rr, p=pts)); diff --git a/regions.scad b/regions.scad index c27aeab..09f7c91 100644 --- a/regions.scad +++ b/regions.scad @@ -594,7 +594,7 @@ function _tag_subpaths(path, region, eps=EPSILON) = midpt = lerp(subpath[0], subpath[1], 0.5), rel = point_in_region(midpt,region,eps=eps) ) rel<0? ["O", subpath] : rel>0? ["I", subpath] : let( - vec = normalize(subpath[1]-subpath[0]), + vec = unit(subpath[1]-subpath[0]), perp = rot(90, planar=true, p=vec), sidept = midpt + perp*0.01, rel1 = point_in_polygon(sidept,path,eps=eps)>0, diff --git a/rounding.scad b/rounding.scad index f293cff..2088e92 100644 --- a/rounding.scad +++ b/rounding.scad @@ -319,8 +319,8 @@ function _bezcorner(points, parm) = let( d = parm[0], k = parm[1], - prev = normalize(points[0]-points[1]), - next = normalize(points[2]-points[1]) + prev = unit(points[0]-points[1]), + next = unit(points[2]-points[1]) ) [ points[1]+d*prev, points[1]+k*d*prev, @@ -335,8 +335,8 @@ function _bezcorner(points, parm) = function _chamfcorner(points, parm) = let( d = parm[0], - prev = normalize(points[0]-points[1]), - next = normalize(points[2]-points[1]) + prev = unit(points[0]-points[1]), + next = unit(points[2]-points[1]) ) [points[1]+prev*d, points[1]+next*d]; @@ -345,9 +345,9 @@ function _circlecorner(points, parm) = angle = vector_angle(points)/2, d = parm[0], r = parm[1], - prev = normalize(points[0]-points[1]), - next = normalize(points[2]-points[1]), - center = r/sin(angle) * normalize(prev+next)+points[1], + prev = unit(points[0]-points[1]), + next = unit(points[2]-points[1]), + center = r/sin(angle) * unit(prev+next)+points[1], start = points[1]+prev*d, end = points[1]+next*d ) @@ -1212,8 +1212,8 @@ function _stroke_end(width,left, right, spec) = normal_seg = _normal_segment(right[0], left[0]), normal_pt = normal_seg[1], center = normal_seg[0], - parallel_dir = normalize(left[0]-right[0]), - normal_dir = normalize(normal_seg[1]-normal_seg[0]), + parallel_dir = unit(left[0]-right[0]), + normal_dir = unit(normal_seg[1]-normal_seg[0]), width_dir = sign(width[0]-width[1]) ) type == "round"? [arc(points=[right[0],normal_pt,left[0]],N=50),1,1] : @@ -1270,7 +1270,7 @@ function _stroke_end(width,left, right, spec) = ) assert(roundover_fits,"Roundover too large to fit") let( - angled_dir = normalize(newleft[0]-newright[0]), + angled_dir = unit(newleft[0]-newright[0]), nPleft = [ leftcorner - jointleft*angled_dir, leftcorner, diff --git a/shapes2d.scad b/shapes2d.scad index 984c674..d4a1993 100644 --- a/shapes2d.scad +++ b/shapes2d.scad @@ -506,12 +506,12 @@ function _turtle_command(command, parm, parm2, state, index) = command=="angle" ? list_set(state, angle, parm) : command=="setdir" ? ( is_vector(parm) ? - list_set(state, step, norm(state[step]) * normalize(parm)) : + list_set(state, step, norm(state[step]) * unit(parm)) : list_set(state, step, norm(state[step]) * [cos(parm),sin(parm)]) ) : - command=="length" ? list_set(state, step, parm*normalize(state[step])) : + command=="length" ? list_set(state, step, parm*unit(state[step])) : command=="scale" ? list_set(state, step, parm*state[step]) : - command=="addlength" ? list_set(state, step, state[step]+normalize(state[step])*parm) : + command=="addlength" ? list_set(state, step, state[step]+unit(state[step])*parm) : command=="arcsteps" ? list_set(state, arcsteps, parm) : command=="arcleft" || command=="arcright" ? assert(is_num(parm),str("\"",command,"\" command requires a numeric radius value at index ",index)) @@ -625,7 +625,7 @@ function regular_ngon(n=6, r, d, or, od, ir, id, side, rounding=0, realign=false (r-rounding*sc)*[cos(a),sin(a)] + rounding*[cos(b),sin(b)] ] - ) rot(spin, p=move(-r*normalize(anchor), p=path)); + ) rot(spin, p=move(-r*unit(anchor), p=path)); module regular_ngon(n=6, r, d, or, od, ir, id, side, rounding=0, realign=false, anchor=CENTER, spin=0) { @@ -951,7 +951,7 @@ function star(n, r, d, or, od, ir, id, step, realign=false, anchor=CENTER, spin= ir = get_radius(r=ir, d=id, dflt=stepr), offset = 90+(realign? 180/n : 0), path = [for(i=[0:1:2*n-1]) let(theta=180*i/n+offset, radius=(i%2)?ir:r) radius*[cos(theta), sin(theta)]] - ) rot(spin, p=move(-r*normalize(anchor), p=path)); + ) rot(spin, p=move(-r*unit(anchor), p=path)); module star(n, r, d, or, od, ir, id, step, realign=false, anchor=CENTER, spin=0) { @@ -1023,7 +1023,7 @@ function supershape(step=0.5,m1=4,m2=undef,n1=1,n2=undef,n3=undef,a=1,b=undef,r= rads = [for (theta = angs) _superformula(theta=theta,m1=m1,m2=m2,n1=n1,n2=n2,n3=n3,a=a,b=b)], scale = is_def(r) ? r/max(rads) : 1, path = [for (i = [0:steps-1]) let(a=angs[i]) scale*rads[i]*[cos(a), sin(a)]] - ) rot(spin, p=move(-scale*max(rads)*normalize(anchor), p=path)); + ) rot(spin, p=move(-scale*max(rads)*unit(anchor), p=path)); module supershape(step=0.5,m1=4,m2=undef,n1,n2=undef,n3=undef,a=1,b=undef, r=undef, d=undef, anchor=CENTER, spin=0) { path = supershape(step=step,m1=m1,m2=m2,n1=n1,n2=n2,n3=n3,a=a,b=b,r=r,d=d); diff --git a/skin.scad b/skin.scad index 11f7581..62a4a0a 100644 --- a/skin.scad +++ b/skin.scad @@ -1038,7 +1038,7 @@ module sweep(shape, transformations, closed=false, caps, convexity=10) { // r * sin(q * phi) ]; // function knot_normal(phi,R,r,p,q) = // knot(phi,R,r,p,q) -// - R*normalize(knot(phi,R,r,p,q) +// - R*unit(knot(phi,R,r,p,q) // - [0,0, knot(phi,R,r,p,q)[2]]) ; // ushape = 3*[[-10, 0],[-10, 10],[ -7, 10],[ -7, 2],[ 7, 2],[ 7, 7],[ 10, 7],[ 10, 0]]; // points = 50; // points per loop @@ -1082,9 +1082,9 @@ function path_sweep(shape, path, method="incremental", normal, closed=false, twi assert(is_undef(normal) || (is_vector(normal) && len(normal)==3) || (is_path(normal) && len(normal)==len(path) && len(normal[0])==3), "Invalid normal specified") assert(is_undef(tangent) || (is_path(tangent) && len(tangent)==len(path) && len(tangent[0])==3), "Invalid tangent specified") let( - tangents = is_undef(tangent) ? path_tangents(path) : [for(t=tangent) normalize(t)], - normal = is_path(normal) ? [for(n=normal) normalize(n)] : - is_def(normal) ? normalize(normal) : + tangents = is_undef(tangent) ? path_tangents(path) : [for(t=tangent) unit(t)], + normal = is_path(normal) ? [for(n=normal) unit(n)] : + is_def(normal) ? unit(normal) : method =="incremental" && abs(tangents[0].z) > 1/sqrt(2) ? BACK : UP, normals = is_path(normal) ? normal : replist(normal,len(path)), pathfrac = twist_by_length ? path_length_fractions(path, closed) : [for(i=[0:1:len(path)]) i / (len(path)-(closed?0:1))], diff --git a/tests/hull.scad b/tests/hull.scad index 72ce28b..4143fd0 100644 --- a/tests/hull.scad +++ b/tests/hull.scad @@ -8,15 +8,15 @@ testpoints_on_sphere = [ for(p = [0,1,PHI], [0,-1,PHI], [0,1,-PHI], [0,-1,-PHI], [PHI,0,1], [-PHI,0,1], [PHI,0,-1], [-PHI,0,-1] ]) - normalize(p) + unit(p) ]; testpoints_circular = [ for(a = [0:15:360-EPSILON]) [cos(a),sin(a)] ]; -testpoints_coplanar = let(u = normalize([1,3,7]), v = normalize([-2,1,-2])) [ for(i = [1:10]) rands(-1,1,1)[0] * u + rands(-1,1,1)[0] * v ]; +testpoints_coplanar = let(u = unit([1,3,7]), v = unit([-2,1,-2])) [ for(i = [1:10]) rands(-1,1,1)[0] * u + rands(-1,1,1)[0] * v ]; -testpoints_collinear_2d = let(u = normalize([5,3])) [ for(i = [1:20]) rands(-1,1,1)[0] * u ]; -testpoints_collinear_3d = let(u = normalize([5,3,-5])) [ for(i = [1:20]) rands(-1,1,1)[0] * u ]; +testpoints_collinear_2d = let(u = unit([5,3])) [ for(i = [1:20]) rands(-1,1,1)[0] * u ]; +testpoints_collinear_3d = let(u = unit([5,3,-5])) [ for(i = [1:20]) rands(-1,1,1)[0] * u ]; testpoints2d = 20 * [for (i = [1:10]) concat(rands(-1,1,2))]; testpoints3d = 20 * [for (i = [1:50]) concat(rands(-1,1,3))]; diff --git a/tests/test_geometry.scad b/tests/test_geometry.scad index 2b8f3ce..7c3291d 100644 --- a/tests/test_geometry.scad +++ b/tests/test_geometry.scad @@ -91,7 +91,7 @@ module test_line_normal() { for (p = pair_wrap(pts)) { p1 = p.x; p2 = p.y; - n = normalize(p2-p1); + n = unit(p2-p1); n1 = [-n.y, n.x]; n2 = line_normal(p1,p2); assert(approx(n2, n1)); @@ -239,7 +239,7 @@ module test_find_circle_3points() { for(i = list_range(count)) { cp = select(coords,i,i+2); r = radii[i]; - nrm = normalize(select(coords,i+10,i+12)); + nrm = unit(select(coords,i+10,i+12)); n = nrm.z<0? -nrm : nrm; angs = sort(select(angles,i,i+2)); pts = translate(cp,p=rot(from=UP,to=n,p=[for (a=angs) point3d(polar_to_xy(r,a))])); @@ -266,7 +266,7 @@ module test_find_circle_3points() { for(i = list_range(count)) { cp = select(coords,i,i+2); r = radii[i]; - nrm = normalize(select(coords,i+10,i+12)); + nrm = unit(select(coords,i+10,i+12)); n = nrm.z<0? -nrm : nrm; angs = sort(select(angles,i,i+2)); pts = translate(cp,p=rot(from=UP,to=n,p=[for (a=angs) point3d(polar_to_xy(r,a))])); diff --git a/tests/test_vectors.scad b/tests/test_vectors.scad index 49e9b74..b13ead9 100644 --- a/tests/test_vectors.scad +++ b/tests/test_vectors.scad @@ -67,17 +67,17 @@ module test_vang() { test_vang(); -module test_normalize() { - assert(normalize([10,0,0]) == [1,0,0]); - assert(normalize([0,10,0]) == [0,1,0]); - assert(normalize([0,0,10]) == [0,0,1]); - assert(abs(norm(normalize([10,10,10]))-1) < EPSILON); - assert(abs(norm(normalize([-10,-10,-10]))-1) < EPSILON); - assert(abs(norm(normalize([-10,0,0]))-1) < EPSILON); - assert(abs(norm(normalize([0,-10,0]))-1) < EPSILON); - assert(abs(norm(normalize([0,0,-10]))-1) < EPSILON); +module test_unit() { + assert(unit([10,0,0]) == [1,0,0]); + assert(unit([0,10,0]) == [0,1,0]); + assert(unit([0,0,10]) == [0,0,1]); + assert(abs(norm(unit([10,10,10]))-1) < EPSILON); + assert(abs(norm(unit([-10,-10,-10]))-1) < EPSILON); + assert(abs(norm(unit([-10,0,0]))-1) < EPSILON); + assert(abs(norm(unit([0,-10,0]))-1) < EPSILON); + assert(abs(norm(unit([0,0,-10]))-1) < EPSILON); } -test_normalize(); +test_unit(); module test_vector_angle() { diff --git a/triangulation.scad b/triangulation.scad index 5f6aeb1..0fd2128 100644 --- a/triangulation.scad +++ b/triangulation.scad @@ -21,7 +21,7 @@ // face = The face, given as a list of indices into the vertex array `points`. function face_normal(points, face) = let(count=len(face)) - normalize( + unit( sum( [ for(i=[0:1:count-1]) cross( diff --git a/vectors.scad b/vectors.scad index 24d9980..ceeb40d 100644 --- a/vectors.scad +++ b/vectors.scad @@ -95,19 +95,19 @@ function vdiv(v1, v2) = [for (i = [0:1:len(v1)-1]) v1[i]/v2[i]]; function vabs(v) = [for (x=v) abs(x)]; -// Function: normalize() +// Function: unit() // Description: // Returns unit length normalized version of vector v. // If passed a zero-length vector, returns the unchanged vector. // Arguments: // v = The vector to normalize. // Examples: -// normalize([10,0,0]); // Returns: [1,0,0] -// normalize([0,10,0]); // Returns: [0,1,0] -// normalize([0,0,10]); // Returns: [0,0,1] -// normalize([0,-10,0]); // Returns: [0,-1,0] -// normalize([0,0,0]); // Returns: [0,0,0] -function normalize(v) = norm(v)<=EPSILON? v : v/norm(v); +// unit([10,0,0]); // Returns: [1,0,0] +// unit([0,10,0]); // Returns: [0,1,0] +// unit([0,0,10]); // Returns: [0,0,1] +// unit([0,-10,0]); // Returns: [0,-1,0] +// unit([0,0,0]); // Returns: [0,0,0] +function unit(v) = norm(v)<=EPSILON? v : v/norm(v); // Function: vector_angle() @@ -182,7 +182,7 @@ function vector_axis(v1,v2=undef,v3=undef) = v3 = (norm(v1-v2) > eps && norm(v1+v2) > eps)? v2 : (norm(vabs(v2)-UP) > eps)? UP : RIGHT - ) normalize(cross(v1,v3)) : assert(false, "Bad arguments."); + ) unit(cross(v1,v3)) : assert(false, "Bad arguments."); // vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap diff --git a/version.scad b/version.scad index dbec34c..59e9403 100644 --- a/version.scad +++ b/version.scad @@ -8,7 +8,7 @@ ////////////////////////////////////////////////////////////////////// -BOSL_VERSION = [2,0,145]; +BOSL_VERSION = [2,0,146]; // Section: BOSL Library Version Functions