Merge ArthurGibbs/fixShapes into master (#5)

This commit is contained in:
Chow Loong Jin 2019-07-23 21:41:55 +08:00
commit 889200a79c

View file

@ -6,25 +6,30 @@
* 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, radius); 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, radius);
//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);
*/
//---------------------- //----------------------
@ -72,19 +77,21 @@ module ellipsoid(w, h, center = false) {
// wall is wall thickness // wall is wall thickness
module tube(height, radius, wall, center = false) { module tube(height, radius, wall, center = false) {
echo_deprecated_shapes_library(); echo_deprecated_shapes_library();
linear_extrude (height = height, center = center) {
difference() {
circle(r = radius);
circle(r = radius - wall);
}
}
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, ID, OD, center = false) { module tube2(height, ID, OD, center = false) {
echo_deprecated_shapes_library(); tube(height = height, center = center, radius = OD / 2, wall = (OD - ID)/2);
difference() {
cylinder(h=height, r=OD/2, center=center);
cylinder(h=height, r=ID/2, center=center);
}
} }
// wall is wall thickness // wall is wall thickness
@ -100,7 +107,9 @@ module ovalTube(height, rx, ry, wall, center = false) {
module hexagon(size, height) { module hexagon(size, height) {
echo_deprecated_shapes_library(); echo_deprecated_shapes_library();
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 // size is the XY plane size, height in Z
@ -108,7 +117,8 @@ module octagon(size, height) {
echo_deprecated_shapes_library(); echo_deprecated_shapes_library();
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);
} }
} }
@ -136,9 +146,11 @@ module hexagram(size, height) {
module rightTriangle(adjacent, opposite, height) { module rightTriangle(adjacent, opposite, height) {
echo_deprecated_shapes_library(); echo_deprecated_shapes_library();
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);
} }
} }
} }
@ -157,7 +169,7 @@ module equiTriangle(side, height) {
module 12ptStar(size, height) { module 12ptStar(size, height) {
echo_deprecated_shapes_library(); echo_deprecated_shapes_library();
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);
} }
@ -168,10 +180,3 @@ module 12ptStar(size, height) {
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();}