common/common.scad

175 lines
5.4 KiB
OpenSCAD
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

IN = 25.4;
MM = 1;
function R (diameter) = diameter / 2.0;
function IN2MM(in) = in * IN;
function MM2IN(mm) = mm / IN;
module hex (diag = 10, h = 1) {
cylinder(r = diag / 2, h = h, center = true, $fn = 6);
}
module tube(o = 1, i = 0, h = 1, center = false, $fn = 12) {
$fn = $fn;
union () {
difference () {
cylinder(r = o, h = h, center = center);
cylinder(r = i, h = h, center = center);
}
}
}
module m3_nut (H = 5) {
cylinder(r=R(6.6), h=H, center=true, $fn=6);
}
module m4_nut (H = 3.1) {
cylinder(r = R(8.1), h = H, center = true, $fn = 6);
}
module rounded_cube (cube_arr = [1, 1, 1], d = 0, center = false) {
off_x = 0;
off_y = 0;
r = d/2;
union () {
cube([cube_arr[0] - d, cube_arr[1], cube_arr[2]], center = center);
cube([cube_arr[0], cube_arr[1] - d, cube_arr[2]], center = center);
translate ([1 * (cube_arr[0] / 2) - r , 1 * (cube_arr[1] / 2)- r, 0]) cylinder(r = r, h = cube_arr[2], center = center);
translate ([-1 * (cube_arr[0] / 2) + r, -1 * (cube_arr[1] / 2) + r, 0]) cylinder(r = r, h = cube_arr[2], center = center);
translate ([1 * (cube_arr[0] / 2) - r, -1 * (cube_arr[1] / 2) + r, 0]) cylinder(r = r, h = cube_arr[2], center = center);
translate ([-1 * (cube_arr[0] / 2) + r, 1 * (cube_arr[1] / 2)- r, 0]) cylinder(r = r, h = cube_arr[2], center = center);
}
}
module c_battery () {
/* C Cell battery, 26.1 × 50 */
x = 26.1;
x_fuzz = .3;
y = 50;
y_fuzz = 2;
cylinder(r = (x + x_fuzz) / 2, h = y + y_fuzz, center = true);
}
module sub_c_battery () {
/* Sub C Cell battery, 22.2 × 42.9 */
x = 22.2;
x_fuzz = .3;
y = 42.9;
y_fuzz = 2;
cylinder(r = (x + x_fuzz) / 2, h = y + y_fuzz, center = true);
}
module cone_45 (d = 1, center = false) {
cylinder(r1 = d/2, r2 = 0, h = d, center = center);
}
module decoys (d = 10, z = 0, number = 4, cube_size = 4, debug = false) {
for (i = [0: number]) {
rotate([0, 0, (360/number) * i]) translate([d, 0, z]) cube([cube_size, cube_size, cube_size], center = true);
if (debug && i == 0) {
rotate([0, 0, (360/number) * i]) translate([d, 0, z]) cube([cube_size * 5, cube_size* 5, cube_size], center = true);
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
// Paraboloid module for OpenScad
//
// Copyright (C) 2013 Lochner, Juergen
// http://www.thingiverse.com/Ablapo/designs
//
// This program is free software. It is
// licensed under the Attribution - Creative Commons license.
// http://creativecommons.org/licenses/by/3.0/
//////////////////////////////////////////////////////////////////////////////////////////////
module paraboloid (y=10, f=5, rfa=0, fc=1, detail=44){
// y = height of paraboloid
// f = focus distance
// fc : 1 = center paraboloid in focus point(x=0, y=f); 0 = center paraboloid on top (x=0, y=0)
// rfa = radius of the focus area : 0 = point focus
// detail = $fn of cone
hi = (y+2*f)/sqrt(2); // height and radius of the cone -> alpha = 45° -> sin(45°)=1/sqrt(2)
x =2*f*sqrt(y/f); // x = half size of parabola
translate([0,0,-f*fc]) // center on focus
rotate_extrude(convexity = 10,$fn=detail ) // extrude paraboild
translate([rfa,0,0]) // translate for fokus area
difference(){
union(){ // adding square for focal area
projection(cut = true) // reduce from 3D cone to 2D parabola
translate([0,0,f*2]) rotate([45,0,0]) // rotate cone 45° and translate for cutting
translate([0,0,-hi/2])cylinder(h= hi, r1=hi, r2=0, center=true, $fn=detail); // center cone on tip
translate([-(rfa+x ),0]) square ([rfa+x , y ]); // focal area square
}
translate([-(2*rfa+x ), -1/2]) square ([rfa+x ,y +1] ); // cut of half at rotation center
}
}
/*
// Height of trapazoid
height = 19;
// Width of top cube
top_x = 30;
// Length of top cube
top_y = 34;
// Width of bottom cube
bottom_x = 45;
// Length of bottom cube
bottom_y = 65;
wall_thickness = 2;
*/
module trap_cube(height = 19, top_x = 30, top_y = 34, bottom_x = 45, bottom_y = 65, wall_thickness = 2) {
difference(){
hull(){
translate([0,0,height])
cube([top_x, top_y, 0.1], center=true);
cube([bottom_x, bottom_y, 0.1], center=true);
}
hull(){
translate([0,0,height])
cube([top_x - wall_thickness, top_y - wall_thickness, 0.1], center=true);
cube([bottom_x - wall_thickness, bottom_y - wall_thickness, 0.1], center=true);
}
}
}
// switch module
module optoswitch() {
difference(){
union (){
color("gray") cube([24.5,3.5,6.4]);
color("gray")translate([6.63,0,0]) cube([4.45,11.3,6.3]);
color("gray")translate([13.63,0,0]) cube([4.45,11.3,6.3]);
}
for ( hole = [2.75,24.5-2.75] ){
rotate([90,0,0]) translate([hole,6.4/2,-4]) cylinder(r=1.5, h=4.5,$fn=40);
}
}
}
module opto_endstop () {
difference(){
union(){
// base PCB
color("green") cube([33.0,1.6,10.5]);
// add the switch module
translate([8.4,1.6,10.5/2-6.4/2]) optoswitch();
// connector
translate([0.2,-7,0]) color("white") cube([5.8,7,10.5]);
// led
translate([3.5,1.6,10.5/2-1.5/2]) color("red") cube([2,0.7,1.5]);
}
translate([8.4,0,10.5/2-6.4/2]) {
for ( hole = [2.75,24.5-2.75] ){
rotate([90,0,0]) translate([hole,6.4/2,-4]) cylinder(r=1.5, h=4.5,$fn=40);
}
}
}
}