def cubic_bz_to_pcorn(bz, thresh): dx = bz[3][0] - bz[0][0] dy = bz[3][1] - bz[0][1] dx1 = bz[1][0] - bz[0][0] dy1 = bz[1][1] - bz[0][1] dx2 = bz[3][0] - bz[2][0] dy2 = bz[3][1] - bz[2][1] chth = atan2(dy, dx) th0 = tocubic.mod_2pi(chth - atan2(dy1, dx1)) th1 = tocubic.mod_2pi(atan2(dy2, dx2) - chth) seg = pcorn.Segment(bz[0], bz[3], th0, th1) err = measure_bz_cloth(seg, bz) if err < thresh: return [seg] else: # de Casteljau x01, y01 = 0.5 * (bz[0][0] + bz[1][0]), 0.5 * (bz[0][1] + bz[1][1]) x12, y12 = 0.5 * (bz[1][0] + bz[2][0]), 0.5 * (bz[1][1] + bz[2][1]) x23, y23 = 0.5 * (bz[2][0] + bz[3][0]), 0.5 * (bz[2][1] + bz[3][1]) xl2, yl2 = 0.5 * (x01 + x12), 0.5 * (y01 + y12) xr1, yr1 = 0.5 * (x12 + x23), 0.5 * (y12 + y23) xm, ym = 0.5 * (xl2 + xr1), 0.5 * (yl2 + yr1) bzl = [bz[0], (x01, y01), (xl2, yl2), (xm, ym)] bzr = [(xm, ym), (xr1, yr1), (x23, y23), bz[3]] segs = cubic_bz_to_pcorn(bzl, 0.5 * thresh) segs.extend(cubic_bz_to_pcorn(bzr, 0.5 * thresh)) return segs
def measure_derivs(x, ys): dx, dy = tocubic.bz_eval(dbz, x) ds = hypot(dx, dy) s = ys[0] * arclen_ratio dscore = ds * (tocubic.mod_2pi(atan2(dy, dx) - seg.th(s)) ** 2) #print s, atan2(dy, dx), seg.th(s) return [ds, dscore]
def measure_derivs(x, ys): dx, dy = tocubic.bz_eval(dbz, x) ds = hypot(dx, dy) s = ys[0] * arclen_ratio dscore = ds * (tocubic.mod_2pi(atan2(dy, dx) - seg.th(s))**2) #print s, atan2(dy, dx), seg.th(s) return [ds, dscore]