2 from __future__ import print_function
5 from numpy import cos, sin
10 from moedebug import *
14 from math import atan2, atan, sqrt
18 findcurve_subprocs = { }
20 class OptimisedCurve():
21 def __init__(hc, cp, nt):
22 db = DiscreteBezier(cp, nt, constructor=BezierSegment)
23 fc_input = map(db.point_at_it, range(0, nt+1))
24 for end in (False,True):
30 ef_dirn =unit_v(cp[cp1i] - cp[cp0i])
31 ef_len = np.linalg.norm(fc_input[fi] - fc_input[ei])
32 f = e + ef_dirn * ef_len
36 findcurve_epsilon = dist_pq_plane * 0.01
39 subproc = findcurve_subprocs[nt]
41 dbg('STARTING FINDCURVE %d' % nt)
42 subproc = subprocess.Popen(
43 ['./findcurve', '%d' % nt],
45 stdin=subprocess.PIPE,
46 stdout=subprocess.PIPE,
49 # restore_signals=True, // want python2 compat, nnng
50 universal_newlines=True,
52 findcurve_subprocs[nt] = subproc
54 dbg(('RUNNING FINDCURVE')
56 findcurve_input = np.hstack(*findcurve_input)
57 s = ' '.join(map(str, findcurve_input))
61 print(s, file=findcurve_subproc.stdin)
62 findcurve_subproc.stdin.flush()
67 l = findcurve_subproc.stdout.readline()
70 if not l: vdbg().crashing('findcurve EOF')
71 if not l.startswith('['):
79 dbg('[%s] %s' % (l, commentary))
82 hc.findcurve_result = l[0:6]
83 #hc.findcurve_result = findcurve_start
84 hc.threshold = l[0]**2
85 hc.total_dist = hc.threshold + l[1]**2
86 #vdbg().curve( hc.point_at_t )
88 def point_at_t(hc, normalised_parameter):
89 dist = normalised_parameter * hc.total_dist
90 ours = list(hc.findcurve_result)
91 if dist <= hc.threshold:
95 ours[1] = sqrt(dist - hc.threshold)
96 asmat = hc.func(*ours)
98 p = augmatmultiply(hc.findcurve_basis, p)