Skip to main content

CAD primitives to produce images and drawings in a variety of formats from a common symbolic definition.

Project description

cadlib

CAD primitives to produce images and drawings in a variety of formats from a common symbolic definition.

cadlib is a 2D CAD geometry library written in Python. It models manual drafting workflows: constructing geometry by creating points, lines, circles, and arcs, then using transformations (mirror, rotate) to build complex shapes.

Installation

pip install cadlib

Quick Start

import cadlib

# Create geometry
center = cadlib.Point(0, 0)
circle = cadlib.Circle(center, 10)
line = cadlib.Line(cadlib.Point(-15, 5), cadlib.Point(15, 5))

# Find intersections
pt = circle.point_at_line_intersection(line, q=1)

# Use transformations
mirrored = line.mirror_x(0)
rotated = line.rotate(center, 45)

Sprocket Generation

cadlib includes a sprocket generator implementing ANSI standard sprocket geometry per the gearseds design specification.

# Generate SVG
cadlib-sprocket svg

# Display with matplotlib
cadlib-sprocket matplotlib

Or use it programmatically:

from cadlib.sprocket import Sprocket, create_svg, create_matplotlib

sprocket = Sprocket(ansi_chain_type="25", n_number_of_teeth=8)
create_svg(sprocket)

Core API

Primitives

  • Point(x, y) -- 2D point with mirror and rotate transformations
  • Line(p1, p2) -- line segment between two points
  • Circle(center, radius) -- circle with intersection and tangency methods
  • Arc(center, radius, angle1, angle2) -- arc defined by center, radius, and angle range

Factory Functions

  • arc_from_points_and_radius(p1, p2, r, q) -- arc from two points and radius
  • arc_from_points_and_center(p1, p2, center) -- arc from two points and center
  • arc_from_points_and_radius_and_height(p1, p2, height) -- arc from chord and height
  • line_from_pt_angle_len(point, angle, length) -- line from point, angle, length

Layers and Drawing

  • Layer -- groups elements for rendering control
  • Drawing -- collection of elements with coordinate transforms for output
  • LAYER_CONSTRUCTION -- default layer for construction guides (gray)
  • LAYER_TOOLPATH -- layer for cutting/tool paths (red)

License

MIT

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

cadlib-0.1.0.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cadlib-0.1.0-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for cadlib-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7842d2566fc7537f117989fcf3f5ddb188e5256a6745aa4e58830a6f249054bc
MD5 8905d2ce6b876eedce482f4e84888439
BLAKE2b-256 a580d7b20a1873b68cd920b60bbc7f5a196dc267ec7b667ff96c5ebfd888d9ef

See more details on using hashes here.

File details

Details for the file cadlib-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cadlib-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for cadlib-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e24099f10aa8b663c1f9cd0fcde48a90c8843366cd269b492a362d2103f5ae6b
MD5 afe73fb3280aa8ca02e7e3bc63f72509
BLAKE2b-256 12f42a2cc307bc176c1439c0c12279d88c9bc74e59eba5932b486bea22dbf4a6

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