# Learning Implicitcad

# Reference

## Constants

Units in ImplicitCAD are in millimeters.

- pi

## Language Elements

### Comments

Comments are C style, or C++ style.

### for

the trivial program:

// Example8.escad -- variable assignment in loops. a = 5; for (c = [1, 2, 3]) { echo(c); a = a*c; echo(a); }

Has the output:

1.0 5.0 2.0 10.0 3.0 30.0

A C-like syntax uses colons:

// Example8.escad -- variable assignment in loops. a = 5; for (c = [1: 1: 3]) { echo(c); a = a*c; echo(a); }

### if

Example:

if (holes>0) { circle(5) }

### echo

### module

### include

uses less than and greater than C style, only without the concept of a system library. always relative paths to current object.

include <otherfile.escad>

## Functions

### 3D

#### sphere

Examples:

sphere(3); sphere(r=5);

Arguments:

- r -- radius of the sphere

#### cube

Examples:

cube(size = [2,3,4], center = true, r = 0.5); cube(4);

Arguments:

- size -- cube size
- center = False -- should center?
- r = 0.0 -- radius of rounding

### cylinder

Examples:

cylinder(r=10, h=30, center=true); cylinder(r1=4, r2=6, h=10); cylinder(r=5, h=10, $fn = 6);

Arguments:

- r = 1.0 -- radius of cylinder
- h = 1.0 -- height of cylinder
- r1 = 1.0 -- bottom radius; overrides r
- r2 = 1.0 -- top radius; overrides r
- $fn = -1.0 -- number of sides, for making prisms
- center = False -- center cylinder with respect to z?

### 2D

#### square

Examples:

square(size = [3,4], center = true, r = 0.5); square(4);

Arguments:

- size -- square size
- center = False -- should center?
- r = 0.0 -- radius of rounding

### circle

Examples:

circle(r=10); // circle circle(r=5, $fn=6); //hexagon

Arguments:

- r -- radius of the circle
- $fn = -1.0 -- if defined, makes a regular polygon with n sides instead of a circle

### polygon

Examples:

polygon ([(0,0), (0,10), (10,0)]);

Arguments:

- points -- vertices of the polygon
- paths = [] -- order to go through vertices; ignored for now
- r = 0.0 -- rounding of the polygon corners; ignored for now

### Functional

#### union

creates an object consisting of all of the objects passed to it overlapped.

Arguments:

- r = 0.0 -- Radius of rounding for the union interface.

#### difference

creates an object consisting of the first object passed to it, missing any spaces where it overlaps with any of the following objects.

Arguments:

- r = 0.0 -- Radius of rounding for the difference interface.

#### intersection

creates an object consisting of the spaces the two passed in objects both occupy.

Arguments:

- r = 0.0 -- Radius of rounding for the intersection interface.

#### translate

Examples:

translate ([2,3]) circle (4); translate ([5,6,7]) sphere(5);

Arguments:

- v -- vector to translate by

#### scale

Examples:

scale(2) square(5); scale([2,3]) square(5); scale([2,3,4]) cube(5);

Arguments:

- v -- vector or scalar to scale by

#### rotate

Arguments:

- a -- value to rotate by; angle or array of angles

Examples:

rotate(45) square(5); rotate([45,45,45]) cube(5);

#### linear_extrude

Examples:

linear_extrude(10) square(5);

Arguments:

- height = 1.0 -- height to extrude to...
- center = False -- center? (the z component)
- twist = Undefined -- twist as we extrude, either a total amount to twist or a function...
- scale = Undefined -- scale according to this function as we extrud...
- translate = Undefined -- translate according to this function as we extrude...
- r = 0.0 -- round the top?

#### pack

Examples:

pack ([45,45], sep=2) { circle(10); circle(10); circle(10); circle(10); }

Arguments:

- size -- size of 2D box to pack objects within
- sep -- required space between objects

#### shell

Arguments:

- w -- width of the shell...

#### rotate_extrude

Examples:

rotate_extrude() translate(20) circle(10);

Arguments:

- a = 360.0 -- angle to sweep
- r = 0.0
- translate = [0.0,0.0]

#### unit

# Bugs

disc4: scale(2) is equivalent to scale([2,1,1]), not scale([2,2,2]). disc6: md5sum mismatch? gear: for() working wrong? track: ((2*pi)/19) is a proper paremeter in a module call, but ((2*pi)/(19)) is not? track: no modulo (%) operator? (fixed in uncommitted code) track: variable not in scope only warns in an if conditional?

# Wishlist

- Better error reporting.
- variables passed to basic primitives that those primitives do not touch.
- semicolons missing.
- variables referenced that do not exist.
- functions called with missing/not enough arguments.

- Less memory consumption.
- threading.
- verbose modes.