Skip to content

Instantly share code, notes, and snippets.

Avatar

Hans Loeblich thehans

View GitHub Profile
@thehans
thehans / chamfer_extrude.scad
Created Jul 18, 2020
OpenSCAD example of one way to chamfer when extruding a 2D profile
View chamfer_extrude.scad
$fs=0.5;
$fa=1;
// example usage
chamfer_extrude(height=10,ch1=-3,ch2=3) {
hull() {
translate([-10,0]) circle(5, $fn=64);
translate([10,0]) circle(5, $fn=64);
}
square([10,30],center=true);
@thehans
thehans / complex_transform.scad
Created Jun 22, 2020
OpenSCAD demo of transformation using complex numbers
View complex_transform.scad
// Demo of using complex numbers to map one 2D point to another.
// Performs rotate and/or scale transform in one operation, without any
// transcendental (trigonometric) functions nor irrational numbers*.
// *please ignore the circular input data
// Enable animation for demo!
// multiply complex numbers
function cmul(c1,c2) = let(a=c1[0],b=c1[1],c=c2[0],d=c2[1])
[a*c-b*d, a*d+b*c];
View pipe_demo.scad
// 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)
View 01_blinky.py
# If the design does not create a "sync" clock domain, it is created by the nMigen build system
# using the platform default clock (and default reset, if any).
from nmigen import *
from nmigen_boards.de10_nano import *
class Blinky(Elaboratable):
def elaborate(self, platform):
leds = Array(platform.request("led", i) for i in range(0,8))
@thehans
thehans / rotate_about.scad
Created Nov 24, 2019
OpenSCAD example for rotating about arbitrary pivot point
View rotate_about.scad
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 / fillet_extrude.scad
Created Nov 24, 2019
OpenSCAD example of particular way to fillet when extruding a 2D profile
View fillet_extrude.scad
$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 / rotate_extrude3D.scad
Created Nov 23, 2019
Example of creating a cutout for a 3D object which is pivoting around the origin.
View rotate_extrude3D.scad
module rotate_extrude3D(clearance, bounds=[1000,1000]) {
rotate_extrude()
intersection() { // clip to positive x axis before rotate_extrude
translate([0,-bounds[1]/2]) square(bounds);
offset(delta=clearance) // add clearance to profile
union() for(a=[-90:$fa:90]) // union projections from multiple angles
projection() rotate([-90,a]) children();
}
}
@thehans
thehans / duct.scad
Created Nov 18, 2019
Basic duct transition using hull in OpenSCAD
View duct.scad
fan=120;
ductl=110;
ductw=40;
h=150;
wallTh = 2;
module transition(h,l1,w1,l2,w2,eps=0.01) {
hull() {
cube([l1,w1,eps], center=true);
translate([0,0,h-eps]) cube([w2,l2,eps], center=true);
@thehans
thehans / perf.scad
Created Nov 6, 2019
Performance test of complex object unioned with many simple objects
View perf.scad
$fn = 100;
module rounded_cube(size,r,center=false)
{
s = is_list(size) ? size : [size,size,size];
translate(center ? -s/2 : [0,0,0])
hull() {
translate([ r, r, r]) sphere(r=r);
translate([ r, r,s.z-r]) sphere(r=r);
translate([ r,s.y-r, r]) sphere(r=r);
@thehans
thehans / rotate_extrude2.scad
Created Nov 5, 2019
Backwards compatible rotate_extrude for OpenSCAD with angle parameter
View rotate_extrude2.scad
// older versions of OpenSCAD do not support "angle" parameter for rotate_extrude
// this module provides that capability even when using older versions (such as thingiverse customizer)
module rotate_extrude2(angle = 360, convexity = 2, size = 1000) {
module angle_cut(angle = 90, size = 1000) {
x = size*cos((angle / 2));
y = size*sin((angle / 2));
translate([0, 0, -size]) linear_extrude((2 * size)) polygon([[0, 0], [x, y], [x, size], [-size, size], [-size, -size], [x, -size], [x, -y]]);
}
// support for angle parameter in rotate_extrude was added after release 2015.03
// Thingiverse customizer is still on 2015.03
You can’t perform that action at this time.