Skip to content

Instantly share code, notes, and snippets.

@thehans
thehans / L_system.scad
Last active April 12, 2024 04:49
L-system implementation in OpenSCAD
/* L-system OpenSCAD library by Hans Loeblich
Version 2.0
- Now supports "M" move without draw
- Also support position save "[" and restore "]"
- Core functions have been completely rewritten and are about twice as fast using half the memory from before.
- Rules now take the form of a single string per rule: "X=ABC"
- Added new examples to demonstrate added features
This library is for creating L-systems, aka Lindenmayer System,
@thehans
thehans / phillips.scad
Created February 26, 2021 18:41
OpenSCAD model for Phillips screwdriver
$fs=0.2;
$fa=0.2;
headNum = 2;
phillipsDrive(headNum);
//phillipsDemo(headNum);
module phillipsDemo(num) {
difference() {
@thehans
thehans / gist:c30c259e83da4e89ccbd975a511dab68
Last active June 3, 2023 12:19
OpenSCAD shear example
// shear such that point will translate by [p.x,p.y] as z-axis is traversed by p.z units
module shearAlongZ(p) {
multmatrix([
[1,0,p.x/p.z,0],
[0,1,p.y/p.z,0],
[0,0,1,0]
]) children();
}
rotate([0,0,0])
@thehans
thehans / ProjectEnclosure.py
Created November 13, 2011 05:23
FreeCAD script for generating parametric project enclosures
from __future__ import division # allows floating point division from integers
from FreeCAD import Base
import Part
import math
# Run this macro to create a generic project enclosure box
# You can change all the parameters by selecting the object in the tree view and tweaking values in the "Data" tab
# Possible additions/improvements
# counterbore bridging .4mm
@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;
@thehans
thehans / rotate_about.scad
Created November 24, 2019 10:19
OpenSCAD example for rotating about arbitrary pivot point
module rotate_about(a, v, p=[0,0,0]) {
translate(p) rotate(a,v) translate(-p) children();
}
// example usage
rotate_about([0,45,0],p=[5,0,10])
cylinder(r=5,h=10);
@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);
#!/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 / fillet_extrude.scad
Created November 24, 2019 09:51
OpenSCAD example of particular way to fillet when extruding a 2D profile
$fs=0.5;
$fa=1;
// example usage
fillet_extrude(height=10,r1=3,r2=-3) {
hull() {
translate([-10,0]) circle(5);
translate([10,0]) circle(5);
}
rotate(90) hull() {
@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