-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv3utils.py
More file actions
190 lines (174 loc) · 5.81 KB
/
v3utils.py
File metadata and controls
190 lines (174 loc) · 5.81 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
from vector3 import Vector3, intDistance, vecDistance
from typing import Union
def fusePointLists(points1:list[Vector3],points2:list[Vector3]) -> list[Vector3]:
"""
returns union of unique points in both lists
"""
ans = points1[:]
ans2 = [p for p in points2 if p not in ans]
return ans+ans2
def getDistances(points:list[Vector3])-> list[list[int]]:
"returns list of all reciprocal distances of points in list"
dists = []
for p in points:
dists.append([intDistance(p,pp) for pp in points if pp is not p])
return dists
def getVecDistances(points:list[Vector3]) -> list[list[tuple[int,int,int]]]:
"""
returns list of reciprocal distances in tuples
"""
dists = []
for p in points:
dists.append([vecDistance(p,pp) for pp in points if pp is not p])
return dists
def areDistancesCompatible(points1:list[Vector3],points2:list[Vector3], threshold:int) -> bool:
"""
Where n = threshold\n
Returns True if at least n points in points1 and points2 have n distances in common\n
(similar to h-index)
points1: first list of Vector3
points2: second list of Vector3
threshold: barrier to surpass for both number of points and distances in common
"""
dists1 = getDistances(points1)
dists2 = getDistances(points2)
count = 0
usedpoints = [] #points that have already satisfied the property
for dist1 in dists1:
shouldLoop = True
for dist2 in dists2:
if not shouldLoop: break
if dist2 in usedpoints: continue
else:
distcount = 0
for d in dist1:
if d in dist2: distcount += 1
if distcount >= threshold-1:
count += 1
if count >= threshold: return True
usedpoints.append(dist2)
shouldLoop = False
return False
def areDistancesVecCompatible(points1:list[Vector3],points2:list[Vector3],threshold:int) -> bool:
"""
Like areDistancesCompatible, but for vectors\n
The result will depend on the correct orientation
"""
dists1 = getVecDistances(points1)
dists2 = getVecDistances(points2)
count = 0
usedpoints = [] #points that have already satisfied the property
for dist1 in dists1:
shouldLoop = True
for dist2 in dists2:
if not shouldLoop: break
if dist2 in usedpoints: continue
else:
distcount = 0
for d in dist1:
if d in dist2: distcount += 1
if distcount >= threshold-1:
count += 1
if count >= threshold: return True
usedpoints.append(dist2)
shouldLoop = False
return False
def extractDistCompatible(candidates:list[list[Vector3]], refPoints:list[Vector3], threshold:int) \
-> Union[list[Vector3],None]:
"""
returns first match for areDistancesCompatible with refPoints with
given threshold
"""
for c in candidates:
if areDistancesCompatible(c,refPoints,threshold): return c
return None
def getRotations(vec:Vector3) -> list[Vector3]:
"get list of all 24 possible 90 degree rotations of input vector"
ans = []
v = vec.copy()
for _ in range(4):
v.rotateY()
ans.append(v.copy())
v.rotateZ()
for _ in range(4):
v.rotateX()
ans.append(v.copy())
v.rotateZ()
for _ in range(4):
v.rotateY()
ans.append(v.copy())
v.rotateZ()
for _ in range(4):
v.rotateX()
ans.append(v.copy())
v.rotateY()
for _ in range(4):
v.rotateZ()
ans.append(v.copy())
v.rotateY()
v.rotateY()
for _ in range(4):
v.rotateZ()
ans.append(v.copy())
return ans
def getListRotations(vecs:list[Vector3]) -> list[list[Vector3]]:
"get all 24 90 degree rotations of list of vectors"
ans = [[] for _ in range(24)]
for v in vecs:
for i,x in enumerate(getRotations(v)):
ans[i].append(x)
return ans
def extractCompatibleRotation(points:list[Vector3],refPoints:list[Vector3],threshold:int) ->\
Union[list[Vector3],None]:
"""
rotate points such that the vec distance with refPoints matches >= threshold\n
or None if no rotation satisfies the criteria
"""
rots = getListRotations(points)
for r in rots:
if areDistancesVecCompatible(r,refPoints,threshold): return r
return None
def getTranslations(points:list[Vector3],move:Vector3) -> list[Vector3]:
"returns list of points, translated by move vector"
ans = []
for p in points:
ans.append(p.copy()+move)
return ans
def getAdjustments(points:list[Vector3],ref:Vector3) -> list[list[Vector3]]:
"copies list for every translation which puts a point over ref"
ans = []
for p in points:
motion = ref - p
ans.append(getTranslations(points,motion))
#print(len(points)==len(ans))
return ans
def getOverlap(p1:list[Vector3],p2:list[Vector3]) -> int:
"returns number of points that overlap"
#print("_-_")
count = 0
hasPrinted = False
for p in p1:
if p in p2:
hasPrinted = True
#print(p)
count+=1
else:
#print(f"{p} not in control list")
pass
if hasPrinted:
#print("---")
#print(*p1)
#print(*p2)
pass
#print("-_-")
return count
def extractSufficientAdjustment(points:list[Vector3],refPoints:list[Vector3],threshold:int)->\
Union[list[Vector3],None]:
"""
Return translation of points that overlap with >= threshold elements of refPoints
"""
for ref in refPoints:
trs = getAdjustments(points,ref)
for t in trs:
if getOverlap(t,refPoints) >= threshold: return t
return None