forked from phoopies/DesignOptimizationCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtentExample.py
More file actions
70 lines (50 loc) · 2 KB
/
tentExample.py
File metadata and controls
70 lines (50 loc) · 2 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from modules.GeometryDesign.tent import Tent
import numpy as np
def run_example():
# Pyramid example
print("Making a pyramid")
# Define the points first
pyramid_points = np.array([
[0,0,0], [1,0,0], [0,1,0], [1,1,0], # floor corners
[.5, .5, 1] # pyramidion / capstone
])
# Instansiate the object
pyramid = Tent(pyramid_points)
# Print some information about the pyramid
print(f"Pyramid\n{'-'*50}\nFloor area: {pyramid.floor_area}\nSurface area: {pyramid.surface_area}\nVolume: {pyramid.volume}\n\n")
# Plot the pyramid
pyramid.plot()
# Box example:
print(f"{'-'*50}\nMaking a box")
# Define the points
box_points = np.array([
[0,0,0], [1,0,0], [0,1,0], [1,1,0], # floor corners
[0,0,1], [1,0,1], [0,1,1], [1,1,1] # Ceiling/roof corners
])
# Instansiate the object
box = Tent(box_points)
# Print the volume
print(f"Box volume: {box.volume}\n\n")
# Plot the box
box.plot()
# Caveats
# Caveat 1
# as the furthermost points (x, y axis) are projected down to z = 0
# defining a box with floor points higher z = 0 will results in the same box
# with floor defined to z = 0
box_points2 = np.array([
[0,0,.5], [1,0,.5], [0,1,.5], [1,1,.5], # floor corners at z = 0.5
[0,0,1], [1,0,1], [0,1,1], [1,1,1]
])
box2 = Tent(box_points2)
# compare
print("comparing two boxes with different point clouds")
print(f"Volume is {'same' if box2.volume == box.volume else 'not same'}")
print(f"Surface area is {'same' if box2.surface_area == box.surface_area else 'not same'}\n\n")
# Caveat 2
# If qhull fails to construct the convexhull the points will be given an offset and
# after that we try again (max 10 times).
offset_points = np.array([[.5, .5, .5]] * 10) # 10 points all at (.5, .5, .5)
print("Constructing a tent with bad points:\n")
t = Tent(offset_points)
run_example() # You can comment this line out and do your own things