This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use <FunctionalOpenSCAD/functional.scad> | |
// https://github.com/thehans/FunctionalOpenSCAD/blob/master/functional.scad | |
module arc_slot(R,r,a) { | |
polygon(concat( | |
arc(r=R-r, angle=a, offsetAngle=0, c=[0,0], endpoint=false), | |
arc(r=r, angle=-180, offsetAngle=a-180, c=R*[cos(a),sin(a)], endpoint=false), | |
arc(r=R+r, angle=-a, offsetAngle=a, c=[0,0], endpoint=false), | |
arc(r=r, angle=-180, offsetAngle=0, c=[R,0], endpoint=false) | |
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
translate([-30,0,0]) poly3d(sphere(r=9,$fn=80)); | |
translate([-10,0,0]) poly3d(normalized_cube(r=9,div_count=20)); | |
translate([10,0,0]) poly3d(spherified_cube(9,div_count=20)); | |
translate([30,0,0]) poly3d(icosahedron(9,n=4)); | |
module poly3d(p) { | |
polyhedron(points=p[0],faces=p[1]); | |
} | |
function normalize(v) = v / norm(v); // convert vector to unit vector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BezierExample(); | |
//BezierCircleApprox(10); | |
// cubic bezier circle approximation example | |
module BezierCircleApprox(r) { | |
$fn=1000; | |
c = 0.551915024494; | |
points = BezierPath([ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dims = [8,8,3]; | |
min = 0; | |
max = 2; | |
seed = 0; | |
tricubic = create_tricubic_interp(dims, min, max, seed); | |
step = 1/8; | |
frames = 64; | |
z = dims[2] * $t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bicubic interpolation of value noise | |
// by Hans Loeblich | |
// Reference: https://en.wikipedia.org/wiki/Bicubic_interpolation | |
dims = [4,4]; | |
min = 0; | |
max = 2; | |
seed = 0; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//use <../Libraries/drawPath.scad> | |
// Width of base | |
wBase = 20; | |
// Length of base | |
lBase = 25; | |
// Thickness of base | |
thBase = 5; | |
// Fillet radius | |
rFillet = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
independent = false; // Note: Independent mirroring of 2 axes is actually a rotation | |
fix111 = false; // Only relevant if independent=false | |
module thing(i,j,k) { | |
translate([2,2,2]) difference() { | |
cube(2,center=true); | |
linear_extrude(convexity=10) | |
text(text=str("M",i,j,k),size=0.5,valign="center",halign="center"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function vsum(v,i=0) = len(v)-1 > i ? v[i] + vsum(v, i+1) : v[i]; | |
function N(p, i, U, u) = p == 0 ? | |
U[i] <= u && u <= U[i+1] ? 1 : 0 : | |
let(a=u-U[i],b=U[i+p]-U[i],c=U[i+p+1]-u,d=U[i+p+1]-U[i+1]) | |
(b==0?0:a/b*N(p-1,i,U,u)) + (d==0?0:c/d*N(p-1,i+1,U,u)); | |
module nurbs_circle() { | |
step = 0.0001; | |
// degree of curve | |
p = 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Pipe library demonstrating a concept of chained operations | |
$fn = 72; // define exact number of fragments in curves | |
// using $fs instead would cause some mismatched # of edges during tapers | |
echo(str("For best results, all angles should be multiples of ", 360/$fn, " degrees")); | |
in = 25.4; | |
// Example of how to use pipe | |
// Note that all calls are chained (there's only one semicolon, at the end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// LSD Radix sort (stable) | |
// base: should be a power of two, otherwise exit condition (d==m) might not be reached. | |
// key: 3 possible types | |
// - number (vector index into each element) | |
// - function (takes element and returns the key value) | |
// - undef (elements are used directly as the key) | |
// key values need not be integers, but will be treated as integers via floor() | |
// e.g. [1.5, 1, 1.2] is considered sorted since they are all same key after floor | |
function radix_sort(v,base=4,key) = key==undef ? | |
_rs(v,1,pow(base,-floor(log(max(v))/log(base))),base) : |