first bash at cleaning up shapes. needs rewrite for perf and capabilities

This commit is contained in:
arthur 2013-12-21 22:40:23 +00:00
parent b2da70e92f
commit 4b20955aca

View file

@ -6,35 +6,44 @@
* License: LGPL 2.1 or later * License: LGPL 2.1 or later
*/ */
// 2D Shapes include <units.scad>
//ngon(sides, radius, center=false);
// 3D Shapes /*
//box(width, height, depth); 2D Shapes
//roundedBox(width, height, depth, factor); ngon(sides, radius, center=false);
//cone(height, radius);
//ellipticalCylinder(width, height, depth); 3D Shapes
//ellipsoid(width, height); box(width, height, depth);
//tube(height, radius, wall, center = false); roundedBox(width, height, depth, factor);
//tube2(height, ID, OD, center = false); cone(height, radius);
//ovalTube(width, height, depth, wall, center = false); ellipticalCylinder(width, height, depth);
//hexagon(height, depth); ellipsoid(width, height);
//octagon(height, depth); tube(height, radius, wall, center = false);
//dodecagon(height, depth); tube2(height, ID, OD, center = false);
//hexagram(height, depth); ovalTube(width, height, depth, wall, center = false);
//rightTriangle(adjacent, opposite, depth); hexagon(height, depth);
//equiTriangle(side, depth); octagon(height, depth);
//12ptStar(height, depth); dodecagon(height, depth);
hexagram(height, depth);
rightTriangle(adjacent, opposite, depth);
equiTriangle(side, depth);
12ptStar(height, depth);
*/
//---------------------- //----------------------
// size is a vector [w, h, d] // size is a vector [w, h, d]
module box(width, height, depth) { module box(width, height, depth) {
echo("USE CUBE[size=[w,d,h,true]]");
cube([width, height, depth], true); cube([width, height, depth], true);
} }
// size is a vector [w, h, d] // size is a vector [w, h, d]
module roundedBox(width, height, depth, radius) { module roundedBox(width = 1,
height = 1,
depth = 1,
radius = 0.2) {
size=[width, height, depth]; size=[width, height, depth];
cube(size - [2*radius,0,0], true); cube(size - [2*radius,0,0], true);
cube(size - [0,2*radius,0], true); cube(size - [0,2*radius,0], true);
@ -56,54 +65,62 @@ module ellipsoid(w, h, center = false) {
scale([1, h/w, 1]) sphere(r=w/2, center=center); scale([1, h/w, 1]) sphere(r=w/2, center=center);
} }
// wall is wall thickness module tube(height = 10,
module tube(height, radius, wall, center = false) { radius = 10,
wall = 2,
center = false) {
difference() { difference() {
cylinder(h=height, r=radius, center=center); cylinder(h=height, r=radius, center=center);
cylinder(h=height, r=radius-wall, center=center); translate([0,0,-epsilon])
cylinder(h=height+2*epsilon, r=radius-wall, center=center);
} }
} }
// wall is wall thickness module tube2(height = 10,
module tube2(height, ID, OD, center = false) { ID = 16,
difference() { OD = 20,
cylinder(h=height, r=OD/2, center=center); center = false) {
cylinder(h=height, r=ID/2, center=center); tube(height=height,center=center,radius=OD/2,wall=(OD/2)-(ID/2));
}
} }
// wall is wall thickness module ovalTube(height = 5,
module ovalTube(height, rx, ry, wall, center = false) { rx = 10,
ry = 5,
wall = 1,
center = false) {
difference() { difference() {
scale([1, ry/rx, 1]) cylinder(h=height, r=rx, center=center); scale([1, ry/rx, 1]) cylinder(h=height, r=rx, center=center);
scale([(rx-wall)/rx, (ry-wall)/rx, 1]) cylinder(h=height, r=rx, center=center); scale([(rx-wall)/rx, (ry-wall)/rx, 1]) cylinder(h=height, r=rx, center=center);
} }
} }
// size is the XY plane size, height in Z module hexagon(size = 10,
module hexagon(size, height) { height = 5) {
boxWidth = size/1.75; boxWidth = size/1.75;
for (r = [-60, 0, 60]) rotate([0,0,r]) cube([boxWidth, size, height], true); for (r = [-60, 0, 60])
rotate([0,0,r])
cube([boxWidth, size, height], true);
} }
// size is the XY plane size, height in Z module octagon(size = 10,
module octagon(size, height) { height = 5) {
intersection() { intersection() {
cube([size, size, height], true); cube([size, size, height], true);
rotate([0,0,45]) cube([size, size, height], true); rotate([0,0,45])
cube([size, size, height], true);
} }
} }
// size is the XY plane size, height in Z module dodecagon(size = 10,
module dodecagon(size, height) { height = 5) {
intersection() { intersection() {
hexagon(size, height); hexagon(size, height);
rotate([0,0,90]) hexagon(size, height); rotate([0,0,90]) hexagon(size, height);
} }
} }
// size is the XY plane size, height in Z module hexagram(size = 10,
module hexagram(size, height) { height = 5) {
boxWidth=size/1.75; boxWidth=size/1.75;
for (v = [[0,1],[0,-1],[1,-1]]) { for (v = [[0,1],[0,-1],[1,-1]]) {
intersection() { intersection() {
@ -115,9 +132,11 @@ module hexagram(size, height) {
module rightTriangle(adjacent, opposite, height) { module rightTriangle(adjacent, opposite, height) {
difference() { difference() {
translate([-adjacent/2,opposite/2,0]) cube([adjacent, opposite, height], true); translate([-adjacent/2,opposite/2,0])
cube([adjacent, opposite, height], true);
translate([-adjacent,0,0]) { translate([-adjacent,0,0]) {
rotate([0,0,atan(opposite/adjacent)]) dislocateBox(adjacent*2, opposite, height+2); rotate([0,0,atan(opposite/adjacent)])
dislocateBox(adjacent*2, opposite, height+2);
} }
} }
} }
@ -132,23 +151,15 @@ module equiTriangle(side, height) {
} }
} }
module 12ptStar(size, height) { module 12ptStar(size = 12,
height = 5) {
starNum = 3; starNum = 3;
starAngle = 360/starNum; starAngle = 90/starNum;
for (s = [1:starNum]) { for (s = [1:starNum]) {
rotate([0, 0, s*starAngle]) cube([size, size, height], true); rotate([0, 0, s*starAngle]) cube([size, size, height], true);
} }
} }
//-----------------------
//MOVES THE ROTATION AXIS OF A BOX FROM ITS CENTER TO THE BOTTOM LEFT CORNER
module dislocateBox(w, h, d) { module dislocateBox(w, h, d) {
translate([0,0,-d/2]) cube([w,h,d]); translate([0,0,-d/2]) cube([w,h,d]);
} }
//-----------------------
// Tests
//module test2D_ellipse(){ellipse(10, 5);}
module test_ellipsoid(){ellipsoid(10, 5);}
//module test2D_egg_outline(){egg_outline();}