def plot_ks(segs, nodes, xo, yo, xscale, yscale): j = 0 cmd = 'moveto' x = xo for i in range(len(segs)): i1 = (i + 1) % len(nodes) n0 = nodes[i] n1 = nodes[i1] x0, y0, t0 = n0.x, n0.y, n0.ty x1, y1, t1 = n1.x, n1.y, n1.ty ks = segs[i].ks chord, ch_th = poly3.integ_chord(ks) l = chord/segs[i].chord k0 = l * poly3.eval_cubic(ks[0], ks[1], .5 * ks[2], 1./6 * ks[3], -.5) print x, yo + yscale * k0, cmd cmd = 'lineto' k3 = l * poly3.eval_cubic(ks[0], ks[1], .5 * ks[2], 1./6 * ks[3], .5) k1 = k0 + l/3 * (ks[1] - 0.5 * ks[2] + .125 * ks[3]) k2 = k3 - l/3 * (ks[1] + 0.5 * ks[2] + .125 * ks[3]) print x + xscale / l / 3., yo + yscale * k1 print x + 2 * xscale / l / 3., yo + yscale * k2 print x + xscale / l, yo + yscale * k3, 'curveto' x += xscale / l if t1 == 'v': j += 2 else: j += 1 print 'stroke' print xo, yo, 'moveto', x, yo, 'lineto stroke'
def plot_ks(path, th, k): if path[0][2] == '{': closed = 0 else: closed = 1 j = 0 cmd = 'moveto' xo = 36 yo = 550 xscale = .5 yscale = 2000 x = xo for i in range(len(path) + closed - 1): i1 = (i + 1) % len(path) x0, y0, t0 = path[i] x1, y1, t1 = path[i1] j1 = (j + 1) % len(th) th0 = th[j] k0 = k[j] th1 = th[j1] k1 = k[j1] chord_th = atan2(y1 - y0, x1 - x0) chord_len = hypot(y1 - y0, x1 - x0) ks = poly3.solve_3spiro(mod_2pi(chord_th - th0), mod_2pi(th1 - chord_th), k0 * chord_len, k1 * chord_len) ksp = (ks[0] * .5, ks[1] * .25, ks[2] * .125, ks[3] * .0625) pside = poly3.int_3spiro_poly(ksp, 64) ksm = (ks[0] * -.5, ks[1] * .25, ks[2] * -.125, ks[3] * .0625) mside = poly3.int_3spiro_poly(ksm, 64) print '%', x0, y0, k0, k1 print "% ks = ", ks l = 2 * chord_len / hypot(pside[-1][0] + mside[-1][0], pside[-1][1] + mside[-1][1]) for i in range(100): s = .01 * i - 0.5 kp = poly3.eval_cubic(ks[0], ks[1], .5 * ks[2], 1. / 6 * ks[3], s) kp /= l print x + xscale * l * (s + .5), yo + yscale * kp, cmd cmd = 'lineto' x += xscale * l if t1 == 'v': j += 2 else: j += 1 print 'stroke' print xo, yo, 'moveto', x, yo, 'lineto stroke'
def plot_ks(path, th, k): if path[0][2] == '{': closed = 0 else: closed = 1 j = 0 cmd = 'moveto' xo = 36 yo = 550 xscale = .5 yscale = 2000 x = xo for i in range(len(path) + closed - 1): i1 = (i + 1) % len(path) x0, y0, t0 = path[i] x1, y1, t1 = path[i1] j1 = (j + 1) % len(th) th0 = th[j] k0 = k[j] th1 = th[j1] k1 = k[j1] chord_th = atan2(y1 - y0, x1 - x0) chord_len = hypot(y1 - y0, x1 - x0) ks = poly3.solve_3spiro(mod_2pi(chord_th - th0), mod_2pi(th1 - chord_th), k0 * chord_len, k1 * chord_len) ksp = (ks[0] * .5, ks[1] * .25, ks[2] * .125, ks[3] * .0625) pside = poly3.int_3spiro_poly(ksp, 64) ksm = (ks[0] * -.5, ks[1] * .25, ks[2] * -.125, ks[3] * .0625) mside = poly3.int_3spiro_poly(ksm, 64) print '%', x0, y0, k0, k1 print "% ks = ", ks l = 2 * chord_len / hypot(pside[-1][0] + mside[-1][0], pside[-1][1] + mside[-1][1]) for i in range(100): s = .01 * i - 0.5 kp = poly3.eval_cubic(ks[0], ks[1], .5 * ks[2], 1./6 * ks[3], s) kp /= l print x + xscale * l * (s + .5), yo + yscale * kp, cmd cmd = 'lineto' x += xscale * l if t1 == 'v': j += 2 else: j += 1 print 'stroke' print xo, yo, 'moveto', x, yo, 'lineto stroke'