-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrigidity_test.py
More file actions
176 lines (146 loc) · 5.31 KB
/
rigidity_test.py
File metadata and controls
176 lines (146 loc) · 5.31 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import math
import numpy
import numpy.testing
from rigidity import rigidity_matrix, inf_dof, is_generically_rigid
import unittest
class RigidityMatrixTest(unittest.TestCase):
def testPage50Example(self):
"""
The example from page 50 of the GFALOP e-book.
"""
config = [(0,0),(5,0),(5,5),(0,5)]
edges = [(0,1), (1,2), (2,3), (3,0)]
expected_rigiditiy_matrix = numpy.array([
[-5, 0, 5, 0, 0, 0, 0, 0],
[ 0, 0, 0, -5, 0, 5, 0, 0],
[ 0, 0, 0, 0, 5, 0, -5, 0],
[ 0, -5, 0, 0, 0, 0, 0, 5]
])
# numpy array equivalent of assertEqual
numpy.testing.assert_allclose(rigidity_matrix(config, edges),
expected_rigiditiy_matrix)
class InfinitesimalDofTest(unittest.TestCase):
"""
Partitions:
vertices: 0, 1, 2, many
edges: 0, 1, many
infinitesimal dof: 0, 1, many;
greater than actual dof?
embedding dimension d: 1, 2, many
configuration dimension k: 0, 1, 1<k<d-1, d-1, d
"""
def test1DLine(self):
# V = 2, E = 1, DOF = 0, d = 1, k = d
config = [(14.2,), (2.991,)]
edges = [(0,1)]
self.assertEqual(inf_dof(config, edges), 0)
def testEmpty(self):
# V = 0, E = 0, DOF = 0, d = ?, k = ?
self.assertEqual(inf_dof([], []), 0)
def testPoint(self):
# V = 1, E = 0, DOF = 0, d = 2, k = 0 < d-1
config = [(19, 34.1245)]
edges = []
self.assertEqual(inf_dof(config, edges), 0)
def testLine(self):
# V = 2, E = 1, DOF = 0, d = 2, k = d-1
config = [(0,0),(1,0)]
edges = [(0,1)]
self.assertEqual(inf_dof(config, edges), 0)
def testTriangle(self):
# V = many, E = many, DOF = 0, d = 2, k = d
triangle_config = [(0,0), (1,0), (0,1)]
edges = [(0,1), (1,2), (2,0)]
self.assertEqual(inf_dof(triangle_config, edges), 0)
def testSquare(self):
# V = many, E = many, DOF = 1, d = 2, k = d
square_config = [(0,0),(0,5),(5,5),(5,0)]
edges = [(0,1), (1,2), (2,3), (3,0)]
self.assertEqual(inf_dof(square_config, edges), 1)
def testDegenerateRectangle(self):
# V = many, E = many, DOF = 4 > actual, d = 3, k = 1 < d-1
degen_rect_config = [(0, 0, 5), (3, 0, 5), (4, 0, 5), (1, 0, 5)]
edges = [(0,1),(1,2),(2,3),(3,0)]
self.assertEqual(inf_dof(degen_rect_config, edges), 4)
def testTwoSquares(self):
"""
V = many, E = many, DOF = 2, d = 2, k = d
1--3--5
| | |
0--2--4
"""
two_square_config = [(0,0), (0,1), (1,0), (1,1), (2,0), (2,1)]
edges = [(0,1), (2,3), (4,5), (0,2), (2,4), (1,3), (3,5)]
self.assertEqual(inf_dof(two_square_config, edges), 2)
def testSpokes(self):
# V = many, E = many, DOF = many, d = 2, k = d
n_spokes = 50
angle = 2 * math.pi / n_spokes
spoke_config = [(0,0)] + [(math.cos(k * angle), math.sin(k * angle))
for k in range(n_spokes)]
edges = [(0, k + 1) for k in range(n_spokes)]
# minus 1 because uniform rotation is a plane isometry
self.assertEqual(inf_dof(spoke_config, edges), n_spokes - 1)
def test3DTriangle(self):
triangle_config = [(0,0,1), (1,0,1), (0,1,1)]
edges = [(0,1), (1,2), (2,0)]
self.assertEqual(inf_dof(triangle_config, edges), 0)
def test3DSquare(self):
square_config = [(0,0,100),(0,5,100),(5,5,100),(5,0,100)]
edges = [(1,2),(2,3),(3,0),(0,1)]
# extra dof because we can fold now.
self.assertEqual(inf_dof(square_config, edges), 2)
def testCube(self):
"""
2--3 6--7
| | connected to | |
0--1 4--5
There are 6 dof.
"""
cube_config = [(0,0,0),(1,0,0),
(0,1,0),(1,1,0),
(0,0,1),(1,0,1),
(0,1,1),(1,1,1)]
edges = [(0,1),(1,3),(3,2),(2,0),
(0,4),(1,5),(2,6),(3,7),
(4,5),(5,7),(7,6),(6,4)]
self.assertEqual(inf_dof(cube_config, edges), 6)
def testNDPoint(self):
dim = 79
config = [(0,)*dim]
edges = []
self.assertEqual(inf_dof(config, edges), 0)
def testNDLine(self):
dim = 17
config = [(0,)*dim, (1,)*dim]
edges = [(0,1)]
self.assertEqual(inf_dof(config, edges), 0)
class IsGenericallyRigidTest(unittest.TestCase):
def test1DLine(self):
self.assertTrue(is_generically_rigid(2, [(0,1)], 2))
def test2DLine(self):
self.assertTrue(is_generically_rigid(2, [(0,1)], 2))
def test2DTriangle(self):
self.assertTrue(is_generically_rigid(3, [(0,1), (1,2), (2,0)], 2))
def test2DTrianglePair(self):
"""
0--1
| /|
|/ |
2--3
(rigid in 2D)
"""
edges = [(0, 1), (0, 2), (1, 2), (1, 3), (2, 3)]
self.assertTrue(is_generically_rigid(4, edges, 2))
def test3DTrianglePair(self):
"""
0--1
| /|
|/ |
2--3
(not rigid in 3D)
"""
edges = [(0, 1), (0, 2), (1, 2), (1, 3), (2, 3)]
self.assertFalse(is_generically_rigid(4, edges, 3))
if __name__ == '__main__':
unittest.main()