summaryrefslogtreecommitdiff
path: root/docs/csg.py
blob: 05d875458df3cf05f7bd0fc9a55814255002a2cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python
#filename: csg.py
#author: Bryan Bishop <kanzure@gmail.com>
#url: http://heybryan.org/
#date: 2010-02-15
#description: trying to figure out how to do pythonic CSG (constructive solid geometry) CAD

sphere = Sphere(position=(0, 0, 0), radius="5 mm")
base = Circle(diameter="20 mm", position=(0,0,0))
cylinder = base.extrude(length="10 mm", direction=Vector(0, 0, 1))
sphere.position = (0, 0, 10)
lamp_post = cylinder.fuse(sphere)

#if you're in an X11 opengl session thingy:
display.add(lamp_post)

#or if you want to export it:
iges_data = lamp_post.to_iges()
file_handler = open("lamp_post.iges", "w")
file_handler.write(iges_data)
file_handler.close()

#############################

base = Circle(diameter="20 mm")
base_plate = Extrusion(base, "10mm", Vector(0,0,1))
#OR: base_plate = base.extrude("10 mm", Vector(0, 0, 1))
#OR: base_plate = extrude(base, "10 mm", Vector(0, 0, 1))

assert base_plate == Cylinder(diameter="20 mm", height="10 mm"), "Cylinder and base plate should be exactly the same"

base_plate.diameter = "25 mm"
assert base.diameter == "25 mm", "base diameter should have been updated"

base.diameter = "32 mm"
assert base_plate.diameter == "32 mm", "base plate diameter should have been updated"