Constructive Solid Geometry
TOC »
Description
3D Solid modeling using combining and transforming primite shapes. The solids can be exported as stl files.
The source code is hosted on https://codeberg.org/her01n/constructive-solid-geometry.
Example
(import constructive-solid-geometry) (export-stl "example.stl" (difference (box 5 4 1) (translate (vector 5 0 0) (cylinder 2 1))))
Reference
All identifiers are imported from constructive-solid-geometry module.
(import constructive-solid-geometry)Points and vectors in 3D space are represented as standard vector, with three elements for x, y, z coordinates.
Primitives
- box width length heightprocedure
An orthogonal cuboid with one corner at origin and the other at [width, length, height] coordinates.
- box u vprocedure
An orthogonal cuboid with one corner at u and the other at v.
- box? valueprocedure
True if value is a box.
- width boxprocedure
- box-length boxprocedure
- height boxprocedure
Returns the parameters of the box. box-length is chosen to not conflict with base scheme function length.
- cylinder radius heightprocedure
Constructs a cylinder primitive. The cylinder extends in z-axis direction, with the base center at origin, and the other base center at [0, 0, height].
- cylinder? valueprocedure
True if the value is a cylinder.
- radius cylinderprocedure
- height cylinderprocedure
Returns the parameters of the cylinder primitive.
- sphere radiusprocedure
Returns a sphere solid with the center at origin and the given radius.
- sphere? valueprocedure
True, if the value is a sphere.
- radius sphereprocedure
Return the sphere's radius.
- cone bottom-radius top-radius heightprocedure
Construct a truncated cone - a frustum. One base is at z = 0 plane with the center at the origin and radius bottom-radius. Cone extends for height in positive z direction, ending with the other base with top-radius. One of bottom-radius or top-radius may be zero. When equal, the shape is identical to cylinder.
- cone? valueprocedure
Checks if the value is cone.
- bottom-radius coneprocedure
- top-radius coneprocedure
- height coneprocedure
Extracts the cone's parameters.
Transformations
- rotate axis angle childprocedure
Rotate the child around the axis. The axis is specified as a vector of three coordinates, the amplitude of the vector is ignored. Angle is expressed in radians.
- rotate? valueprocedure
True if the value is a rotation transformation.
- axis rotationprocedure
- angle rotationprocedure
- child rotationprocedure
Access rotation parameters.
- translate translation childprocedure
Move the child in the coordinate system. translation is a vector of three numbers.
- translate? valueprocedure
Check if the value is translation transformation.
- translation translateprocedure
- child translateprocedure
Get the parameters of translation transformation.
Operations
- union child ...procedure
Merge children. This is a boolean or operation.
- union? valueprocedure
True if the value is an union operation.
- children unionprocedure
Returns the children of the union.
- difference upper lowerprocedure
Subtract lower solid from upper solid. Returns a part of upper that is not part of lower.
- difference? valueprocedure
Checks if value is a difference operation.
- upper differenceprocedure
- lower differenceprocedure
Get the operands of the difference operation.
- intersection child ...procedure
Construct an intersection of all the children. This is a boolean and operation.
- intersection? valueprocedure
Checks if the value is an intersection operation.
- children intersectionprocedure
Returns the children of the intersection.
Export
- export-stl filename solidprocedure
Calculates the triangular surface mesh, and writes it in STL format to a file.
Other
- solid? valueprocedure
Returns true if the value is a solid: either primitive, transformation or operation.
- inside? point solidprocedure
Returns true if the point is inside a solid. If it point lies on the surface of the solid, the return value is unspecified.
Author
Michal Herko
License
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. A full copy of the GPL license can be found at <http://www.gnu.org/licenses/>.