Beispiel #1
0
    def on_key(*args):

        points = np.random.randint(100,700,8)
        C = CubicBezier(*points)

        plt.cla()
        plt.ion()

        cubic_bezier(C.p0,C.p1,C.p2,C.p3)

        # P = C.flatten_forward_iterative(n=50)
        # P = np.array(P)
        # polyline(P, linewidth=100, alpha=.25)
        # plt.scatter(P[:,0], P[:,1], s=25,
        #             edgecolor='k', facecolor='w', zorder=10, lw=.5)

        # P = C.flatten_iterative(flatness=.125/2, angle=10)
        # P = np.array(P)
        # polyline(P, linewidth=100, alpha=.25)
        # plt.scatter(P[:,0], P[:,1], s=25,
        #              edgecolor='k', facecolor='w', zorder=10, lw=.5)

        P = C.flatten_recursive(flatness=.25, angle=10)
        P = np.array(P)
        print len(P)
        polyline(P, linewidth=100, alpha=.25)
        plt.scatter(P[:,0], P[:,1], s=25,
                     edgecolor='k', facecolor='w', zorder=10, lw=.5)

        #A = C.flatten_behdad_arc(0.125)
        #polyarc(A, linewidth=50, alpha=.25)

        

        plt.ioff()
Beispiel #2
0
    def on_key(*args):

        P = np.random.randint(100,700,(4,2))
        C = CubicBezier(*P)

        plt.cla()
        plt.ion()

        cubic_bezier(C.p0,C.p1,C.p2,C.p3)

        # P = C.flatten_forward_iterative(n=50)
        # P = np.array(P)
        # polyline(P, linewidth=100, alpha=.25)
        # plt.scatter(P[:,0], P[:,1], s=25,
        #             edgecolor='k', facecolor='w', zorder=10, lw=.1)

        P = C.flatten_iterative(flatness=.125, angle=10)
        P = np.array(P)
        polyline(P, linewidth=100, alpha=.1)
        plt.scatter(P[:,0], P[:,1], s=25, edgecolor='k', facecolor='w', zorder=10, lw=.5)

        # P = C.flatten_recursive(flatness=.125, angle=10) 
        # P = np.array(P)
        # polyline(P, linewidth=100, alpha=.1)
        # plt.scatter(P[:,0], P[:,1], s=25, edgecolor='k', facecolor='w', zorder=10, lw=.5)

        #A = C.flatten_behdad_arc(0.125)
        #polyarc(A, linewidth=100, alpha=.1)

        print "[%d,%d %d,%d %d,%d, %d,%d] : %s" % (
            C.p0[0],C.p0[1], C.p1[0],C.p1[1],
            C.p2[0],C.p2[1], C.p3[0],C.p3[1],
            cubic_bezier_type( vec2(C.p0[0],C.p0[1]),
                               vec2(C.p1[0],C.p1[1]),
                               vec2(C.p2[0],C.p2[1]),
                               vec2(C.p3[0],C.p3[1]) ))
        print '%d points generated' % len(P)

        plt.ioff()
Beispiel #3
0
               angle0, angle1 = angle1, angle0
            d = a.distance_to_point (behdad.Point(*p))
            dmin = min(d,dmin)
        D[i] = dmin
    return D.mean(), D.std(), len(arcs)



# ------------------------------------------------------------------------------
if __name__ == '__main__':
    import matplotlib
    import matplotlib.pyplot as plt
    from cubic_bezier import CubicBezier

    p0,p1,p2,p3 = np.random.randint(100,700,(4,2))
    C = CubicBezier(p0[0],p0[1],p1[0],p1[1],p2[0],p2[1],p3[0],p3[1])

    P = C.flatten_forward_iterative(n=25)
    print polyline_to_cubic(P, p0, p1, p2, p3, n=100)

    P = C.flatten_forward_iterative(n=50)
    print polyline_to_cubic(P, p0, p1, p2, p3, n=100)

    P = C.flatten_iterative(0.125)
    print polyline_to_cubic(P, p0, p1, p2, p3, n=100)

    P = C.flatten_recursive(0.125)
    print polyline_to_cubic(P, p0, p1, p2, p3, n=100)

    A = C.flatten_behdad_arc(0.125)
    print polyarc_to_cubic(A, p0, p1, p2, p3, n=100)
Beispiel #4
0
    block = int(round(barLength*progress))
    text = "\rProgress: [%s] %.2f%% %s" % ("="*block + " "*(barLength-block), progress*100, status)
    sys.stdout.write(text)
    sys.stdout.flush()


# Forward method, n=25
# -------------------------------------
filename = 'forward-iterative-25.npy'
if not os.path.exists(filename):
    print "Computing", filename
    E1 = []
    for i in range(NTESTS):
        update_progress(i/float(NTESTS))
        p0,p1,p2,p3 = curves[i]
        C = CubicBezier(p0[0],p0[1],p1[0],p1[1],p2[0],p2[1],p3[0],p3[1])
        P = C.flatten_forward_iterative(n=n1)
        d = distance.polyline_to_cubic(P, p0, p1, p2, p3, n=100)
        E1.append(d)
    update_progress(1)
    E1 = np.array(E1)
    np.save(filename, E1)
else:
    print "Loading", filename
    E1 = np.load(filename)


# Forward method, n=50
# -------------------------------------
filename = 'forward-iterative-50.npy'
if not os.path.exists(filename):
Beispiel #5
0
                                           (barLength - block), progress * 100,
                                           status)
    sys.stdout.write(text)
    sys.stdout.flush()


# Forward method, n=25
# -------------------------------------
filename = 'forward-iterative-25.npy'
if not os.path.exists(filename):
    print "Computing", filename
    E1 = []
    for i in range(NTESTS):
        update_progress(i / float(NTESTS))
        p0, p1, p2, p3 = curves[i]
        C = CubicBezier(*curves[i])
        P = C.flatten_forward_iterative(n=n1)
        d = distance.polyline_to_cubic(P, *curves[i], n=100)
        E1.append(d)
    update_progress(1)
    E1 = np.array(E1)
    np.save(filename, E1)
else:
    print "Loading", filename
    E1 = np.load(filename)

# Forward method, n=50
# -------------------------------------
filename = 'forward-iterative-50.npy'
if not os.path.exists(filename):
    print "Computing", filename
Beispiel #6
0
#
# The views and conclusions contained in the software and documentation are
# those of the authors and should not be interpreted as representing official
# policies, either expressed or implied, of Nicolas P. Rougier.
# ----------------------------------------------------------------------------
import time
import numpy as np
from cubic_bezier import CubicBezier
from bezier_type import CubicBezierType, cubic_bezier_type

# np.random.seed(1)
n = 100000
curves = np.random.randint(0, 100, (n, 4, 2))

types = {
    CubicBezierType.arch: 0,
    CubicBezierType.line: 0,
    CubicBezierType.single: 0,
    CubicBezierType.double: 0,
    CubicBezierType.loop: 0,
    CubicBezierType.cusp: 0
}

for i in range(n):
    C = CubicBezier(*curves[i])
    t = cubic_bezier_type(*curves[i])
    types[t] += 1

for key, value in types.items():
    print "%-18s: %.2f%%" % (key, 100 * value / float(n))