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 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 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. See http://creativecommons.org/licenses/LGPL/2.1/ or the included file, lgpl-2.1.txt.
== Usage == ## 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>", 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 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 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 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 details. Since the maintainers aren't very responsive, may have to work around this
somehow) 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 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, 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. do `cd PATH; git checkout master; git pull`. See `git help submodule` for more info.
Currently Provided Tools: Currently Provided Tools:
@ -36,6 +37,7 @@ Currently Provided Tools:
- stepper_motor_mount(nema_standard, slide_distance OPTIONAL, mochup OPTIONAL) - stepper_motor_mount(nema_standard, slide_distance OPTIONAL, mochup OPTIONAL)
Other tools (alpha and beta quality): Other tools (alpha and beta quality):
* nuts_and_bolts.scad: for creating metric and imperial bolt/nut holes * nuts_and_bolts.scad: for creating metric and imperial bolt/nut holes
* bearing.scad: standard/custom bearings * bearing.scad: standard/custom bearings
* screw.scad: screws and augers * screw.scad: screws and augers
@ -46,6 +48,7 @@ Other tools (alpha and beta quality):
* triangles.scad: simple triangles * triangles.scad: simple triangles
Very generally useful functions and constants: Very generally useful functions and constants:
* math.scad: general math functions * math.scad: general math functions
* constants.scad: mathematical constants * constants.scad: mathematical constants
* curves.scad: mathematical functions defining curves * curves.scad: mathematical functions defining curves
@ -55,10 +58,12 @@ Very generally useful functions and constants:
* shapes.scad: simple shapes by Catarina Mota * shapes.scad: simple shapes by Catarina Mota
External utils that generate and and process openscad code: External utils that generate and and process openscad code:
* openscad_testing.py: testing code, see below * openscad_testing.py: testing code, see below
* openscad_utils.py: code for scraping function names etc. * 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 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 accomodate the community as much as possible in this. If for some reason you
want collaborator access, just ask. 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 improvements directly, and have already included code from various sources
(thingiverse is great :) (thingiverse is great :)
=== Code style === ### Code style ###
I'd prefer to have all included code nicely indented, at least at the block 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 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 opposed to tabs or other mixes of whitespace, but at least try to choose a style
and stick to it. and stick to it.
=== Testing === ### Testing ###
I've started a minimal testing infrastucture for OpenSCAD code. It's written in 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 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 and tracebacks for failing tests. It's very simplistic still, but it should test
that no syntax errors occur at least. that no syntax errors occur at least.

View file

@ -1,21 +1,25 @@
/* /*
* OpenSCAD Shapes Library (www.openscad.org) * OpenSCAD Shapes Library (www.openscad.org)
* Copyright (C) 2009 Catarina Mota * Copyright (C) 2009 Catarina Mota
* Copyright (C) 2010 Elmo Mäntynen
* *
* License: LGPL 2.1 or later * License: LGPL 2.1 or later
*/ */
// 2D Shapes // 2D Shapes
//ellipse(width, height); //ellipse(width, height);
//egg_outline(width=5, length=7);
//ngon(sides, radius, center=false);
// 3D Shapes // 3D Shapes
//box(width, height, depth); //box(width, height, depth);
//roundedBox(width, height, depth, factor); //roundedBox(width, height, depth, factor);
//cone(height, radius); //cone(height, radius);
//ellipticalCylinder(width, height, depth); //ellipticalCylinder(width, height, depth);
//ellipsoid(width, height); //ellipsoid(width, height);
//tube(height, radius, wall); //tube(height, radius, wall, center = false);
//ovalTube(width, height, depth, wall); //tube2(height, ID, OD, center = false);
//ovalTube(width, height, depth, wall, center = false);
//hexagon(height, depth); //hexagon(height, depth);
//octagon(height, depth); //octagon(height, depth);
//dodecagon(height, depth); //dodecagon(height, depth);
@ -27,12 +31,13 @@
//---------------------- //----------------------
// size is a vector [w, h, d] // size is a vector [w, h, d]
module box(size) { module box(width, height, depth,) {
cube(size, true); cube([width, height, depth,], true);
} }
// size is a vector [w, h, d] // 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 - [2*radius,0,0], true);
cube(size - [0,2*radius,0], true); cube(size - [0,2*radius,0], true);
for (x = [radius-size[0]/2, -radius+size[0]/2], 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); scale([1, h/w, 1]) cylinder(h=height, r=w, center=center);
} }
module ellipse(w, h) { module ellipse(w, h, center = false) {
scale([1, h/w, 1]) circle(r=w, center=center); scale([1, h/w, 1]) circle(r=w/2, center=center);
} }
module ellipsoid(w, h) { module ellipsoid(w, h, center = false) {
scale([1, h/w, 1]) sphere(r=w, center=center); 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 // 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 // wall is wall thickness
module ovalTube(height, rx, ry, wall, center = false) { module ovalTube(height, rx, ry, wall, center = false) {
difference() { 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 // size is the XY plane size, height in Z
module hexagon(size, height) { module hexagon(size, height) {
boxWidth = size/1.75; 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 //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();}