📏 cad3d - 3D CAD Modeling
CSG, Extrude, Revolve, Loft, Boolean Operations
79
function
1,023
lines
32 KB
Boyut
🚀 Quick Start
import cad3d
// CSG (Constructive Solid Geometry)
let box = cad3d.box([0.0, 0.0, 0.0], [2.0, 2.0, 2.0])
let sphere = cad3d.sphere([1.0, 1.0, 1.0], 1.5)
// Boolean operations
let union = cad3d.union(box, sphere)
let intersection = cad3d.intersection(box, sphere)
let difference = cad3d.difference(box, sphere)
// Extrude (2D profile -> 3D solid)
let profile = cad3d.circle(1.0, 32)
let cylinder = cad3d.extrude(profile, 5.0)
// Revolve (rotate profile around axis)
let vase = cad3d.revolve(profile, [0.0, 1.0, 0.0], 360.0)
// Export
cad3d.export_step(union, "part.step")
📚 CAD Operations
- Primitives: box, sphere, cylinder, cone, torus
- Boolean: union, intersection, difference
- Transforms: translate, rotate, scale, mirror
- Modeling: extrude, revolve, loft, sweep
- Export: STEP, IGES, STL
💡 Exampleler
Mechanical Part (Bolt)
import cad3d, math
function bolt_create(uzunluk: float, çap: float) -> Solid do
// Shaft
let shaft = cad3d.cylinder([0.0, 0.0, 0.0], çap/2.0, uzunluk)
// Head (hexagon)
let head_profile = []
each i in aralık(0, 6) for do
let angle = i.float() * math.PI / 3.0
let x = math.cos(angle) * çap
let y = math.sin(angle) * çap
head_profile.ekle([x, y])
end
let head = cad3d.extrude(head_profile, çap * 0.7)
cad3d.translate(head, [0.0, 0.0, uzunluk])
// Thread (simplified)
let thread_depth = çap * 0.1
let helix = cad3d.helix([0.0, 0.0, 0.0], çap/2.0 - thread_depth, uzunluk, 2.0)
// Combine
let bolt = cad3d.union(shaft, head)
bolt = cad3d.difference(bolt, helix)
return bolt
end
let m8_bolt = bolt_create(50.0, 8.0)
cad3d.export_step(m8_bolt, "m8_bolt.step")
Parametric Gear
import cad3d, math
function gear_create(teeth: tamsayı, module: float, thickness: float) -> Solid do
let pitch_radius = module * teeth.float() / 2.0
let base_circle = cad3d.circle(pitch_radius, teeth * 4)
// Tooth profile (involute curve - simplified)
let tooth_angle = 2.0 * math.PI / teeth.float()
let gear_profile = []
each i in aralık(0, teeth) for do
let angle = i.float() * tooth_angle
// Tooth tip
let tip_r = pitch_radius * 1.1
let tip_x = math.cos(angle) * tip_r
let tip_y = math.sin(angle) * tip_r
gear_profile.ekle([tip_x, tip_y])
// Tooth root
let root_angle = angle + tooth_angle * 0.5
let root_r = pitch_radius * 0.9
let root_x = math.cos(root_angle) * root_r
let root_y = math.sin(root_angle) * root_r
gear_profile.ekle([root_x, root_y])
end
let gear = cad3d.extrude(gear_profile, thickness)
// Center hole
let hole = cad3d.cylinder([0.0, 0.0, 0.0], pitch_radius * 0.3, thickness)
gear = cad3d.difference(gear, hole)
return gear
end
let gear = gear_create(24, 2.0, 10.0)
cad3d.export_step(gear, "gear.step")