OpenSCAD User Manual/MCAD

From Wikibooks, open books for an open world
Jump to navigation Jump to search


Overview of MCAD Library[edit | edit source]

Download source: github dot com/openscad/MCAD

The MCAD library contains components commonly used in designing and making mockup mechanical designs. It is currently unfinished and you can expect some API changes, however many things are already working.

This library was created by various authors as named in the individual files' comments. All the files are licensed under the LGPL 2.1 (see creativecommons dot org/licenses/LGPL/2.1/ or the included file lgpl-2.1.txt), some of them allow distribution under more permissive terms (as described in the files' comments).

Usage[edit | edit source]

You can import these files in your scripts with use <MCAD/filename.scad>, where 'filename' is one of the files listed below like 'motors' or 'servos'. Some files include useful constants that are available with include <MCAD/filename.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 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.

Currently Provided Tools:

  • regular_shapes.scad
    • regular polygons, ie. 2D
    • regular polyhedrons, ie. 3D
  • involute_gears.scad (on Thingiverse):
    • gear()
    • bevel_gear()
    • bevel_gear_pair()
  • gears.scad (Old version):
    • gear(number_of_teeth, circular_pitch OR diametrial_pitch, pressure_angle OPTIONAL, clearance OPTIONAL)
  • motors.scad:
    • stepper_motor_mount(nema_standard, slide_distance OPTIONAL, mochup OPTIONAL)

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
  • materials.scad: color definitions for different materials
  • stepper.scad: NEMA standard stepper outlines
  • servos.scad: servo outlines
  • boxes.scad: box with rounded corners
  • triangles.scad: simple triangles
  • 3d_triangle.scad: more advanced triangles

Very generally useful functions and constants:

  • math.scad: general math functions
  • constants.scad: mathematical constants
  • curves.scad: mathematical functions defining curves
  • units.scad: easy metric units
  • utilities.scad: geometric funtions and misc. useful stuff
  • teardrop.scad (www dot thingiverse dot com/thing:3457): parametric teardrop module
  • shapes.scad: DEPRECATED simple shapes by Catarina Mota
  • polyholes.scad: holes that should come out well when printed


  • alphabet_block.scad
  • bitmap.scad
  • letter_necklace.scad
  • name_tag.scad
  • height_map.scad
  • trochoids.scad
  • libtriangles.scad
  • layouts.scad
  • transformations.scad
  • 2Dshapes.scad
  • gridbeam.scad
  • fonts.scad
  • unregular_shapes.scad


  • lego_compatibility.scad
  • multiply.scad
  • hardware.scad

External utils that generate and process openscad code:

  • testing code, see below
  • code for scraping function names etc.

MCAD/regular_shapes.scad[edit | edit source]

2D regular shapes[edit | edit source]

regular_polygon(sides, radius), or in older libraries, reg_polygon(sides, radius)[edit | edit source]

n-gons 2D shapes[edit | edit source]


Screenshot of regular 2D shapes with varying number of sides
use <MCAD/regular_shapes.scad>

radius = 5;

translate([00,0,0]) triangle(radius);
translate([10,0,0]) pentagon(radius);
translate([20,0,0]) hexagon(radius);
translate([30,0,0]) heptagon(radius);
translate([40,0,0]) octagon(radius);
translate([50,0,0]) nonagon(radius);
translate([60,0,0]) decagon(radius);
translate([70,0,0]) hendecagon(radius);
translate([80,0,0]) dodecagon(radius);
triangle(radius)[edit | edit source]
pentagon(radius)[edit | edit source]
hexagon(radius)[edit | edit source]
heptagon(radius)[edit | edit source]
octagon(radius)[edit | edit source]
nonagon(radius)[edit | edit source]
decagon(radius)[edit | edit source]
hendecagon(radius)[edit | edit source]
dodecagon(radius)[edit | edit source]

ring(inside_diameter, thickness)[edit | edit source]


Screenshot of ring shape
use <MCAD/regular_shapes.scad>
ring(10, 5);

ellipse(width, height)[edit | edit source]


Screenshot of ellipse()
use <MCAD/regular_shapes.scad>
ellipse(30, 15);

egg_outline(width, length)[edit | edit source]


Screenshot of Egg_outline()
use <MCAD/regular_shapes.scad>
egg_outline(10, 15);

3D regular shapes[edit | edit source]

cone(height, radius, center = false)[edit | edit source]


Screenshot of cone()
use <MCAD/regular_shapes.scad>
cone(20, 10);

oval_prism(height, rx, ry, center = false)[edit | edit source]


Screenshot of oval_prism()
use <MCAD/regular_shapes.scad>
oval_prism(20, 15, 5);

oval_tube(height, rx, ry, wall, center = false)[edit | edit source]


Screenshot of oval_tube()
use <MCAD/regular_shapes.scad>
oval_tube(20, 10, 5, 1);

cylinder_tube(height, radius, wall, center = false)[edit | edit source]


Screenshot of cylinder_tube()
use <MCAD/regular_shapes.scad>
cylinder_tube(20, 10, 1);

triangle_prism(height,radius)[edit | edit source]


Screenshot of triangle_prism()
use <MCAD/regular_shapes.scad>

triangle_tube(height,radius,wall)[edit | edit source]


Screenshot of triangle_tube()
use <MCAD/regular_shapes.scad>
triangle_tube(20,10, 1);

pentagon_prism(height,radius)[edit | edit source]

Solid pentagon shape

pentagon_tube(height,radius,wall)[edit | edit source]

Hollow pentagon shape

hexagon_prism(height,radius)[edit | edit source]

Similar to above

hexagon_tube(height,radius,wall)[edit | edit source]

Similar to above

heptagon_prism(height,radius)[edit | edit source]

Similar to above

heptagon_tube(height,radius,wall)[edit | edit source]

Similar to above

octagon_prism(height,radius)[edit | edit source]

Similar to above

octagon_tube(height,radius,wall)[edit | edit source]

Similar to above

nonagon_prism(height,radius)[edit | edit source]

Similar to above

decagon_prism(height,radius)[edit | edit source]

Similar to above

hendecagon_prism(height,radius)[edit | edit source]

Similar to above

dodecagon_prism(height,radius)[edit | edit source]

Similar to above

torus(outerRadius, innerRadius)[edit | edit source]


Screenshot of torus()
use <MCAD/regular_shapes.scad>
torus(30, 15);

torus2(r1, r2)[edit | edit source]


Screenshot of torus2()
use <MCAD/regular_shapes.scad>
torus2(30, 5);

oval_torus(inner_radius, thickness=[0, 0])[edit | edit source]


Screenshot of oval_torus()
use <MCAD/regular_shapes.scad>
oval_torus(20, thickness=[4, 8], $fn=50);

triangle_pyramid(radius)[edit | edit source]


Screenshot of triangle_pyramid()
use <MCAD/regular_shapes.scad>

square_pyramid(base_x, base_y, height)[edit | edit source]


Screenshot of square_pyramid()
use <MCAD/regular_shapes.scad>
square_pyramid(10, 20, 30);

egg(width, length)[edit | edit source]

NOTE: I couldn't get egg() to work at the time of creating this document.

To Fix egg(): replace 'cube(' with 'square(' at line 254 pos 40 on regular_shapes.scad

MCAD/involute_gears.scad[edit | edit source]

NOTE regarding bevel gears: Two bevel gears mesh when they have the same cone distance, circular pitch (measured at the cone distance), and pressure angle.

bevel_gear_pair()[edit | edit source]

bevel_gear_pair (gear1_teeth = 41, gear2_teeth = 7, axis_angle = 90, outside_circular_pitch=1000)

bevel_gear()[edit | edit source]

bevel_gear (
    clearance = 0.2, 
    gear_thickness = 15, 
    backlash = 0, 
    finish = -1) 
    Bevel Gear Finishing Options:
    bevel_gear_flat = 0;
    bevel_gear_back_cone = 1;

More INFO:

  • number_of_teeth number of teeth
  • cone_distance Important to the angle of your gear teeth. See Cone Distance
  • pressure_angle Part of the terms that, taken together, make up the gear tooth profile. See Pressure_angle
  • bore_diameter Size of hole in middle of gear
  • outside_circular_pitch Roughly, this is the circumference of the gear. This is one of the most important measurements, and is worth looking up more precisely. See Pitch_circle. This indirectly controls the gear radius. Your gear's overall diameter is roughly the outside_circle_pitch / 360 * number_of_teeth. For example, 1000 / 360 * 36 would result in a gear approx 100mm in diameter.
  • finish Special parameter. Setting this equal to bevel_gear_flat (0) vs bevel_gear_back_cone (1) changes whether your gear looks like a flat bevel gear, or whether a back cone (similar to the 'cone' before) is used. See Back Cone
  • gear_thickness Bit of a misnomer. This is not the "typical" gear definition of thickness. Instead, it has nothing to do with the teeth of your gear and instead asks how tall of a cylinder the gear teeth should be placed on top oc

gear()[edit | edit source]

gear (
    circular_pitch=false, diametral_pitch=false,
    clearance = 0.2,

More INFO:

  • number_of_teeth number of teeth. Note that since circumference=2πr∝number_of_teeth the distance_between_gears∝total_number_of_teeth*pitch Basically if you have two gears, any two gears with the same sum number of teeth also fit at that distance.
  • circular_pitch, diametral_pitch proportional to the size of the teeth. (TODO proportionality constant)
  • pressure_angle
  • clearance
  • flat Makes the module a 2d object. This way you can `linear_extrude` it yourself.

The module has a lot of 'extra' features.

  • rim_thickness Thickness of edges(where it contacts.
  • gear_thickness Thickness inside, it cuts out a circle to make the inside flatter if smaller than rim thickness.
  • rim_width How far from the edge the gear is made at the
  • hub_thickness, hub_diameter, thicker bit in the center.
  • bore_diameter hole in center, for an axle, for instance.=
  • circles Makes the given number of holes around the center to save material
  • backlash
  • twist Twist in linear extruding. Used for making helical gears. (e.g.chevron/herringbone or worm drive gears)
  • involute_facets


 gear(number_of_teeth=20, circular_pitch=200, flat=true);

Tests[edit | edit source]

test_gears()[edit | edit source]


Demonstration of output from test_gears()
use <MCAD/involute_gears.scad>

test_meshing_double_helix()[edit | edit source]


Screenshot of output of testing_meshing_double_helix()
use <MCAD/involute_gears.scad>

test_bevel_gear()[edit | edit source]


Screenshot of test_bevel_gear
use <MCAD/involute_gears.scad>

test_bevel_gear_pair()[edit | edit source]


Screenshot of test_bevel_gear_pair()
use <MCAD/involute_gears.scad>

test_backlash()[edit | edit source]


Screenshot of test_backlash()
use <MCAD/involute_gears.scad>
test_backlash ();

MCAD/teardrop.scad[edit | edit source]

The teardrop shape can be used to make printing vertical holes easier for the 3d printer by avoiding steep overhangs.


Screenshot of Teardrop Shaped Cutouts
 use <MCAD/teardrop.scad>
 difference() {
     cube([5, 60, 40], center=true);
     translate([0, -15, 0]) teardrop(radius=6, length=20, angle=90);
     translate([0,   0, 0]) teardrop(radius=5, length=20, angle=60);
     translate([0,  15, 0]) teardrop(radius=4, length=20, angle=45);

MCAD/stepper.scad[edit | edit source]

The stepper's shaft is pointing in negative Z-direction. The stepper's round front plate is flush with the Z-Plane.


Screenshot of Stepper Motors
 include <MCAD/stepper.scad>
 for (size = [NemaShort, NemaMedium, NemaLong]) {  
   translate([50, size*100,0])  motor(Nema34, size, dualAxis=false);
   translate([150,size*100,0])  motor(Nema23, size, dualAxis=false);
   translate([250,size*100,0])  motor(Nema17, size, dualAxis=true);
   translate([350,size*100,0])  motor(Nema14, size, dualAxis=true);
   translate([450,size*100,0])  motor(Nema11, size, dualAxis=true);
   translate([550,size*100,0])  motor(Nema08, size, dualAxis=true);
 % translate([0, 150, 0.01]) cube([600, 200, 0.1]); 

MCAD/nuts_and_bolts.scad[edit | edit source]


Screenshot of M3 capscrew, nut, bole, and clearance holes
Screenshot of M3 capscrew, nut, bolt, and clearance holes
 use <MCAD/nuts_and_bolts.scad>
 include <MCAD/units.scad>


 //M3 is an alias for 3. It is defined in units.scad

 // cap screw
 boltHole(M3, length=10);
 // clearance hole for cap screw
 %translate([0, 7, 0])
   boltHole(M3, length=10, tolerance=0.3);
 // nut
 translate([7, 0, 0]) 
   nutHole(M3, tolerance=0.0);
 // nut hole
 %translate([7, 7, 0]) 
   nutHole(M3, tolerance=0.3);
 // bolt
 translate([14, 0, 0]){
    boltHole(M3, length=10);
    rotate([180,0,0])nutHole(M3, tolerance=0.0);}

MCAD/2Dshapes.scad[edit | edit source]


Screenshot of various 2D shapes
 use <MCAD/2Dshapes.scad>
 ellipse(width=50, height=80);
 translate([100, 0, 0]) pieSlice([50, 100], start_angle=0, end_angle=250);
 translate([210, 0, 0]) donutSlice(20,50,0,300);
 translate([320, 0, 0]) ngon(6, 50, center=false);