Skip to content

Instantly share code, notes, and snippets.

@thehans
thehans / arc_slot.scad
Created May 2, 2022
arc_slot OpenSCAD example
View arc_slot.scad
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)
));
@thehans
thehans / tricubic_interp_noise.scad
Created Sep 12, 2021
Tricubic interpolation of 3D noise for OpenSCAD
View tricubic_interp_noise.scad
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;
@thehans
thehans / bicubic_interp_noise.scad
Created Sep 11, 2021
Bicubic interpolation of value noise for OpenSCAD
View bicubic_interp_noise.scad
// 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;
@thehans
thehans / offset_extrude.scad
Created Sep 4, 2021
Offset Extrude and Fillet Extrude for OpenSCAD
View offset_extrude.scad
$fs=0.5;
$fa=1;
// General offset_extrude and fillet_extrude.
// These use minkowski which can be incredibly slow and resource intensive, but should theoretically work on any 2d geometry.
// fillet_extrude is also much slower than offset_extrude, due to significantly more facets needed for rounded edges.
// There are some alternative methods which are much faster,
// ***BUT*** they have the limitation of only working for CONVEX children.
// chamfer_extrude (basically like offset_extrude): https://gist.github.com/thehans/072005c68e5fcef3394b8c08e37d1c35
@thehans
thehans / gist:af1dc6bca07fbfddc27ddca99194ce95
Last active Aug 30, 2021
Cylinder extrude example for OpenSCAD
View gist:af1dc6bca07fbfddc27ddca99194ce95
$fs = 2;
$fa = 2;
r_cyl = 10;
h_cyl = 100;
// Take a 2d shape and extrude outward (or inward with r_delta < 0)
// from a theoretical cylinder of given radius and height (centered).
// Input geometry should fit within the bounds of [-PI*r_cyl, -h/2] and [PI*r_cyl, h/2]
module cylinder_extrude(r_cyl, r_delta, h, eps=0.01) {
frags = fragments(r_cyl);
View endstop_mount_final.scad
//use <../Libraries/drawPath.scad>
// Width of base
wBase = 20;
// Length of base
lBase = 25;
// Thickness of base
thBase = 5;
// Fillet radius
rFillet = 1;
@thehans
thehans / gist:ca0ec0516c0b1b4af8ce2f580ef5ffc7
Created Jun 4, 2021
Different ways of mirroring in OpenSCAD
View gist:ca0ec0516c0b1b4af8ce2f580ef5ffc7
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");
}
}
@thehans
thehans / nurbs.scad
Created Jun 2, 2021
OpenSCAD NURBS quad surface test
View nurbs.scad
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;
@thehans
thehans / phillips.scad
Created Feb 26, 2021
OpenSCAD model for Phillips screwdriver
View phillips.scad
$fs=0.2;
$fa=0.2;
headNum = 2;
phillipsDrive(headNum);
//phillipsDemo(headNum);
module phillipsDemo(num) {
difference() {
@thehans
thehans / radix_sort.scad
Last active Jan 6, 2021
OpenSCAD radix sort implementation
View radix_sort.scad
// 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) :