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
$fs=0.2; | |
$fa=0.2; | |
headNum = 2; | |
phillipsDrive(headNum); | |
//phillipsDemo(headNum); | |
module phillipsDemo(num) { | |
difference() { |
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) : |
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
n = 8; | |
height = 40; | |
width = 50; // distance across flats of polygon (when n is even) | |
rxy = 8; | |
rz = 3; | |
width2 = 30; | |
rxy2 = rxy*width2/width; | |
rz2 = 0.1; // small but nonzero |
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
$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); |
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
// 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]; |
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
# 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)) |
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
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); |
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
$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() { |
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
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(); | |
} | |
} |