dyna3/data554/processData.py

85 lines
3.6 KiB
Python

from math import fabs, nan, sqrt
import sys
vertices = {}
current_id = ""
for line in sys.stdin:
text = line.strip()
if text.endswith(":"):
new_id = text.strip(":")
vertices[new_id] = []
if current_id: print(current_id, vertices[current_id])
current_id = new_id
continue
remainder = text.strip("┌ ┐└┘│")
if len(remainder): vertices[current_id].append(float(remainder))
print(len(vertices), "vertices found")
P = True
F = False
HPHI = nan
RTHPHI = nan
RTPHIPH = nan
# Taken verbatim from test_assembly_chooser.rs
acron_data = [
("A_NE", [ 0.5, 0.5, 0.], P, 0, ""),
("A_NW", [-0.5, 0.5, 0.], P, 0, ""),
("A_SE", [ 0.5, -0.5, 0.], P, 0, ""),
("A_SW", [-0.5, -0.5, 0.], P, 0, ""),
("Z_E", [ 0.229, -0.002, 0.821], F, 1, "A_NE,A_SE"),
("Z_S", [ 0.002, -0.229, 0.821], F, 1, "A_SE,A_SW"),
("B_NE", [ HPHI, HPHI, RTHPHI], P, 2, "Z_E"),
("B_NW", [-HPHI, HPHI, RTHPHI], P, 2, ""),
("B_SW", [-HPHI, -HPHI, RTHPHI], P, 2, "Z_S"),
("B_SE", [ 0.812, -0.812, 0.89], F, 2, "A_SE,Z_E,Z_S"),
("Y_NE", [ 0.11, 0.103, 1.019], F, 3, "B_NE"),
("Y_NW", [-0.103, 0.103, 1.02], F, 3, "B_NW"),
("Y_SE", [ 0.11, -0.11, 1.017], F, 3, "B_SE"),
("Y_SW", [-0.103, -0.11, 1.019], F, 3, "B_SW"),
("C_N", [ 0., 1., RTPHIPH], P, 4, "Y_NE,Y_NW"),
("C_W", [-1., 0., RTPHIPH], P, 4, "Y_NW,Y_SW"),
("C_E", [ 1.006, -0.006, 1.45], F, 4, "B_NE,B_SE,Y_NE,Y_SE"),
("C_S", [ 0.006, -1.006, 1.45], F, 4, "B_SE,B_SW,Y_SE,Y_SW"),
("D_NE", [ 0.2, 0.181, 2.011], F, 5, "Y_NE,C_N,C_E"),
("D_NW", [-0.181, 0.181, 2.014], F, 5, "Y_NW,C_N,C_W"),
("D_SE", [ 0.2, -0.2, 2.009], F, 5, "Y_SE,C_E,C_S"),
("D_SW", [-0.181, -0.2, 2.011], F, 5, "Y_SW,C_W,C_S"),
("E_N", [ 0.012, 1.055, 2.46], F, 6, "C_N,D_NE,D_NW"),
("E_W", [-1.055, -0.012, 2.46], F, 6, "C_W,D_NW,D_SW"),
("E_E", [ 1.079, -0.012, 2.447], F, 6, "C_E,D_NE,D_SE"),
("E_S", [ 0.012, -1.079, 2.447], F, 6, "C_S,D_SE,D_SW"),
("F_NE", [ 0.296, 0.265, 3.003], F, 7, "D_NE,E_N,E_E"),
("F_NW", [-0.265, 0.265, 3.007], F, 7, "D_NW,E_N,E_W"),
("F_SE", [ 0.296, -0.296, 3.0], F, 7, "D_SE,E_E,E_S"),
("F_SW", [-0.265, -0.296, 3.003], F, 7, "D_SW,E_W,E_S"),
# The following must be in order around the octagon (in some orientation)
("G_1", [ 0.517, 1.19, 3.312], F, 8, "E_N,F_NE"),
("G_2", [ 1.224, 0.483, 3.304], F, 8, "E_E,F_NE"),
("G_4", [ 1.224, -0.517, 3.298], F, 8, "E_E,F_SE"),
("G_5", [ 0.517, -1.224, 3.298], F, 8, "E_S,F_SE"),
("G_7", [-0.483, -1.224, 3.304], F, 8, "E_S,F_SW"),
("G_8", [-1.19, -0.517, 3.312], F, 8, "E_W,F_SW"),
("G_10", [-1.19, 0.483, 3.318], F, 8, "E_W,F_NW"),
("G_11", [-0.483, 1.19, 3.318], F, 8, "E_N,F_NW"),
]
E = 0.0
n_struts = 11 # for the pinned vertices, which all have length exactly 1
for vi in range(0, len(acron_data)):
start_id = acron_data[vi][0]
start = vertices[start_id]
ends = acron_data[vi][4].split(",")
if acron_data[vi][3] == 8:
if start_id != "G_1":
ends.append(acron_data[vi-1][0])
if vi+1 == len(acron_data):
ends.append("G_1")
for end_id in ends:
if not(end_id): continue
end = vertices[end_id]
dist = sqrt(
(end[0]-start[0])**2 + (end[1]-start[1])**2 + (end[2]-start[2])**2)
print(f"{start_id}-{end_id}: {dist} {dist-1}")
E += fabs(dist-1)
n_struts += 1
print(n_struts, "unit edges")
print(f"----> Total distortion E={E}")