-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclipper_test.py
More file actions
136 lines (128 loc) · 5.45 KB
/
clipper_test.py
File metadata and controls
136 lines (128 loc) · 5.45 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# Ruiqi Chen
# July 3, 2020
'''
Test polygon insetting.
'''
import os
import unittest
import matplotlib.pyplot as plt
import numpy as np
import clipper
from visualization import plot_polygon
class TestClipper(unittest.TestCase):
def DISABLED_test_inset(self):
dumbbell = np.array([
[3, 3],
[3, -3],
[0.5, -3],
[0.5, -0.5],
[-0.5, -0.5],
[-0.5, -3],
[-3, -3],
[-3, 3],
[-0.5, 3],
[-0.5, 0.5],
[0.5, 0.5],
[0.5, 3]
])
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_aspect('equal')
plot_polygon(dumbbell, ax)
insets = [0.2, 0.5, 1, 1.5]
num_solutions = [1, 2, 2, 0]
for inset_amount, num_sol in zip(insets, num_solutions):
solution = clipper.inset_polygon(dumbbell, inset_amount)
self.assertEqual(len(solution), num_sol)
for sol in solution:
plot_polygon(np.array(sol), ax)
plt.show()
def test_hole_in_plate(self):
directory = r'D:\OneDrive - Leland Stanford Junior University\Research\Projects\Aligned Infills\Code\alignedinfill\hole_in_plate'
streamline0 = np.load(os.path.join(directory, 'streamline0.npy'))
streamline1 = np.load(os.path.join(directory, 'streamline1.npy'))
# Region 0: top half
region0 = np.zeros((streamline0.shape[0] + 4, 3))
region0[0:-4] = streamline0
region0[-4:] = np.array([[-3.5, 0.10338015, 0],
[-3.5, 2.5, 0],
[3.5, 2.5, 0],
[3.5, 0.10338015, 0]])
# Region 1: bottom half
region1 = np.zeros((streamline1.shape[0] + 4, 3))
region1[0:-4] = streamline1
region1[-4:] = np.array([[-3.5, -0.10338015, 0],
[-3.5, -2.5, 0],
[3.5, -2.5, 0],
[3.5, -0.10338015, 0]])
# Region 2: left half
kNumPtsFromStreamlineToInclude = 145 # this is a user parameter to achieve conformal boundary
kNumPtsInArc = 50
region2 = np.zeros((2 * kNumPtsFromStreamlineToInclude + kNumPtsInArc + 2, 3))
region2[0] = np.array([-3.5, -0.10338015, 0])
region2[1:kNumPtsFromStreamlineToInclude+1] = streamline1[-1:-(kNumPtsFromStreamlineToInclude+1):-1]
arc2 = np.zeros((kNumPtsInArc, 3))
theta = np.linspace(220*np.pi/180, 140*np.pi/180, kNumPtsInArc)
arc2[:, 0] = 1.02*np.cos(theta)
arc2[:, 1] = 1.02*np.sin(theta)
region2[kNumPtsFromStreamlineToInclude+1:kNumPtsFromStreamlineToInclude+kNumPtsInArc+1] = arc2
region2[kNumPtsFromStreamlineToInclude+kNumPtsInArc+1:-1] = streamline0[-kNumPtsFromStreamlineToInclude::1]
region2[-1] = np.array([-3.5, 0.10338015, 0])
# Region 3: right half
region3 = np.zeros_like(region2)
region3[0] = np.array([3.5, -0.10338015, 0])
region3[1:kNumPtsFromStreamlineToInclude+1] = streamline1[:kNumPtsFromStreamlineToInclude]
arc3 = np.zeros((kNumPtsInArc, 3))
theta = np.linspace(-40*np.pi/180, 40*np.pi/180, kNumPtsInArc)
arc3[:, 0] = 1.02*np.cos(theta)
arc3[:, 1] = 1.02*np.sin(theta)
region3[kNumPtsFromStreamlineToInclude+1:kNumPtsFromStreamlineToInclude+kNumPtsInArc+1] = arc3
region3[kNumPtsFromStreamlineToInclude+kNumPtsInArc+1:-1] = streamline0[kNumPtsFromStreamlineToInclude-1::-1]
region3[-1] = np.array([3.5, 0.10338015, 0])
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_aspect('equal')
plot_polygon(region0, ax)
plot_polygon(region1, ax)
plot_polygon(region2, ax)
plot_polygon(region3, ax)
np.save(os.path.join(directory, 'region0.npy'), region0)
np.save(os.path.join(directory, 'region1.npy'), region1)
np.save(os.path.join(directory, 'region2.npy'), region2)
np.save(os.path.join(directory, 'region3.npy'), region3)
# plt.show()
insets = np.arange(0.25, 2, 0.25)
# nozzle_diam_inch = 0.019685
# insets = np.arange(nozzle_diam_inch/2, 2, nozzle_diam_inch)
counter = 0
for inset in insets:
for region in [region0, region1, region2, region3]:
solution = clipper.inset_polygon(region, inset)
for sol in solution:
plot_polygon(np.array(sol), ax)
out_path = os.path.join(directory, 'polygons', '{}.npy'.format(counter))
# np.save(out_path, np.array(sol))
counter += 1
plt.show()
def DISABLED_test_simply_supported_beam(self):
region = np.array([[0, 0, 0],
[-0.25, 0, 0],
[-0.25, 5, 0],
[-30, 5, 0],
[-30, -5, 0],
[30, -5, 0],
[30, 5, 0],
[0.25, 5, 0],
[0.25, 0, 0]])
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_aspect('equal')
plot_polygon(region, ax)
insets = np.arange(0.25, 2, 0.25)
for inset in insets:
solution = clipper.inset_polygon(region, inset)
for sol in solution:
plot_polygon(np.array(sol), ax)
plt.show()
if __name__ == '__main__':
unittest.main()