Exemplo n.º 1
0
def make_error_vec(path, th, k):
    if path[0][2] == '{': closed = 0
    else: closed = 1
    n = len(path)
    v = zeros(n * 2, Float)
    j = 0
    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)
        l = chord_len / hypot(pside[-1][0] + mside[-1][0],
                              pside[-1][1] + mside[-1][1])
        k1l = (ks[1] - .5 * ks[2] + .125 * ks[3]) / (l * l)
        k1r = (ks[1] + .5 * ks[2] + .125 * ks[3]) / (l * l)
        k2l = (ks[2] - .5 * ks[3]) / (l * l * l)
        k2r = (ks[2] + .5 * ks[3]) / (l * l * l)

        if t0 == 'o' or t0 == '[' or t0 == 'v':
            v[2 * j] -= k1l
            v[2 * j + 1] -= k2l
        elif t0 == 'c':
            v[2 * j + 1] += k2l

        if t1 == 'o' or t1 == ']' or t1 == 'v':
            v[2 * j1] += k1r
            v[2 * j1 + 1] += k2r
        elif t1 == 'c':
            v[2 * j1] += k2r

        print "% left k'", k1l, "k''", k2l, "right k'", k1r, "k''", k2r
        if t1 == 'v':
            j += 2
        else:
            j += 1
    print '% error vector:'
    for i in range(n):
        print '%  ', v[2 * i], v[2 * i + 1]
    return v
Exemplo n.º 2
0
def make_error_vec(path, th, k):
    if path[0][2] == '{': closed = 0
    else: closed = 1
    n = len(path)
    v = zeros(n * 2, Float)
    j = 0
    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)
        l = chord_len / hypot(pside[-1][0] + mside[-1][0], pside[-1][1] + mside[-1][1])
        k1l = (ks[1] - .5 * ks[2] + .125 * ks[3]) / (l * l)
        k1r = (ks[1] + .5 * ks[2] + .125 * ks[3]) / (l * l)
        k2l = (ks[2] - .5 * ks[3]) / (l * l * l)
        k2r = (ks[2] + .5 * ks[3]) / (l * l * l)

        if t0 == 'o' or t0 == '[' or t0 == 'v':
            v[2 * j] -= k1l
            v[2 * j + 1] -= k2l
        elif t0 == 'c':
            v[2 * j + 1] += k2l

        if t1 == 'o' or t1 == ']' or t1 == 'v':
            v[2 * j1] += k1r
            v[2 * j1 + 1] += k2r
        elif t1 == 'c':
            v[2 * j1] += k2r

        print "% left k'", k1l, "k''", k2l, "right k'", k1r, "k''", k2r
        if t1 == 'v':
            j += 2
        else:
            j += 1
    print '% error vector:'
    for i in range(n):
        print '%  ', v[2 * i], v[2 * i + 1]
    return v
Exemplo n.º 3
0
def plot_path(path, th, k):
    if path[0][2] == '{': closed = 0
    else: closed = 1
    j = 0
    cmd = 'moveto'
    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)
        mside.reverse()
        for i in range(len(mside)):
            mside[i] = (-mside[i][0], -mside[i][1])
        pts = mside + pside[1:]
        rot = chord_th - atan2(pts[-1][1] - pts[0][1], pts[-1][0] - pts[0][0])
        scale = hypot(x1 - x0, y1 - y0) / hypot(pts[-1][1] - pts[0][1],
                                                pts[-1][0] - pts[0][0])
        u, v = scale * cos(rot), scale * sin(rot)
        xt = x0 - u * pts[0][0] + v * pts[0][1]
        yt = y0 - u * pts[0][1] - v * pts[0][0]
        for x, y in pts:
            print xt + u * x - v * y, yt + u * y + v * x, cmd
            cmd = 'lineto'
        if t1 == 'v':
            j += 2
        else:
            j += 1
    print 'stroke'
    if 0:
        j = 0
        for i in range(len(path)):
            x0, y0, t0 = path[i]
            print 'gsave', x0, y0, 'translate'
            print ' ', th[j] * 180 / pi, 'rotate'
            print '  -50 0 moveto 50 0 lineto stroke'
            print 'grestore'
            j += 1
Exemplo n.º 4
0
def plot_path(path, th, k):
    if path[0][2] == '{': closed = 0
    else: closed = 1
    j = 0
    cmd = 'moveto'
    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)
        mside.reverse()
        for i in range(len(mside)):
            mside[i] = (-mside[i][0], -mside[i][1])
        pts = mside + pside[1:]
        rot = chord_th - atan2(pts[-1][1] - pts[0][1], pts[-1][0] - pts[0][0])
        scale = hypot(x1 - x0, y1 - y0) / hypot(pts[-1][1] - pts[0][1], pts[-1][0] - pts[0][0])
        u, v = scale * cos(rot), scale * sin(rot)
        xt = x0 - u * pts[0][0] + v * pts[0][1]
        yt = y0 - u * pts[0][1] - v * pts[0][0]
        for x, y in pts:
            print xt + u * x - v * y, yt + u * y + v * x, cmd
            cmd = 'lineto'
        if t1 == 'v':
            j += 2
        else:
            j += 1
    print 'stroke'
    if 0:
        j = 0
        for i in range(len(path)):
            x0, y0, t0 = path[i]
            print 'gsave', x0, y0, 'translate'
            print ' ', th[j] * 180 / pi, 'rotate'
            print '  -50 0 moveto 50 0 lineto stroke'
            print 'grestore'
            j += 1
Exemplo n.º 5
0
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'
Exemplo n.º 6
0
def make_matrix(path, th, k):
    if path[0][2] == '{': closed = 0
    else: closed = 1
    n = len(path)
    m = zeros((n * 2, n * 2), Float)
    j = 0
    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)
        l = chord_len / hypot(pside[-1][0] + mside[-1][0],
                              pside[-1][1] + mside[-1][1])

        if t0 == 'o' or t0 == '[' or t0 == 'v':
            add_k1l(m, 2 * j, j, j1, l, -1)
            add_k2l(m, 2 * j + 1, j, j1, l, -1)
        elif t0 == 'c':
            add_k2l(m, 2 * j + 1, j, j1, l, 1)

        if t1 == 'o' or t1 == ']' or t1 == 'v':
            add_k1r(m, 2 * j1, j, j1, l, 1)
            add_k2r(m, 2 * j1 + 1, j, j1, l, 1)
        elif t1 == 'c':
            add_k2r(m, 2 * j1, j, j1, l, 1)

        if t1 == 'v':
            j += 2
        else:
            j += 1
    return m
Exemplo n.º 7
0
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'
Exemplo n.º 8
0
def make_matrix(path, th, k):
    if path[0][2] == '{': closed = 0
    else: closed = 1
    n = len(path)
    m = zeros((n * 2, n * 2), Float)
    j = 0
    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)
        l = chord_len / hypot(pside[-1][0] + mside[-1][0], pside[-1][1] + mside[-1][1])

        if t0 == 'o' or t0 == '[' or t0 == 'v':
            add_k1l(m, 2 * j, j, j1, l, -1)
            add_k2l(m, 2 * j + 1, j, j1, l, -1)
        elif t0 == 'c':
            add_k2l(m, 2 * j + 1, j, j1, l, 1)

        if t1 == 'o' or t1 == ']' or t1 == 'v':
            add_k1r(m, 2 * j1, j, j1, l, 1)
            add_k2r(m, 2 * j1 + 1, j, j1, l, 1)
        elif t1 == 'c':
            add_k2r(m, 2 * j1, j, j1, l, 1)

        if t1 == 'v':
            j += 2
        else:
            j += 1
    return m