From d5967a760d40f59effe0c2c6f137c81543dc560d Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 7 Apr 2018 22:40:33 +0100 Subject: [PATCH] curveopt: wip Signed-off-by: Ian Jackson --- curveopt.py | 41 ++++++++++++++++++++++------------------- findcurve.c | 2 +- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/curveopt.py b/curveopt.py index 699e437..ab02a82 100644 --- a/curveopt.py +++ b/curveopt.py @@ -19,28 +19,31 @@ findcurve_subprocs = { } class OptimisedCurve(): def __init__(oc, cp, nt): - db = DiscreteBezier(cp, nt, constructor=BezierSegment) + db = DiscreteBezier(cp, nt, bezier_constructor=BezierSegment) + fc_input = map(db.point_at_it, range(0, nt+1)) + for end in (False,True): - ei = end ? nt : 0 - fi = end ? nt-1 : 1 - cp0i = end ? 0 : 3 - cp1i = end ? 1 : 2 - e = cp[cp0i] - ef_dirn =unit_v(cp[cp1i] - cp[cp0i]) - ef_len = np.linalg.norm(fc_input[fi] - fc_input[ei]) + ei = nt if end else 0 + fi = nt-1 if end else 1 + cp0i = 0 if end else 3 + cp1i = 1 if end else 2 + e = np.array(cp[cp0i]) + ef_dirn = unit_v(cp[cp1i] - cp[cp0i]) + ef_len = np.linalg.norm(np.array(fc_input[fi]) - np.array(fc_input[ei])) f = e + ef_dirn * ef_len fc_input[ei] = e fc_input[fi] = f - findcurve_epsilon = dist_pq_plane * 0.01 + findcurve_epsilon = 0.01 try: subproc = findcurve_subprocs[nt] except KeyError: - dbg('STARTING FINDCURVE %d' % nt) + cl = ['./findcurve', '%d' % nt, '%.18g' % findcurve_epsilon] + dbg('STARTING FINDCURVE %s' % cl) subproc = subprocess.Popen( - ['./findcurve', '%d' % nt], + cl, bufsize=1, stdin=subprocess.PIPE, stdout=subprocess.PIPE, @@ -51,20 +54,20 @@ class OptimisedCurve(): ) findcurve_subprocs[nt] = subproc - dbg(('RUNNING FINDCURVE') + dbg('RUNNING FINDCURVE') - findcurve_input = np.hstack(*findcurve_input) - s = ' '.join(map(str, findcurve_input)) + fc_input = np.hstack(fc_input) + s = ' '.join(map(str, fc_input)) dbg(('>> %s' % s)) - print(s, file=findcurve_subproc.stdin) - findcurve_subproc.stdin.flush() + print(s, file=subproc.stdin) + subproc.stdin.flush() commentary = '' while True: - l = findcurve_subproc.stdout.readline() + l = subproc.stdout.readline() l = l.rstrip() dbg('<< ', l) if not l: vdbg().crashing('findcurve EOF') @@ -83,5 +86,5 @@ class OptimisedCurve(): oc._result = np.reshape(findcurve_result, (3,-1)) - def point_at_ti(oc, ti): - return oc._result[ti] + def point_at_it(oc, it): + return oc._result[it] diff --git a/findcurve.c b/findcurve.c index 077f31c..58f7472 100644 --- a/findcurve.c +++ b/findcurve.c @@ -102,6 +102,7 @@ int main(int argc, const char *const *argv) { int i; NP = atoi(argv[1]); + epsilon = atof(argv[2]); gsl_rng *rng = gsl_rng_alloc(gsl_rng_ranlxd2); @@ -112,7 +113,6 @@ int main(int argc, const char *const *argv) { /* NINPUT + 1 doubles: startpoint, epsilon for residual */ for (i=0; i