Skip to content

Commit 4add1d0

Browse files
committed
started implementing approach to find round shapes like spheres and hylinders
1 parent 2ffa431 commit 4add1d0

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

stl2step/__main__.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,45 @@ def count_len(lst):
175175
return np.unique(np.array([len(e) for e in lst]), return_counts=True)
176176

177177

178+
def get_2triangle_pacthes(edge_idx2faces_idx, faces):
179+
return np.array(
180+
[
181+
list(
182+
set(
183+
[
184+
(p[0], p[1], p[2])
185+
for p in np.concatenate([faces[e[0]], faces[e[1]]])
186+
]
187+
)
188+
)
189+
for e in edge_idx2faces_idx
190+
]
191+
)
192+
193+
194+
def calc_circumsphere_center(four_pnts):
195+
M = np.vstack(
196+
[
197+
four_pnts[1] - four_pnts[0],
198+
four_pnts[2] - four_pnts[0],
199+
four_pnts[3] - four_pnts[0],
200+
]
201+
)
202+
print(np.linalg.det(M))
203+
if np.abs(np.linalg.det(M)) < 1e-10:
204+
return np.array([np.nan] * 4)
205+
r_vec = 0.5 * np.array(
206+
[
207+
np.dot(four_pnts[1] - four_pnts[0], four_pnts[1] + four_pnts[0]),
208+
np.dot(four_pnts[2] - four_pnts[0], four_pnts[2] + four_pnts[0]),
209+
np.dot(four_pnts[3] - four_pnts[0], four_pnts[3] + four_pnts[0]),
210+
]
211+
)
212+
c = np.linalg.solve(M, r_vec)
213+
r = np.linalg.norm(c - four_pnts[0])
214+
return np.array([c[0], c[1], c[2], r])
215+
216+
178217
if __name__ == "__main__":
179218
print("stl2step")
180219

@@ -191,6 +230,13 @@ def count_len(lst):
191230
edge_idx2edge, edge_idx2faces_idx = find_edges_of_faces(face_idx2pnt_idx_lst)
192231
face_idx2edge_idx_list = invert_relation(edge_idx2faces_idx, number_of_faces)
193232

233+
# print(edge_idx2faces_idx)
234+
# print(faces)
235+
236+
edge_idx24pnts = get_2triangle_pacthes(edge_idx2faces_idx, faces)
237+
edge_idx2circ_cntr = [calc_circumsphere_center(e) for e in edge_idx24pnts]
238+
print(edge_idx2circ_cntr)
239+
194240
# find planes
195241
faces_to_be_merged_list = cluster_planes(faces)
196242
print(f"Number of planes found: {len(faces_to_be_merged_list):16d}")

0 commit comments

Comments
 (0)