Skip to content

Instantly share code, notes, and snippets.

@thehans
thehans / smooth_grip.scad
Created February 6, 2023 00:23
A pistol-style grip for a pvc pipe
// Created in 2018 by Ryan A. Colyer.
// This work is released with CC0 into the public domain.
// https://creativecommons.org/publicdomain/zero/1.0/
include <plot_function.scad> // https://www.thingiverse.com/thing:2391851
finger_spacing = 21;
oblong_factor = 1.8;
ripple_sharpness = 0.6; // range [0:1]
grip_width = 20;
#!/bin/bash
# This script is meant to help with updating old PRs.
# Mainly any OpenSCAD branch which has not been updated since 2022-02-06
# It is intended to be run on a git repo in which a merge has already been started (merging master into the current, old branch),
# and has conflicts which show as "deleted by them:", or "(modified/deleted)".
#
# Due to how git DOES NOT track file moves/renames, in addition to how it determines file "similarity" (by # of exactly matched lines in a file),
# it makes it very difficult to merge master into branches created before 2 significant events in the OpenSCAD repo:
# 1) A large code style reformatting (PR #4095 on 2022-02-06), and
@thehans
thehans / arc_slot.scad
Created May 2, 2022 19:39
arc_slot OpenSCAD example
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 September 12, 2021 03:21
Tricubic interpolation of 3D noise for OpenSCAD
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 September 11, 2021 00:02
Bicubic interpolation of value noise for OpenSCAD
// 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 September 4, 2021 09:16
Offset Extrude and Fillet Extrude for OpenSCAD
$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 August 23, 2022 14:28
Cylinder extrude example for OpenSCAD
$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);
@thehans
thehans / endstop_mount_final.scad
Last active August 28, 2021 18:41
Endstop mount
//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 June 4, 2021 23:22
Different ways of mirroring in OpenSCAD
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 June 2, 2021 19:40
OpenSCAD NURBS quad surface test
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;