def optimize(bzs): result = [] for sp in fromcubic.bzs_to_pcorn(bzs): r = [] curve = pcorn.Curve(sp) breaks = getbreaks(curve) for i in range(len(breaks) - 1): r.extend(optimize_run(curve, breaks[i], breaks[i + 1])) result.append(r) return result
def compute_arms(th0, th1): seg = pcorn.Segment((0, 0), (1, 0), th0, th1) curve = pcorn.Curve([seg]) s0 = 0 s1 = seg.arclen - 1e-9 print s1, curve.arclen bzs = draw_cornu.pcorn_segment_to_bzs(curve, s0, s1, 1, 1e9) a0 = math.hypot(bzs[0][1][0], bzs[0][1][1]) a1 = math.hypot(1 - bzs[0][2][0], bzs[0][2][1]) return (a0, a1)
def offset(curve, d): segs = [] for seg in curve.segs: segs.extend(seg_offset(seg, d)) return pcorn.Curve(segs)
print '0 20 translate' if __name__ == '__main__': f = file(sys.argv[1]) bzs = read_bz(f) rsps = bzs_to_pcorn(bzs, 1) #print rsps tocubic.plot_prolog() print 'grestore' print '1 -1 scale 0 -720 translate' print '/ss 1.5 def' print '/circle { ss 0 moveto currentpoint exch ss sub exch ss 0 360 arc } bind def' tot = 0 for segs in rsps: curve = pcorn.Curve(segs) #curve = offset.offset(curve, 10) print '%', curve.arclen print '%', curve.sstarts if 0: print 'gsave 1 0 0 setrgbcolor' cmd = 'moveto' for i in range(100): s = i * .01 * curve.arclen x, y = curve.xy(s) th = curve.th(s) sth = 5 * sin(th) cth = 5 * cos(th) print x, y, cmd cmd = 'lineto' print 'closepath stroke grestore'