Overview

Reincarnate facilitates conversions between three different representations of objects. The first, and highest, level is Lambda CAD. This is a functional language that adds utility and abstraction on top of the CAD representation. Lambda CAD evaluates to CAD, which represents the object using trees of binary operators, and the unit and empty sets. The final level is an ordered set of n-simplex faces, which define the boundary of the object. This representation is equivalent to many other currently existing mesh formats, such as STL, when done in 3D. Reincarnate has two main capacities: it can compile downwards, from Lambda CAD to CAD to mesh, or it can synthesize upwards, but only from mesh to CAD. The documentation will describe the specifics of how to write programs in each representation. If you get confused at any point, head over to the examples to see how this translates into real programs.


λ CAD

Lambda CAD is an ml-like functional programming language that includes a standard library of CAD functions, and a bit of special syntax. Every program starts with an expression, which when evaluated gives the final CAD object. After this expression, adding a where allows you to define your own function to use in the base expression. With the syntax out of the way, here is a description of the standard library.

CAD Functions

Hull

hull cad takes a CAD and returns its convex hull.

Bounding Box

bbox cad returns a pair of points ((x1, y1, z1), (x2, y2, z2)). The first point is the corner of the bounding box of cad closest to the origin. The second point is the corner furthest from the origin.

Translate

trans v cad translates the CAD over by the vector.

Home

home v cad translates the CAD so that the point v * dv away from the bottom left of the bbox lies at the origin, where dv is the vector of dimensions of the bounding box and * represents element-wise multiplication.

Scale

scale v cad scales every point in the CAD in each dimension by the corresponding element in vector v. scale a cad scales every point in the CAD uniformly by some scalar a.

scale_rel v cad scales cad about the center of its bounding box.

Union

union cadA cadB takes two CADs and returns one CAD which represents the union of their sets.

Difference

diff cadA cadB takes two CADs and returns the CAD which represents the set of points in cadA that are not in cadB.

Intersection

inter cadA cadB takes two CADs and returns the CAD which represents the set of points in both cadA and cadB.

Rotate

rotate deg cad rotates a 2D CAD by deg degrees counterclockwise around the origin. rotateX deg cad rotates a 3D CAD by deg degrees counterclockwise around the x axis. rotateY deg cad rotates a 3D CAD by deg degrees counterclockwise around the y axis. rotateZ deg cad rotates a 3D CAD by deg degrees counterclockwise around the z axis.

rotateX_rel v cad, rotateY_rel v cad, and rotateZ_rel cad rotate cad about the center of its bounding box along the given axis.

Fit

fit v cad scales cad so that its bounding box has dimensions v. fit_rel v cad fits cad about the center of its bounding box.

Extrude

extrude h cad extrudes cad into the next heigher dimension, from 0 to height h.

Utility Functions

Math

Basic Operations

add a b, sub a b, mul a b, and div a b adds, subtracts, multiplies, and divides a by b respectively. neg a returns -a. rem a b returns a modulo b. sqrt a returns the square root of a.

Trigonometry

sin r, cos r, and tan r return the sin, cos, and tangent respectively of the angle r in radians. sin_d deg, cos_d deg, and tan_d deg return the sin, cos, and tangent respectively of the angle deg in degrees. rad_of_deg deg converts the angle deg in degrees to radians. deg_of_rad r converts the angle r in radians to degrees. pi represents the numerical constant pi.

List

map_circ f n returns a list of the function f applied to n equally spaced angles in degrees covering the unit circle, starting at 0.

Base Primitives

Each primitive has an accociated dimension, which allows Lambda CAD to be dimension-independent. However, Reincarnate will throw an error if primitives from different dimensions are mixed, as this is an illegal operation!

Unit

unit1 represents the closed 1D unit interval from 0 to 1 on the number line. unit2 represents the closed 2D unit square from (0, 0) to (1, 1). unit3 represents the closed 3D unit cube from (0, 0, 0) to (1, 1, 1).

Empty

empty1 represents the empty set in 1D. empty2 represents the empty set in 2D. empty3 represents the empty set in 3D.

Derived Primitives

1D

No derived primitives are currently supported in 1D.

2D

To simpify specifications, all primitives exist only in the first quadrant (x > 0 and y > 0) with the lower left corner of the bounding box at (0, 0) and a side along the bottom of the bounding box (referred to as the base) at the x axis. Height refers to the vertical height of the bounding box.

Right Triangle

For all right triangles, the right angle is at the origin, one leg is on the x axis, and one leg is on the y axis. tri_rt a b returns a right triangle with a base a and height b. tri_rt_hyp a hyp returns a right triangle with a base a and a hypotenuse hyp. tri_rt_deg a deg returns a right triangle with base a, and an angle at the origin of deg. tri_rt_hyp_deg hyp deg returns a right triangle with hypotenuse hyp and an angle at the origin of deg.

Equilateral Triangle

tri_eq s returns an equilateral triangle with side length s.

Isosceles Triangle

tri_iso b s returns an isosceles triangle with base b and slant side length s. tri_iso_h b h returns an isosceles triangle with base b and height h. tri_iso_b_deg b deg returns an isosceles triangle with base b and an angle at the origin of deg. tri_iso_s_deg s deg returns an isosceles triangle with slant side length s and an angle at the origin of deg. tri_iso_h_deg h deg returns an isosceles triangle with height h and an angle at the origin of deg.

Triangle

tri a b c returns a triangle with base c, a left slant side length of a, and a right slant side length of b.

Parallelogram

paragram a b deg returns a parallelogram with base b, slant side length a and an acute angle at the origin of deg. paragram_h a b h returns a parallelogram with base b, slant side length a, and height h.

Right Trapezoid

trap_rt blo bhi h returns a right trapezoid with bottom base length blo, top base length bhi, and height h.

Isosceles Trapezoid

trap_iso a b deg returns an isosceles trapezoid with side length a, bottom base b, and angle deg between a and b at the origin. trap_iso_lo a b h returns an isosceles trapezoid with side length a, bottom base b, and height h. trap_iso_hi a b h returns an isosceles trapezoid with side length a, top base b, and height h. trap_iso_bs blo bhi h returns an isosceles trapezoid with bottom base blo, top base bhi, and height h.

Regular polygons

pgon_reg n s returns an n-sided regular polygon with side length s. pgon_reg_r n r returns an n-sided regular polygon with circumradius r.

Circle

circle n returns a 4n-sided regular polygon approximation to the unit circle.

3D

Cylinder

cylinder r h n returns a cylinder with a base radius of r, a height of h, and 4*n sides.

Tetrahedron

tetrahedron returns a tetrahedron with the base in the unit square on the xy plane.

Prism

prism r h n returns a right prism with base radius r, height h, and number of sides n.

Pyramid

pyramid r h n returns a right pyramid with base radius r, height h, and number of sides n.

Sphere

sphere r n returns a sphere of radius r, with n vertical and horizontal subdivisions.

Example

inter
  unit2
  trans (0.5, 0) unit2

This produces the rectangle from (0.5, 0) to (1, 1). For more in-depth λ CAD examples see the examples page.


CAD

CAD supports many of the same operations as Lambda CAD, but without the functional programming syntax. CADs are laid out as trees of operations. At the beginning of every CAD program is a dimensional specification, CAD1, CAD2, or CAD3 for 1D, 2D, or 3D. Then, there is a sequence of nested operations, and at the bottom of the tree there are primitives.

Operators

Operators have two types of input, CADs and vectors/scalars. For instance, Union { cadA cadB } applies the Union operation to the contained CADs, while Scale (2, 1) { cad } applies the Scale operation, with both the vector (2, 1) and the CAD as inputs.

Hull

Hull { cad } returns the convex hull of the CAD.

Translate

Trans (v) { cad } returns the translation of the CAD over by vector v.

Home

Home (v) { cad } translates the CAD so that the point v * dv away from the bottom left of the bbox lies at the origin, where dv is the vector of dimensions of the bounding box and * represents element-wise multiplication.

Scale

Scale (v) { cad } returns the scaled up version of the CAD in each dimension by the corresponding element in vector v.

Union

Union { cadA cadB } returns the CAD representing the set of points in either cadA or cadB.

Difference

Diff { cadA cadB } returns the CAD representing the set of points in cadA but not in cadB.

Intersection

Inter { cadA cadB } returns the CAD representing the set of points in both cadA and cadB.

Rotate

Rotate (deg) { cad } rotates a 2D CAD by deg degrees counterclockwise around the origin. rotateX (deg) { cad } rotates a 3D CAD by deg degrees counterclockwise around the x axis. rotateY (deg) { cad } rotates a 3D CAD by deg degrees counterclockwise around the y axis. rotateZ (deg) { cad } rotates a 3D CAD by deg degrees counterclockwise around the z axis.

Fit

Fit (v) { cad } scales cad so that its bounding box has dimensions v.

Primitives

Unit

Unit represents the unit inverval [0, 1] in 1D, the unit rectangle from (0, 0) to (1, 1) in 2D, and the unit cube from (0, 0, 0) to (1, 1, 1) in 3D.

Empty

Empty represents the empty set.

Example

Inter {
  Unit
  Trans (0.5, 0) {
    Unit2
  }
}

This produces the rectangle from (0.5, 0) to (1, 1).


Mesh

Each mesh is a set of faces, in the format [face1; face2; face3...; facen]. The collection of faces forms the boundary of the set representing the object.

1D

In 1D, the faces take the form of numbers, and must be sorted in ascending order. For example, [0; 1] is the unit interval [0, 1] as a mesh.

2D

In 2D, the faces are line segments, represented by the two endpoints. For example, ((0, 0), (0, 1)) is the left face of the unit square in 2D.

3D

In 3D, the faces are triangles, represented by the three vertices. For examples, ((0, 0, 0), (0, 1, 0), (0, 0, 1)) is half of the intersection of the boundary of the unit cube with the yz plane.

Example

[((0.5, 0), (0.5, 1)); ((0.5, 1), (1, 1)); ((1, 1), (1, 0)); ((1, 0), (0, 0))]

This produces the rectangle from (0.5, 0) to (1, 1).