2 from __future__ import print_function
5 from numpy import cos, sin
12 from moedebug import *
16 from math import atan2, atan, sqrt
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))
27 for end in (False,True):
29 fi = nt-1 if end else 1
30 cp0i = 3 if end else 0
31 cp1i = 2 if end else 1
32 e = np.array(cp[cp0i])
33 ef_dirn = unit_v(cp[cp1i] - cp[cp0i])
34 ef_len = np.linalg.norm(np.array(fc_input[fi]) - np.array(fc_input[ei]))
35 f = e + ef_dirn * ef_len
36 dbg(repr((end, e,f, ef_dirn, ef_len)))
42 findcurve_epsilon = 0.01
44 cl = ['./findcurve', '%d' % (nt+1), '%.18g' % findcurve_epsilon]
45 dbg('STARTING FINDCURVE %s' % cl)
46 subproc = subprocess.Popen(
49 stdin=subprocess.PIPE,
50 stdout=subprocess.PIPE,
53 # restore_signals=True, // want python2 compat, nnng
54 universal_newlines=True,
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))
89 assert(subproc.returncode == 0)
92 oc._result = np.reshape(findcurve_result, (-1,3), 'C')
95 vdbg().curve( oc.point_at_t )
97 def point_at_it(oc, it):
101 def point_at_t(oc, t):
103 it0 = int(math.floor(itd))
104 it1 = int(math.ceil(itd))
105 p0 = oc.point_at_it(it0)
106 p1 = oc.point_at_it(it1)
107 return p0 + (p1-p0) * (itd-it0)