Skip to main content

A Python library for exact 3D geometric modeling using CGAL

Project description

CGAL PyCAD

Build Status License Python

CGAL PyCAD is a Python library for exact 3D geometric modeling, built on top of the powerful CGAL library. It provides a simple, OpenSCAD-like Domain Specific Language (DSL) for creating constructively solid geometry (CSG) without the floating-point errors common in other CAD tools.

Features

  • Exact Arithmetic: All coordinates are handled as exact rational numbers (CGAL::Gmpq), ensuring zero precision loss during booleans and transformations.
  • Robust Backend: Powered by CGAL's Nef_polyhedron_3, guaranteeing valid, closed 3D solids.
  • Pythonic wrappers: Simple, functional API inspired by OpenSCAD.
  • No Floating Point: The API strictly accepts integers, fractions.Fraction, or rational strings/tuples. Floats are explicitly forbidden to prevent accidental precision loss.
  • Export: Generates standard STL and OFF files for 3D printing and visualization.

Installation

Prerequisites

You must have CGAL and a C++ compiler installed on your system.

Ubuntu/Debian:

sudo apt update
sudo apt install libcgal-dev g++ cmake

From PyPI (Coming soon)

pip install cgal_pycad

From Source

git clone https://github.com/ctrichet/cgal_pycad.git
cd cgal_pycad
pip install .

Usage

from cgal_pycad import cube, translate, scale
from fractions import Fraction

# Create a base block (100 x 200 x 2)
base = cube([100, 200, 2])

# Create a slot
slot = cube([10, 3, 4])

# Subtract slot from base multiple times
for i in range(5):
    # exact translation
    t_vec = [20*i, -1, -1]
    base = base - translate(t_vec)(slot)

# Scale (anisotropic)
result = base.scale([1, 1, Fraction(1, 2)])

# Export
result.to_stl("output.stl")

Contributing

Contributions are welcome!

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/amazing-feature).
  3. Commit your changes.
  4. Push to the branch.
  5. Open a Pull Request.

Development Setup

# Create venv
python3 -m venv venv
source venv/bin/activate

# Install build deps
pip install scikit-build cmake ninja pybind11

# Build and install in editable mode
pip install -e .

License

Distributed under the MIT License. See LICENSE for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cgal_pycad-0.1.0.tar.gz (712.1 kB view details)

Uploaded Source

File details

Details for the file cgal_pycad-0.1.0.tar.gz.

File metadata

  • Download URL: cgal_pycad-0.1.0.tar.gz
  • Upload date:
  • Size: 712.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for cgal_pycad-0.1.0.tar.gz
Algorithm Hash digest
SHA256 56e56bafd76601cb9c0655c14e7bde5db759f5a78929bd0b424b9e424ead589e
MD5 81c7821b03fe4b28fca50d5ed2a2e0f4
BLAKE2b-256 7f36feb54bcf62ec2313fbe688ee3f1026242e3989fbaf5c016b4ef4142e4fd7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page