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))
29 for end in (False,True):
31 fi = nt-1 if end else 1
32 cp0i = 3 if end else 0
33 cp1i = 2 if end else 1
34 e = np.array(cp[cp0i])
35 ef_dirn = unit_v(cp[cp1i] - cp[cp0i])
36 ef_len = np.linalg.norm(np.array(fc_input[fi]) - np.array(fc_input[ei]))
37 f = e + ef_dirn * ef_len
41 findcurve_epsilon = 0.01
44 subproc = findcurve_subprocs[nt]
46 cl = ['./findcurve', '%d' % (nt+1), '%.18g' % findcurve_epsilon]
47 dbg('STARTING FINDCURVE %s' % cl)
48 subproc = subprocess.Popen(
51 stdin=subprocess.PIPE,
52 stdout=subprocess.PIPE,
55 # restore_signals=True, // want python2 compat, nnng
56 universal_newlines=True,
58 findcurve_subprocs[nt] = subproc
60 dbg('RUNNING FINDCURVE')
62 fc_input = np.hstack(fc_input)
63 s = ' '.join(map(str, fc_input))
67 print(s, file=subproc.stdin)
73 l = subproc.stdout.readline()
76 if not l: vdbg().crashing('findcurve EOF')
77 if not l.startswith('['):
85 dbg('[%s] %s' % (l, commentary))
91 oc._result = np.reshape(findcurve_result, (-1,3), 'C')
94 vdbg().curve( oc.point_at_t )
96 def point_at_it(oc, it):
100 def point_at_t(oc, t):
102 it0 = int(math.floor(itd))
103 it1 = int(math.ceil(itd))
104 p0 = oc.point_at_it(it0)
105 p1 = oc.point_at_it(it1)
106 return p0 + (p1-p0) * (itd-it0)