Merge branch 'master' of github.com:elmom/MCAD

This commit is contained in:
Timothy Schmidt 2011-01-18 06:11:19 -05:00
commit 1eaf67207a
2 changed files with 62 additions and 22 deletions

View file

@ -1,4 +1,4 @@
OpenSCAD MCAD Library
OpenSCAD MCAD Library [![](http://stillmaintained.com/elmom/MCAD.png)](http://stillmaintained.com/elmom/MCAD)
=====================
This library contains components commonly used in designing and moching up
@ -8,19 +8,20 @@ changes, however many things are already working.
This library is licensed under the LGPL 2.1
See http://creativecommons.org/licenses/LGPL/2.1/ or the included file, lgpl-2.1.txt.
== Usage ==
You can import these files in your scripts with "use <MCAD/*.scad>", but some
files include useful constants which will be available with "include <MCAD/*.scad>",
## Usage ##
You can import these files in your scripts with `use <MCAD/*.scad>`, but some
files include useful constants which will be available with `include <MCAD/*.scad>`,
which should be safe to use on all included files (ie. no top level code should
create geometry). (There is a bug/feature that prevents including constants from
files that "include" other files - see the openscad mailing list archives for more
details. Since the maintainers aren't very responsive, may have to work around this
somehow)
If you host your project in git, you can do "git submodule add URL PATH" in your
If you host your project in git, you can do `git submodule add URL PATH` in your
repo to import this library as a git submodule for easy usage. Then you need to do
a "git submodule update --init" after cloning. When you want to update the submodule,
do "cd PATH; git checkout master; git pull". See "git help submodule"" for more info.
a `git submodule update --init` after cloning. When you want to update the submodule,
do `cd PATH; git checkout master; git pull`. See `git help submodule` for more info.
Currently Provided Tools:
@ -36,6 +37,7 @@ Currently Provided Tools:
- stepper_motor_mount(nema_standard, slide_distance OPTIONAL, mochup OPTIONAL)
Other tools (alpha and beta quality):
* nuts_and_bolts.scad: for creating metric and imperial bolt/nut holes
* bearing.scad: standard/custom bearings
* screw.scad: screws and augers
@ -46,6 +48,7 @@ Other tools (alpha and beta quality):
* triangles.scad: simple triangles
Very generally useful functions and constants:
* math.scad: general math functions
* constants.scad: mathematical constants
* curves.scad: mathematical functions defining curves
@ -55,10 +58,12 @@ Very generally useful functions and constants:
* shapes.scad: simple shapes by Catarina Mota
External utils that generate and and process openscad code:
* openscad_testing.py: testing code, see below
* openscad_utils.py: code for scraping function names etc.
== Development ==
## Development ##
You are welcome to fork this project in github and request pulls. I will try to
accomodate the community as much as possible in this. If for some reason you
want collaborator access, just ask.
@ -67,15 +72,15 @@ Github is fun (and easy), but I can include code submissions and other
improvements directly, and have already included code from various sources
(thingiverse is great :)
=== Code style ===
### Code style ###
I'd prefer to have all included code nicely indented, at least at the block
level, and no extraneous whitespace. I'm used to indent with four spaces as
opposed to tabs or other mixes of whitespace, but at least try to choose a style
and stick to it.
=== Testing ===
### Testing ###
I've started a minimal testing infrastucture for OpenSCAD code. It's written in
python and uses py.test (might be compatible with Nose also). Just type py.test
python and uses py.test (might be compatible with Nose also). Just type `py.test`
inside the lib dir in a terminal and you should see a part of the tests passing
and tracebacks for failing tests. It's very simplistic still, but it should test
that no syntax errors occur at least.

View file

@ -1,21 +1,25 @@
/*
* OpenSCAD Shapes Library (www.openscad.org)
* Copyright (C) 2009 Catarina Mota
* Copyright (C) 2010 Elmo Mäntynen
*
* License: LGPL 2.1 or later
*/
// 2D Shapes
//ellipse(width, height);
//egg_outline(width=5, length=7);
//ngon(sides, radius, center=false);
// 3D Shapes
//box(width, height, depth);
//roundedBox(width, height, depth, factor);
//cone(height, radius);
//ellipticalCylinder(width, height, depth);
//ellipsoid(width, height);
//tube(height, radius, wall);
//ovalTube(width, height, depth, wall);
//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);
@ -27,12 +31,13 @@
//----------------------
// size is a vector [w, h, d]
module box(size) {
cube(size, true);
module box(width, height, depth,) {
cube([width, height, depth,], true);
}
// size is a vector [w, h, d]
module roundedBox(size, radius) {
module roundedBox(width, height, depth, radius) {
size=[width, height, depth,];
cube(size - [2*radius,0,0], true);
cube(size - [0,2*radius,0], true);
for (x = [radius-size[0]/2, -radius+size[0]/2],
@ -49,12 +54,22 @@ module ellipticalCylinder(w,h, height, center = false) {
scale([1, h/w, 1]) cylinder(h=height, r=w, center=center);
}
module ellipse(w, h) {
scale([1, h/w, 1]) circle(r=w, center=center);
module ellipse(w, h, center = false) {
scale([1, h/w, 1]) circle(r=w/2, center=center);
}
module ellipsoid(w, h) {
scale([1, h/w, 1]) sphere(r=w, center=center);
module ellipsoid(w, h, center = false) {
scale([1, h/w, 1]) sphere(r=w/2, center=center);
}
module egg_outline(width=5, length=7){
union(){
difference(){
ellipse(width, 2*length-width, center=true);
translate([0, length/2, 0]) square(length, center=true);
}
circle(r=width/2, center=true);
}
}
// wall is wall thickness
@ -65,6 +80,14 @@ module tube(height, radius, wall, center = false) {
}
}
// wall is wall thickness
module tube2(height, ID, OD, center = false) {
difference() {
cylinder(h=height, r=OD/2, center=center);
cylinder(h=height, r=ID/2, center=center);
}
}
// wall is wall thickness
module ovalTube(height, rx, ry, wall, center = false) {
difference() {
@ -73,6 +96,11 @@ module ovalTube(height, rx, ry, wall, center = false) {
}
}
// The orientation might change with the implementation of circle...
module ngon(sides, radius, center=false){
rotate([0, 0, 360/sides/2]) circle(r=radius, $fn=sides, center=center);
}
// size is the XY plane size, height in Z
module hexagon(size, height) {
boxWidth = size/1.75;
@ -137,4 +165,11 @@ module 12ptStar(size, height) {
//MOVES THE ROTATION AXIS OF A BOX FROM ITS CENTER TO THE BOTTOM LEFT CORNER
module dislocateBox(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();}