ConstructiveGeometry.jl Documentation

This package provides tools for describing 3d objects in Julia. For example, this is the Julia code used to draw the logo of this page:

using ConstructiveGeometry
using CairoMakie
using Colors

hexagon = polygon([[cospi(t/3),sinpi(t/3)] for t in 0:5])
c1, c2, c3 = colorant"#cb3c33", colorant"#9558b2", colorant"#389826"

bolt = linear_extrude(5)*(8*hexagon) ∪ cylinder(15,4) ∪
	rotate_extrude(7*360, slide=14)*translate([1,0])*square(4,1)

m = union(c1*bolt, [20,0,0]+c2*bolt, [10,17,0]+c3*bolt)

save("logo.png", Makie.plot(m))


Drawing an object is generally done in two steps. First, an abstract, “ideal” geometric object (in either two or three dimensions) is defined using the following constructions:

Such an abstract object is stored as a tree with primitive objects as leaves:

julia> display(bolt)
├─ Prism
│  └─ AffineTransform
│     └─ ShapeMesh # 1 polygon(s), 6 vertices
├─ Prism
│  └─ Circle
└─ Revolution
   └─ AffineTransform
      └─ Square

Any geometric object defined in this way can then be instantiated as an explicit mesh. The mesh may be visualized directly within Julia (using Makie) or exported in several formats, including as an STL (for 3d objects) or SVG (for 2d objects) file.

The documentation about extending ConstructiveGeometry also contains some explanations about the internals.