2010-08-26 04:04:17 -05:00
|
|
|
/*
|
|
|
|
* OpenSCAD Shapes Library (www.openscad.org)
|
|
|
|
* Copyright (C) 2009 Catarina Mota
|
2011-01-08 05:35:24 -06:00
|
|
|
* Copyright (C) 2010 Elmo Mäntynen
|
2010-08-26 04:04:17 -05:00
|
|
|
*
|
|
|
|
* License: LGPL 2.1 or later
|
|
|
|
*/
|
|
|
|
|
2013-12-21 16:40:23 -06:00
|
|
|
include <units.scad>
|
|
|
|
|
|
|
|
/*
|
|
|
|
2D Shapes
|
|
|
|
ngon(sides, radius, center=false);
|
|
|
|
|
|
|
|
3D Shapes
|
|
|
|
box(width, height, depth);
|
2019-07-23 08:41:55 -05:00
|
|
|
roundedBox(width, height, depth, radius);
|
2013-12-21 16:40:23 -06:00
|
|
|
cone(height, radius);
|
|
|
|
ellipticalCylinder(width, height, depth);
|
|
|
|
ellipsoid(width, height);
|
|
|
|
tube(height, radius, wall, center = false);
|
|
|
|
tube2(height, ID, OD, center = false);
|
|
|
|
ovalTube(width, height, depth, wall, center = false);
|
|
|
|
hexagon(height, depth);
|
|
|
|
octagon(height, depth);
|
|
|
|
dodecagon(height, depth);
|
|
|
|
hexagram(height, depth);
|
|
|
|
|
|
|
|
rightTriangle(adjacent, opposite, depth);
|
|
|
|
equiTriangle(side, depth);
|
|
|
|
12ptStar(height, depth);
|
|
|
|
*/
|
2010-08-26 04:04:17 -05:00
|
|
|
|
|
|
|
//----------------------
|
|
|
|
|
2018-10-07 11:40:26 -05:00
|
|
|
echo_deprecated_shapes_library();
|
2018-09-28 14:16:05 -05:00
|
|
|
|
2018-10-07 11:40:26 -05:00
|
|
|
module echo_deprecated_shapes_library() {
|
2018-09-28 14:16:05 -05:00
|
|
|
echo("<font color='red'>
|
2018-10-04 13:04:09 -05:00
|
|
|
DEPRECATED: 'shapes' library is now deprecated
|
|
|
|
please use 'regular_shapes' instead</font>");
|
2018-09-28 14:16:05 -05:00
|
|
|
}
|
|
|
|
|
2010-08-26 04:04:17 -05:00
|
|
|
// size is a vector [w, h, d]
|
2011-01-21 02:40:36 -06:00
|
|
|
module box(width, height, depth) {
|
2018-10-07 11:40:26 -05:00
|
|
|
echo_deprecated_shapes_library();
|
2011-01-21 02:40:36 -06:00
|
|
|
cube([width, height, depth], true);
|
2010-08-26 04:04:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// size is a vector [w, h, d]
|
2011-01-08 05:32:58 -06:00
|
|
|
module roundedBox(width, height, depth, radius) {
|
2018-10-07 11:40:26 -05:00
|
|
|
echo_deprecated_shapes_library();
|
2011-01-21 02:40:36 -06:00
|
|
|
size=[width, height, depth];
|
2010-08-26 04:04:17 -05:00
|
|
|
cube(size - [2*radius,0,0], true);
|
|
|
|
cube(size - [0,2*radius,0], true);
|
|
|
|
for (x = [radius-size[0]/2, -radius+size[0]/2],
|
|
|
|
y = [radius-size[1]/2, -radius+size[1]/2]) {
|
|
|
|
translate([x,y,0]) cylinder(r=radius, h=size[2], center=true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module cone(height, radius, center = false) {
|
2018-10-07 11:40:26 -05:00
|
|
|
echo_deprecated_shapes_library();
|
2010-08-26 04:04:17 -05:00
|
|
|
cylinder(height, radius, 0, center);
|
|
|
|
}
|
|
|
|
|
2010-12-18 10:19:44 -06:00
|
|
|
module ellipticalCylinder(w,h, height, center = false) {
|
2018-10-07 11:40:26 -05:00
|
|
|
echo_deprecated_shapes_library();
|
2010-08-26 04:04:17 -05:00
|
|
|
scale([1, h/w, 1]) cylinder(h=height, r=w, center=center);
|
|
|
|
}
|
|
|
|
|
2011-01-08 03:46:57 -06:00
|
|
|
module ellipsoid(w, h, center = false) {
|
2018-10-07 11:40:26 -05:00
|
|
|
echo_deprecated_shapes_library();
|
2011-01-08 03:46:57 -06:00
|
|
|
scale([1, h/w, 1]) sphere(r=w/2, center=center);
|
2010-12-18 10:19:44 -06:00
|
|
|
}
|
|
|
|
|
2010-08-26 04:04:17 -05:00
|
|
|
// wall is wall thickness
|
|
|
|
module tube(height, radius, wall, center = false) {
|
2018-10-07 11:40:26 -05:00
|
|
|
echo_deprecated_shapes_library();
|
2019-07-23 08:41:55 -05:00
|
|
|
linear_extrude (height = height, center = center) {
|
|
|
|
difference() {
|
|
|
|
circle(r = radius);
|
|
|
|
circle(r = radius - wall);
|
|
|
|
}
|
|
|
|
}
|
2010-08-26 04:04:17 -05:00
|
|
|
difference() {
|
|
|
|
cylinder(h=height, r=radius, center=center);
|
2019-07-23 08:41:55 -05:00
|
|
|
translate([0,0,-epsilon])
|
2013-12-21 16:40:23 -06:00
|
|
|
cylinder(h=height+2*epsilon, r=radius-wall, center=center);
|
2010-08-26 04:04:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-08 07:37:56 -06:00
|
|
|
module tube2(height, ID, OD, center = false) {
|
2019-07-23 08:41:55 -05:00
|
|
|
tube(height = height, center = center, radius = OD / 2, wall = (OD - ID)/2);
|
2011-01-08 07:37:56 -06:00
|
|
|
}
|
|
|
|
|
2010-08-26 04:04:17 -05:00
|
|
|
// wall is wall thickness
|
|
|
|
module ovalTube(height, rx, ry, wall, center = false) {
|
2018-10-07 11:40:26 -05:00
|
|
|
echo_deprecated_shapes_library();
|
2010-08-26 04:04:17 -05:00
|
|
|
difference() {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// size is the XY plane size, height in Z
|
|
|
|
module hexagon(size, height) {
|
2018-10-07 11:40:26 -05:00
|
|
|
echo_deprecated_shapes_library();
|
2010-08-26 04:04:17 -05:00
|
|
|
boxWidth = size/1.75;
|
2019-07-23 08:41:55 -05:00
|
|
|
for (r = [-60, 0, 60])
|
|
|
|
rotate([0,0,r])
|
2013-12-21 16:40:23 -06:00
|
|
|
cube([boxWidth, size, height], true);
|
2010-08-26 04:04:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// size is the XY plane size, height in Z
|
|
|
|
module octagon(size, height) {
|
2018-10-07 11:40:26 -05:00
|
|
|
echo_deprecated_shapes_library();
|
2010-08-26 04:04:17 -05:00
|
|
|
intersection() {
|
|
|
|
cube([size, size, height], true);
|
2019-07-23 08:41:55 -05:00
|
|
|
rotate([0,0,45])
|
|
|
|
cube([size, size, height], true);
|
2010-08-26 04:04:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// size is the XY plane size, height in Z
|
|
|
|
module dodecagon(size, height) {
|
2018-10-07 11:40:26 -05:00
|
|
|
echo_deprecated_shapes_library();
|
2010-08-26 04:04:17 -05:00
|
|
|
intersection() {
|
|
|
|
hexagon(size, height);
|
|
|
|
rotate([0,0,90]) hexagon(size, height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// size is the XY plane size, height in Z
|
|
|
|
module hexagram(size, height) {
|
2018-10-07 11:40:26 -05:00
|
|
|
echo_deprecated_shapes_library();
|
2010-08-26 04:04:17 -05:00
|
|
|
boxWidth=size/1.75;
|
|
|
|
for (v = [[0,1],[0,-1],[1,-1]]) {
|
|
|
|
intersection() {
|
|
|
|
rotate([0,0,60*v[0]]) cube([size, boxWidth, height], true);
|
|
|
|
rotate([0,0,60*v[1]]) cube([size, boxWidth, height], true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module rightTriangle(adjacent, opposite, height) {
|
2018-10-07 11:40:26 -05:00
|
|
|
echo_deprecated_shapes_library();
|
2010-08-26 04:04:17 -05:00
|
|
|
difference() {
|
2019-07-23 08:41:55 -05:00
|
|
|
translate([-adjacent/2,opposite/2,0])
|
2013-12-21 16:40:23 -06:00
|
|
|
cube([adjacent, opposite, height], true);
|
2010-08-26 04:04:17 -05:00
|
|
|
translate([-adjacent,0,0]) {
|
2019-07-23 08:41:55 -05:00
|
|
|
rotate([0,0,atan(opposite/adjacent)])
|
2013-12-21 16:40:23 -06:00
|
|
|
dislocateBox(adjacent*2, opposite, height+2);
|
2010-08-26 04:04:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module equiTriangle(side, height) {
|
2018-10-07 11:40:26 -05:00
|
|
|
echo_deprecated_shapes_library();
|
2010-08-26 04:04:17 -05:00
|
|
|
difference() {
|
|
|
|
translate([-side/2,side/2,0]) cube([side, side, height], true);
|
|
|
|
rotate([0,0,30]) dislocateBox(side*2, side, height);
|
|
|
|
translate([-side,0,0]) {
|
|
|
|
rotate([0,0,60]) dislocateBox(side*2, side, height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module 12ptStar(size, height) {
|
2018-10-07 11:40:26 -05:00
|
|
|
echo_deprecated_shapes_library();
|
2010-08-26 04:04:17 -05:00
|
|
|
starNum = 3;
|
2013-12-21 16:40:23 -06:00
|
|
|
starAngle = 90/starNum;
|
2010-08-26 04:04:17 -05:00
|
|
|
for (s = [1:starNum]) {
|
|
|
|
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
|
2010-12-22 13:46:28 -06:00
|
|
|
module dislocateBox(w, h, d) {
|
|
|
|
translate([0,0,-d/2]) cube([w,h,d]);
|
2011-01-08 03:46:57 -06:00
|
|
|
}
|