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.
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