2 from __future__ import print_function
5 from numpy import cos, sin
12 from moedebug import *
16 from math import atan2, atan, sqrt
20 findcurve_subprocs = { }
22 class OptimisedCurve():
23 def __init__(oc, cp, nt):
24 db = DiscreteBezier(cp, nt, bezier_constructor=BezierSegment)
26 fc_input = map(db.point_at_it, range(0, nt+1))
28 for end in (False,True):
30 fi = nt-1 if end else 1
31 cp0i = 0 if end else 3
32 cp1i = 1 if end else 2
33 e = np.array(cp[cp0i])
34 ef_dirn = unit_v(cp[cp1i] - cp[cp0i])
35 ef_len = np.linalg.norm(np.array(fc_input[fi]) - np.array(fc_input[ei]))
36 f = e + ef_dirn * ef_len
40 findcurve_epsilon = 0.01
43 subproc = findcurve_subprocs[nt]
45 cl = ['./findcurve', '%d' % (nt+1), '%.18g' % findcurve_epsilon]
46 dbg('STARTING FINDCURVE %s' % cl)
47 subproc = subprocess.Popen(
50 stdin=subprocess.PIPE,
51 stdout=subprocess.PIPE,
54 # restore_signals=True, // want python2 compat, nnng
55 universal_newlines=True,
57 findcurve_subprocs[nt] = subproc
59 dbg('RUNNING FINDCURVE')
61 fc_input = np.hstack(fc_input)
62 s = ' '.join(map(str, fc_input))
66 print(s, file=subproc.stdin)
72 l = subproc.stdout.readline()
75 if not l: vdbg().crashing('findcurve EOF')
76 if not l.startswith('['):
84 dbg('[%s] %s' % (l, commentary))
90 oc._result = np.reshape(findcurve_result, (-1,3), 'C')
93 vdbg().curve( oc.point_at_t )
95 def point_at_it(oc, it):
99 def point_at_t(oc, t):
101 it0 = int(math.floor(itd))
102 it1 = int(math.ceil(itd))
103 p0 = oc.point_at_it(it0)
104 p1 = oc.point_at_it(it1)
105 return p0 + (p1-p0) * (itd-it0)