Skip to content

almargolis/cadlib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages