"""Plot poses of a design_fit candidate with the coarse capsules: y-z (along x) and x-y (plan) views."""
import math, sys, os, subprocess
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import design_fit as F
import design_kin as K
MAGICK = r"E:\Tools\ImageMagick-7.1.2-Q16-HDRI\magick.exe"
s, u, px, cle = map(float, sys.argv[1:5]); split = sys.argv[5]; split = split if split == "prop" else float(split)
version, door, pref = sys.argv[6], sys.argv[7], sys.argv[8]
frames = [int(v) for v in sys.argv[9].split(",")] if len(sys.argv) > 9 else [1, 6, 12, 30, 48]
S = F.setup(s, u, px, cle, split, door, version)
br = +1
m = F.assess(S, 0.0, br)
if m["fail"]:
br = -1; m = F.assess(S, 0.0, br)
print("fail", m["fail"], "branch", br)
recs = [r for r in m["recs"] if r["f"] in frames]
cols = ["#d33", "#e80", "#0a0", "#08c", "#a0a", "#555", "#0aa"]
def view(fn, proj, rng, title):
(u0, u1), (v0, v1) = rng
W, H = 1400, int(1400 * (v1 - v0) / (u1 - u0))
sc = W / (u1 - u0)
X = lambda a: (a - u0) * sc
Y = lambda b: (v1 - b) * sc
L = ['')
open(pref + "_yz.svg", "w").write("\n".join(L))
# plan x-y (+y up the page)
side = S["side"]
xr = (-9.6, -0.4) if side > 0 else (6.5, 15.7)
L, X, Y = view(None, None, (xr, (-10.0, -2.0)), "plan (x right, +y up), %s door %s" % (version, door))
for xa, xb in ((-9.1035, -2.5453), (8.6453, 15.2035)):
L.append('' % (X(xa), Y(-5.5662), X(xb) - X(xa), Y(-6.0238) - Y(-5.5662)))
for xw in (-9.0348, 15.1348):
L.append('' % (X(xw), Y(-10), X(xw), Y(-2)))
L.append('' % (X(-3.15), Y(-10), X(-3.15), Y(-2)))
L.append('' % (X(9.25), Y(-10), X(9.25), Y(-2)))
for i, r in enumerate(recs):
col = cols[i % len(cols)]
dx, dy, dz = r["door"]
x0, x1 = (dx - 2.997, dx + 2.825) if side > 0 else (dx - 2.825, dx + 2.997)
L.append('' % (X(x0), Y(dy + 2.557), X(x1) - X(x0), Y(dy - 2.87) - Y(dy + 2.557), col))
for nm, a, b, rad in F.world_pts(S, r):
L.append('' % (X(a[0]), Y(a[1]), X(b[0]), Y(b[1]), col, 2 * rad * (X(1) - X(0))))
L.append('' % (X(a[0]), Y(a[1]), X(b[0]), Y(b[1]), col))
L.append('' % (X(r["c"] - S["Lc"] / 2), Y(S["yb"] + S["Wc"] / 2), S["Lc"] * (X(1) - X(0)), S["Wc"] * (X(1) - X(0)), col))
L.append('f%d' % (X(r["WC"][0]) + 6, Y(r["WC"][1]) - 6, col, r["f"]))
L.append('')
open(pref + "_xy.svg", "w").write("\n".join(L))
for k in ("_yz", "_xy"):
subprocess.run([MAGICK, pref + k + ".svg", pref + k + ".png"])
for r in recs:
q = r["q"]
print("f%d c %.3f q1 %.0f q2 %.0f q3 %.0f q4 %.0f q5 %.0f q6 %.0f elb %.0f WC %s" % (r["f"], r["c"], *[math.degrees(q[k]) for k in ("q1", "q2", "q3", "q4", "q5", "q6", "elbow_inner")], tuple(round(v, 2) for v in r["WC"])))