# SolidModeling.jl

**Constructive Solid Geometry (CSG)** is a solid modeling technique that uses boolean operations like union and intersection to combine 3D solids. This library implements CSG operations on using BSP trees.

It's ported from the excellent javascript library csg.js with some added features (like volume calculation).

## Installation

You can install this package using the following Julia command:

`Pkg.add("SolidModeling")`

The package can then be loaded and used in a Julia script or a Jupyter Notebook by:

`using SolidModeling`

## Usage

You can perform 3 basic operations on two solids - `intersection`

, `subtraction`

and `union`

.

### Union of two cubes

```
# 1x1x1 cube with center point in [0.5, 0.5, 0.5]
c1 = cube(0.0, 0.0, 0.0, 1.0, 1.0, 1.0)
# 1.5x1.5x1.5 cube with center point in [1.25, 1.25, 1.25]
c2 = cube(0.5, 0.5, 0.5, 2.0, 2.0, 2.0)
# calculate union of the two cubes
c = bunion(c1, c2)
# calculate volume of the union if needed
vol = volume(c)
```

### Intersection of two cubes

```
# calculate intersection of the two cubes from above
c = bintersect(c1, c2)
# calculate volume of the union if needed
vol = volume(c)
```

### Subtraction of two cubes

```
# calculate subtraction of the two cubes from above (c1-c2)
c = bsubtract(c1, c2)
# calculate volume of the union if needed
vol = volume(c)
```

To see more about CSG operations, see the csg.js docs.

## Authors

**Jan Vorisek**<**jan@vorisek.me**>

Original javascript code written by:

## License

This project is licensed under the MIT License.