refactor - introduce config folder, and other misc changes
This commit is contained in:
35
helper/apply.scad
Normal file
35
helper/apply.scad
Normal file
@ -0,0 +1,35 @@
|
||||
// Modules for apply pattern
|
||||
|
||||
module apply_p() {
|
||||
union() {
|
||||
children(0);
|
||||
children(1);
|
||||
}
|
||||
}
|
||||
|
||||
module apply_n() {
|
||||
difference() {
|
||||
children(1);
|
||||
children(0);
|
||||
}
|
||||
}
|
||||
|
||||
module apply_pn() {
|
||||
difference() {
|
||||
union() {
|
||||
children(0);
|
||||
children(2);
|
||||
}
|
||||
children(1);
|
||||
}
|
||||
}
|
||||
|
||||
module apply_np() {
|
||||
difference() {
|
||||
union() {
|
||||
children(1);
|
||||
children(2);
|
||||
}
|
||||
children(0);
|
||||
}
|
||||
}
|
||||
@ -1,47 +1,10 @@
|
||||
// Helper aggregator
|
||||
|
||||
/* Some commonly used variables plus functions
|
||||
*/
|
||||
|
||||
$fn=64;
|
||||
// TODO move these to math
|
||||
eps=0.0001;
|
||||
|
||||
inf10 = 10;
|
||||
inf50 = 50;
|
||||
inf1000 = 1000;
|
||||
inf = inf1000;
|
||||
|
||||
|
||||
module apply_p() {
|
||||
union() {
|
||||
children(0);
|
||||
children(1);
|
||||
}
|
||||
}
|
||||
|
||||
module apply_n() {
|
||||
difference() {
|
||||
children(1);
|
||||
children(0);
|
||||
}
|
||||
}
|
||||
|
||||
module apply_pn() {
|
||||
difference() {
|
||||
union() {
|
||||
children(0);
|
||||
children(2);
|
||||
}
|
||||
children(1);
|
||||
}
|
||||
}
|
||||
|
||||
module apply_np() {
|
||||
difference() {
|
||||
union() {
|
||||
children(1);
|
||||
children(2);
|
||||
}
|
||||
children(0);
|
||||
}
|
||||
}
|
||||
include <./apply.scad>
|
||||
include <./dovetail.scad>
|
||||
include <./filet.scad>
|
||||
include <./keystone.scad>
|
||||
include <./math.scad>
|
||||
include <./matrix.scad>
|
||||
include <./screws.scad>
|
||||
include <./sine.scad>
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
|
||||
module cylindricalFiletEdge(width, depth, height, roundness) {
|
||||
rd = roundness;
|
||||
|
||||
intersection() {
|
||||
minkowski() {
|
||||
rotate(a = [90, 0, 0])
|
||||
cylinder(r = rd, h = eps);
|
||||
|
||||
translate(v = [rd, 0, rd])
|
||||
cube(size = [width, depth, height]);
|
||||
}
|
||||
|
||||
cube(size = [width, depth, height]);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
include <./common.scad>
|
||||
include <./math.scad>
|
||||
|
||||
// centered on z axis
|
||||
module dovetail(
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
/*
|
||||
Dowel pin config used in side wall hinge module and side wall
|
||||
*/
|
||||
|
||||
dowelPinR = 1.5;
|
||||
dowelPinH = 10;
|
||||
@ -1,12 +1,40 @@
|
||||
include <./halfspace.scad>
|
||||
include <./math.scad>
|
||||
|
||||
// Some modules for simple subtractive filets
|
||||
module sphericalFiletEdge(width, depth, height, roundness) {
|
||||
rd = roundness;
|
||||
|
||||
intersection() {
|
||||
minkowski() {
|
||||
sphere(r = rd);
|
||||
|
||||
translate(v = [rd, rd, rd])
|
||||
cube(size = [width*2, depth - 2*rd, height*2]);
|
||||
}
|
||||
|
||||
cube(size = [width, depth, height]);
|
||||
}
|
||||
}
|
||||
|
||||
module cylindricalFiletEdge(width, depth, height, roundness) {
|
||||
rd = roundness;
|
||||
|
||||
intersection() {
|
||||
minkowski() {
|
||||
rotate(a = [90, 0, 0])
|
||||
cylinder(r = rd, h = eps);
|
||||
|
||||
translate(v = [rd, 0, rd])
|
||||
cube(size = [width, depth, height]);
|
||||
}
|
||||
|
||||
cube(size = [width, depth, height]);
|
||||
}
|
||||
}
|
||||
|
||||
module cylindricalFiletNegative(p0, p1, n, r) {
|
||||
l = norm(p1-p0);
|
||||
|
||||
align_to(p0=p0, p1=p1, p2=p0-n)
|
||||
alignTo(p0=p0, p1=p1, p2=p0-n)
|
||||
rotate(a=[45,0,0])
|
||||
rotate(a=[0,90,0])
|
||||
zFiletNegative(length = l, r = r);
|
||||
|
||||
@ -1,26 +0,0 @@
|
||||
include <./common.scad>
|
||||
|
||||
module halfspace(vpos, p) {
|
||||
|
||||
ref = [0,0,-1];
|
||||
|
||||
if (cross(ref, vpos) == [0,0,0]) {
|
||||
translate(p)
|
||||
translate(v=[0,0, (ref*vpos) * -inf/2])
|
||||
cube(size=[inf, inf, inf], center=true);
|
||||
} else {
|
||||
translate(p)
|
||||
alignPlanar(a=ref, b = vpos)
|
||||
translate(v = [0, 0, -inf/2])
|
||||
cube(size = [inf, inf, inf], center = true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module alignPlanar(a,b) {
|
||||
rot_axis = cross(a,b);
|
||||
angle = acos(a*b/(norm(a)*norm(b)));
|
||||
|
||||
rotate(v=rot_axis, a=angle)
|
||||
children(0);
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
include <./slack.scad>
|
||||
|
||||
// Dimensions for small cylindrical neodymium magnets that I bought off Amazon
|
||||
magnetR = 3;
|
||||
magnetH = 1.7;
|
||||
|
||||
magnetRSlack = 0.1;
|
||||
magnetHSlack = 0.05;
|
||||
|
||||
magnetRSlacked = magnetR + magnetRSlack;
|
||||
magnetHSlacked = magnetH + magnetHSlack;
|
||||
@ -1,11 +1,20 @@
|
||||
// TODO remove/rename this file
|
||||
/* Example usage:
|
||||
for (i=mirror4XY(midpoint=[0,0,0], offsetX=90, offsetY=90)) {
|
||||
translate(v=i)
|
||||
something();
|
||||
}
|
||||
*/
|
||||
// Some misc math-y utils
|
||||
|
||||
$fn=64;
|
||||
eps=0.0001;
|
||||
inf10 = 10;
|
||||
inf50 = 50;
|
||||
inf1000 = 1000;
|
||||
inf = inf1000;
|
||||
|
||||
function unit(v) = v/norm(v);
|
||||
|
||||
function lerp(a, b, t) = (b * t + a * (1 - t));
|
||||
|
||||
/* Example usage:
|
||||
for (i=mirror4XY(midpoint=[0,0,0], offsetX=90, offsetY=90))
|
||||
{ translate(v=i) something(); }
|
||||
*/
|
||||
module mirror4XY(p, dx, dy) {
|
||||
|
||||
px = p[0];
|
||||
@ -24,20 +33,18 @@ module mirror4XY(p, dx, dy) {
|
||||
children(0);
|
||||
}
|
||||
|
||||
// Generate a 4x4 matrix that causes a change of basis
|
||||
// such that the origin is at point p0, the x axis is aligned
|
||||
// from p0 to p1 and point p2 is in the first quadrant.
|
||||
// Copied and pasted from https://trmm.net/Basis/
|
||||
module align_to(p0,p1,p2) {
|
||||
/* Generate a 4x4 matrix that causes a change of basis
|
||||
such that the origin is at point p0, the x axis is aligned
|
||||
from p0 to p1 and point p2 is in the first quadrant.
|
||||
Copied and pasted from https://trmm.net/Basis/
|
||||
*/
|
||||
module alignTo(p0,p1,p2) {
|
||||
|
||||
x = unit(p1-p0);
|
||||
yp = unit(p2-p0);
|
||||
z = unit(cross(x,yp));
|
||||
y = unit(cross(z,x));
|
||||
|
||||
echo(p0,p1,p2);
|
||||
echo(x,y,z);
|
||||
|
||||
multmatrix([
|
||||
[x[0], y[0], z[0], p0[0]],
|
||||
[x[1], y[1], z[1], p0[1]],
|
||||
@ -47,5 +54,27 @@ module align_to(p0,p1,p2) {
|
||||
children();
|
||||
}
|
||||
|
||||
function unit(v) = v/norm(v);
|
||||
function lerp(a, b, t) = (b * t + a * (1 - t));
|
||||
module halfspace(vpos, p) {
|
||||
|
||||
ref = [0,0,-1];
|
||||
|
||||
if (cross(ref, vpos) == [0,0,0]) {
|
||||
translate(p)
|
||||
translate(v=[0,0, (ref*vpos) * -inf/2])
|
||||
cube(size=[inf, inf, inf], center=true);
|
||||
} else {
|
||||
translate(p)
|
||||
alignPlanar(a=ref, b = vpos)
|
||||
translate(v = [0, 0, -inf/2])
|
||||
cube(size = [inf, inf, inf], center = true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module alignPlanar(a,b) {
|
||||
rot_axis = cross(a,b);
|
||||
angle = acos(a*b/(norm(a)*norm(b)));
|
||||
|
||||
rotate(v=rot_axis, a=angle)
|
||||
children(0);
|
||||
}
|
||||
@ -1,7 +1,6 @@
|
||||
/* Some common screw dimensions and helper functions/modules */
|
||||
|
||||
include <./math.scad>
|
||||
include <./common.scad>
|
||||
|
||||
/********************************************************************************/
|
||||
// M3 dimensions
|
||||
|
||||
@ -57,6 +57,3 @@ module sineWaveHull(length, resolution, amplitudeFunction, period, shift, hullDi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//sineWaveHull(length, resolution, amplitudeFunction, period, shift, 10);
|
||||
@ -1,28 +0,0 @@
|
||||
/*
|
||||
Slack config to standardize different usages of slack/tolerance values.
|
||||
|
||||
The purpose of this config is to introduce some consistency with how slack values defined in code. E.g. Why is the
|
||||
slack value defined as 0.3 in this file, but 0.4 in another? This will also allow model-level adjustments for tighter
|
||||
fitting parts, for when it might not convenient to adjust the actual 3d printer (using a 3d printer at a makerspace,
|
||||
for example).
|
||||
|
||||
Some important details:
|
||||
- The general philosophy for slack applications in this project is to subtract space from sockets, while not
|
||||
modifying the plugs. TODO: enforce this
|
||||
- Values are signed. Positive values can be interpreted as how much to remove from the socket along some dimension.
|
||||
- This shouldn't be used to compensate for more serious part shrinkage (> +-0.5mm differences)
|
||||
*/
|
||||
|
||||
xySlack = 0.3;
|
||||
|
||||
radiusXYSlack = xySlack/2;
|
||||
|
||||
zSlack = 0.2; // TODO figure out nice default value for this. keep in mind z shrinkage
|
||||
|
||||
overhangSlack = 0.4;
|
||||
|
||||
supportedOverhangSlack = 0.4;
|
||||
|
||||
|
||||
// special slack cases, change if neccessary
|
||||
xBarYBarDovetailSlack = xySlack;
|
||||
@ -1,15 +0,0 @@
|
||||
|
||||
module sphericalFiletEdge(width, depth, height, roundness) {
|
||||
rd = roundness;
|
||||
|
||||
intersection() {
|
||||
minkowski() {
|
||||
sphere(r = rd);
|
||||
|
||||
translate(v = [rd, rd, rd])
|
||||
cube(size = [width*2, depth - 2*rd, height*2]);
|
||||
}
|
||||
|
||||
cube(size = [width, depth, height]);
|
||||
}
|
||||
}
|
||||
@ -1,95 +0,0 @@
|
||||
|
||||
// (c)2013 Felipe Sanches <juca@members.fsf.org>
|
||||
// licensed under the terms of the GNU GPL version 3 (or later)
|
||||
|
||||
function normalize(v) = v / (sqrt(v[0] * v[0] + v[1] * v[1]));
|
||||
|
||||
//
|
||||
// The voronoi() function generates a 2D surface, which can be provided to
|
||||
// a) linear_extrude() to produce a 3D object
|
||||
// b) intersection() to restrict it to a a specified shape -- see voronoi_polygon.scad
|
||||
//
|
||||
// Parameters:
|
||||
// points (required) ... nuclei coordinates (array of [x, y] pairs)
|
||||
// L ... the radius of the "world" (the pattern is built within this circle)
|
||||
// thickness ... the thickness of the lines between cells
|
||||
// round ... the radius applied to corners (fillet in CAD terms)
|
||||
// nuclei (bool) ... show nuclei sites
|
||||
//
|
||||
// These parameters need to be kept more or less in proportion to each other, and to the distance
|
||||
// apart of points in the point_set. If one or the other parameter is increased or decreased too
|
||||
// much, you'll get no output.
|
||||
//
|
||||
module voronoi(points, L = 200, thickness = 1, round = 6, nuclei = true) {
|
||||
for (p = points) {
|
||||
difference() {
|
||||
minkowski() {
|
||||
intersection_for(p1 = points){
|
||||
if (p != p1) {
|
||||
angle = 90 + atan2(p[1] - p1[1], p[0] - p1[0]);
|
||||
|
||||
translate((p + p1) / 2 - normalize(p1 - p) * (thickness + round))
|
||||
rotate([0, 0, angle])
|
||||
translate([-L, -L])
|
||||
square([2 * L, L]);
|
||||
}
|
||||
}
|
||||
circle(r = round, $fn = 20);
|
||||
}
|
||||
if (nuclei)
|
||||
translate(p) circle(r = 1, $fn = 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// The random_voronoi() function is the helper wrapper over the voronoi() core.
|
||||
// It generates random nuclei site coordinates into the square area,
|
||||
// passing other arguments to voronoi() unchanged.
|
||||
//
|
||||
// Parameters:
|
||||
// n ... number of nuclei sites to be generated
|
||||
// nuclei (bool) ... show nuclei sites
|
||||
// L ... the radius of the "world" (the pattern is built within this circle)
|
||||
// thickness ... the thickness of the lines between cells
|
||||
// round ... the radius applied to corners (fillet in CAD terms)
|
||||
// min ... minimum x and y coordinate for nuclei generation
|
||||
// max ... maximum x and y coordinate for nuclei generation
|
||||
// seed ... seed for the random generator (random if undefined)
|
||||
// center (bool) ... move resulting pattern to [0, 0] if true
|
||||
//
|
||||
module random_voronoi(n = 20, nuclei = true, L = 200, thickness = 1, round = 6, min = 0, max = 100, seed = undef, center = false) {
|
||||
seed = seed == undef ? rands(0, 100, 1)[0] : seed;
|
||||
echo("Seed", seed);
|
||||
|
||||
// Generate points.
|
||||
x = rands(min, max, n, seed);
|
||||
y = rands(min, max, n, seed + 1);
|
||||
points = [ for (i = [0 : n - 1]) [x[i], y[i]] ];
|
||||
|
||||
// Center Voronoi.
|
||||
offset_x = center ? -(max(x) - min(x)) / 2 : 0;
|
||||
offset_y = center ? -(max(y) - min(y)) / 2 : 0;
|
||||
translate([offset_x, offset_y])
|
||||
|
||||
voronoi(points, L = L, thickness = thickness, round = round, nuclei = nuclei);
|
||||
}
|
||||
|
||||
// example with an explicit list of points:
|
||||
point_set = [
|
||||
[0, 0], [30, 0], [20, 10], [50, 20], [15, 30], [85, 30], [35, 30], [12, 60],
|
||||
[45, 50], [80, 80], [20, -40], [-20, 20], [-15, 10], [-15, 50]
|
||||
];
|
||||
//voronoi(points = point_set, round = 4, nuclei = true);
|
||||
|
||||
module voronoi3u_N(h) {
|
||||
intersection() {
|
||||
translate(v=[10,5,0])
|
||||
cube(size=[160, 10, h]);
|
||||
translate(v=[20,-52,0])
|
||||
scale(v=[0.40,0.44,10])
|
||||
linear_extrude(height=10)
|
||||
random_voronoi(n = 128, round = 10, min = 0, max = 300, seed = 40, thickness=3.5, nuclei=false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user