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__(oc, cp, nt):
22 db = DiscreteBezier(cp, nt, bezier_constructor=BezierSegment)
24 fc_input = map(db.point_at_it, range(0, nt+1))
26 for end in (False,True):
28 fi = nt-1 if end else 1
29 cp0i = 0 if end else 3
30 cp1i = 1 if end else 2
31 e = np.array(cp[cp0i])
32 ef_dirn = unit_v(cp[cp1i] - cp[cp0i])
33 ef_len = np.linalg.norm(np.array(fc_input[fi]) - np.array(fc_input[ei]))
34 f = e + ef_dirn * ef_len
38 findcurve_epsilon = 0.01
41 subproc = findcurve_subprocs[nt]
43 cl = ['./findcurve', '%d' % nt, '%.18g' % findcurve_epsilon]
44 dbg('STARTING FINDCURVE %s' % cl)
45 subproc = subprocess.Popen(
48 stdin=subprocess.PIPE,
49 stdout=subprocess.PIPE,
52 # restore_signals=True, // want python2 compat, nnng
53 universal_newlines=True,
55 findcurve_subprocs[nt] = subproc
57 dbg('RUNNING FINDCURVE')
59 fc_input = np.hstack(fc_input)
60 s = ' '.join(map(str, fc_input))
64 print(s, file=subproc.stdin)
70 l = subproc.stdout.readline()
73 if not l: vdbg().crashing('findcurve EOF')
74 if not l.startswith('['):
82 dbg('[%s] %s' % (l, commentary))
87 oc._result = np.reshape(findcurve_result, (3,-1))
89 def point_at_it(oc, it):