AST

The abstract syntax tree provides different shape types and transformations that can be nested. They’re largely inspired by OpenSCAD.

2D Shapes

class tangible.ast.Circle(radius)[source]

A circle 2D shape.

Parameters:radius (int or float) – The radius of the circle.
Raises:ValueError if validation fails.
class tangible.ast.CircleSector(radius, angle)[source]

A circle sector (pizza slice).

Parameters:
  • radius (int or float) – The radius of the circle.
  • angle (int or float) – The central angle in degrees.
Raises:

ValueError if validation fails.

class tangible.ast.Rectangle(width, height)[source]

A rectangle 2D shape.

Parameters:
  • width (int or float) – Width of the rectangle.
  • height (int or float) – Height of the rectangle.
Raises:

ValueError if validation fails.

class tangible.ast.Polygon(points)[source]

A polygon 2D shape.

Parameters:points (list of 2-tuples) – List of coordinates. Order of points is significant. The shape must be closed, meaning that the first and the last coordinate must be the same.
Raises:ValueError if validation fails.

3D Shapes

class tangible.ast.Cube(width, height, depth)[source]

A cube 3D shape.

Parameters:
  • width (int or float) – Width of the cube.
  • height (int or float) – Height of the cube.
  • depth (int or float) – Depth of the cube.
Raises:

ValueError if validation fails.

class tangible.ast.Sphere(radius)[source]

A sphere 3D shape.

Parameters:radius (int or float) – The radius of the sphere.
Raises:ValueError if validation fails.
class tangible.ast.Cylinder(height, radius1, radius2)[source]

A cylinder 3D shape.

Parameters:
  • height (int or float) – The height of the cylinder.
  • radius1 (int or float) – The bottom radius of the cylinder.
  • radius2 (int or float) – The top radius of the cylinder.
Raises:

ValueError if validation fails.

class tangible.ast.Polyhedron(points, triangles=[], quads=[])[source]

A polyhedron 3D shape. Supports both triangles and quads. Triangles and quads can also be mixed.

Parameters:
  • points (list of 3-tuples) – List of points.
  • triangles (list of 3-tuples) – Triangles formed by a 3-tuple of point indexes (e.g. (0, 1, 3)). When looking at the triangle from outside, the points must be in clockwise order. Default: [].
  • quads (list of 4-tuples) – Rectangles formed by a 4-tuple of point indexes (e.g. (0, 1, 3, 4)). When looking at the rectangle from outside, the points must be in clockwise order. Default: [].
Raises:

ValueError if validation fails.

Transformations

class tangible.ast.Translate(x, y, z, item)[source]

A translate transformation.

Parameters:
  • x (int or float) – Translation on the X axis.
  • y (int or float) – Translation on the Y axis.
  • z (int or float) – Translation on the Z axis.
  • item (tangible.ast.AST) – An AST object.
Raises:

ValueError if validation fails

class tangible.ast.Rotate(degrees, vector, item)[source]

A rotate transformation.

Parameters:
  • degrees (int or float) – Number of degrees to rotate.
  • vector – The axes to rotate around. When a rotation is specified for multiple axes then the rotation is applied in the following order: x, y, z. As an example, a vector of [1,1,0] will cause the object to be first rotated around the x axis, and then around the y axis.
  • item (tangible.ast.AST) – An AST object.
Raises:

ValueError if validation fails

class tangible.ast.Scale(x, y, z, item)[source]

A scale transformation.

The x, y and z attributes are multiplicators of the corresponding dimensions. E.g. to double the height of an object, you’d use 1, 1, 2 as x, y and z values.

Parameters:
  • x (int or float) – X axis multiplicator.
  • y (int or float) – Y axis multiplicator.
  • z (int or float) – Z axis multiplicator.
  • item (tangible.ast.AST) – An AST object.
Raises:

ValueError if validation fails

class tangible.ast.Mirror(vector, item)[source]

A mirror transformation.

Mirror the child element on a plane through the origin.

Parameters:
  • vector (3-tuple) – Normal vector describing the plane intersecting the origin through which to mirror the object.
  • item (tangible.ast.AST) – An AST object.
Raises:

ValueError if validation fails

Boolean operations

class tangible.ast.Union(items)[source]

A union operation.

Parameters:items (list) – List of AST objects.
Raises:ValueError if validation fails
class tangible.ast.Difference(items)[source]

A difference operation.

Parameters:items (list) – List of AST objects.
Raises:ValueError if validation fails
class tangible.ast.Intersection(items)[source]

A intersection operation.

Parameters:items (list) – List of AST objects.
Raises:ValueError if validation fails

Extrusions

class tangible.ast.LinearExtrusion(height, item, twist=0)[source]

A linear extrusion along the z axis.

Parameters:
  • height (int or float) – The height of the extrusion.
  • item (tangible.ast.AST) – An AST object.
  • twist (int or float) – How many degrees to twist the object around the z axis.
class tangible.ast.RotateExtrusion(item)[source]

A rotational extrusion around the z axis.

Parameters:item (tangible.ast.AST) – An AST object.