# OpenSCAD User Manual/MCAD

NOTE: WIP

## Overview of MCAD Library

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

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 functions 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
Other:
* 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
Umetric_fastners.scad
* lego_compatibility.scad
* multiply.scad
* hardware.scad
External utils that generate and process openscad code:
* openscad_testing.py: testing code, see below
* openscad_utils.py: code for scraping function names etc.

## MCAD/regular_shapes.scad
### 2D regular shapes

This library is no longer the best way to create regular polygons — you can do this more efficiently with:
The regular polygon functions will be retained for compatibility and readability.

#### n-gons 2D shapes

Example:

##### hexagon(radius, diameter, across_flats)

Specify one of these three arguments giving the radius from center to a vertex, the diameter between opposite vertices, or as across_flats, the distance between opposite sides.

##### dodecagon(radius)
#### ring(inside_diameter, thickness)

Example:

#### ellipse(width, height)

Example:

#### egg_outline(width, length)

Example:

### 3D regular shapes
#### cone(height, radius, center = false)

Example:

#### oval_prism(height, rx, ry, center = false)

This is a cylinder with unequal x and y dimensions specified here as radii.
Example:

#### oval_tube(height, rx, ry, wall, center = false)

Difference of two scaled cylinders. Note this does not give a wall of even thickness if the cylinders are elliptical -- you would need to use offset for that.
Example:

#### cylinder_tube(height, radius, wall, center = false)

Example:

#### triangle_prism(height,radius)

Example:

#### triangle_tube(height,radius,wall)

Example:

#### pentagon_prism(height,radius)

Solid pentagon shape

#### pentagon_tube(height,radius,wall)

Hollow pentagon shape

#### hexagon_prism(height,radius)

Similar to above

#### hexagon_tube(height,radius,wall)

Similar to above

#### heptagon_prism(height,radius)

Similar to above

#### heptagon_tube(height,radius,wall)

Similar to above

#### octagon_prism(height,radius)

Similar to above

#### octagon_tube(height,radius,wall)

Similar to above

#### nonagon_prism(height,radius)

Similar to above

#### decagon_prism(height,radius)

Similar to above

#### hendecagon_prism(height,radius)

Similar to above

#### dodecagon_prism(height,radius)

Similar to above

#### torus(outerRadius, innerRadius)

Example:

#### torus2(r1, r2)

Example:

#### oval_torus(inner_radius, thickness=[0, 0])

Example:

#### triangle_pyramid(radius)

Example:

#### square_pyramid(base_x, base_y, height)

Example:

#### egg(width, length)

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

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

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

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
Example:

### Tests
#### test_gears

Example:

#### test_meshing_double_helix

Example:

#### test_bevel_gear

Example:

#### test_bevel_gear_pair

Example:

#### test_backlash

Example:

## MCAD/teardrop.scad

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

## MCAD/stepper.scad

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

## MCAD/nuts_and_bolts.scad

Example:

## MCAD/2Dshapes.scad

Example: