Esempio n. 1
0
def draw_closed_curve(the_canvas,
                      the_x,
                      the_y,
                      fill="black",
                      px_per_segment=100,
                      width=1):
    ''' Draws closed curve based on simplicial weight interpolation
        with linear basis functions and hyperbolic weights 

        Args:
            the_canvas: Canvas to write on.
            the_x, the_y: Lists of coordinates.
            fill: Color of the curve.
            px_per_segment: Number of points calculated with mswine per segment.
            width: Witdh of the curve. 

        Returns:
            Nothing
    '''
    def k(x):  # curve weight function
        if x != 0:
            return 1 / float(x)
        else:
            return 1.0e10  # to avoid zero division

    if len(the_x) < 3 or len(the_x) != len(the_y):
        return

    x = the_x + [the_x[i] for i in range(3)]
    y = the_y + [the_y[i] for i in range(3)]
    t = [[i + 1] for i in range(len(x))]
    s1 = [[i, i + 1] for i in range(1, len(x))]
    fxi = mswine.get_linear_functions(t, x, s1)  # basis functions
    fyi = mswine.get_linear_functions(t, y, s1)  # basis functions
    ox = 'none'
    oy = 'none'
    for i in xrange(len(s1)):  # for all simplexes
        if i > 0 and i < len(
                s1) - 1:  # these simplexes are to grant smoothness only
            for j in xrange(px_per_segment + 1):
                ti1 = t[s1[i][0] - 1][0]
                ti2 = t[s1[i][1] - 1][0]
                ti = ti1 + j * float(ti2 - ti1) / px_per_segment
                F_x = mswine.F_s([ti], t, s1, fxi, k)
                F_y = mswine.F_s([ti], t, s1, fyi, k)
                if ox != 'none' and oy != 'none':
                    the_canvas.create_line(F_x,
                                           F_y,
                                           ox,
                                           oy,
                                           fill=fill,
                                           width=width)
                ox = F_x
                oy = F_y
Esempio n. 2
0
def draw_closed_curve(the_canvas, the_x, the_y, fill="black", px_per_segment=100, width=1):
    ''' Draws closed curve based on simplicial weight interpolation
        with linear basis functions and hyperbolic weights 

        Args:
            the_canvas: Canvas to write on.
            the_x, the_y: Lists of coordinates.
            fill: Color of the curve.
            px_per_segment: Number of points calculated with mswine per segment.
            width: Witdh of the curve. 

        Returns:
            Nothing
    ''' 
    def k(x):   # curve weight function
        if x!=0:
            return 1/float(x)
        else:
            return 1.0e10  # to avoid zero division

    if len(the_x)<3 or len(the_x)!=len(the_y):
        return
    
    x = the_x+[the_x[i] for i in range(3)]
    y = the_y+[the_y[i] for i in range(3)]
    t = [[i+1] for i in range(len(x))]
    s1 = [[i,i+1] for i in range(1,len(x))]
    fxi = mswine.get_linear_functions(t, x, s1)    # basis functions
    fyi = mswine.get_linear_functions(t, y, s1)    # basis functions
    ox='none'
    oy='none'
    for i in xrange(len(s1)):    # for all simplexes
        if i>0 and i<len(s1)-1: # these simplexes are to grant smoothness only
            for j in xrange(px_per_segment+1):
                ti1 = t[s1[i][0]-1][0]
                ti2 = t[s1[i][1]-1][0]
                ti = ti1 + j*float(ti2 - ti1)/px_per_segment
                F_x=mswine.F_s([ti], t, s1, fxi, k)
                F_y=mswine.F_s([ti], t, s1, fyi, k)
                if ox!='none' and oy!='none':
                    the_canvas.create_line(F_x, F_y, ox, oy, fill=fill, width=width)
                ox = F_x
                oy = F_y
Esempio n. 3
0
        canvas1.create_line(nbasis[i][0],
                            nbasis[i][1],
                            nbasis[i][0],
                            nbasis[i][1] - nbasis[i][2],
                            fill="#FFAAAA")
        canvas1.create_line(obasis[i][0],
                            obasis[i][1] - obasis[i][2],
                            nbasis[i][0],
                            nbasis[i][1] - nbasis[i][2],
                            fill="#AA2222",
                            arrow="last",
                            width=2)

    # basis functions
    # for surface
    fs = mswine.get_linear_functions(xs, ys, tris)

    # for deformation
    fdx = mswine.get_constant_functions(
        obasis, [nbasis[i][0] - obasis[i][0] for i in range(len(obasis))], [])
    fdy = mswine.get_constant_functions(
        obasis, [nbasis[i][1] - obasis[i][1] for i in range(len(obasis))], [])
    fdz = mswine.get_constant_functions(
        obasis, [nbasis[i][2] - obasis[i][2] for i in range(len(obasis))], [])

    # quasi-isometric plot
    colors = [
        "#880000", "#008800", "#000088", "#888800", "#008888", "#880088"
    ]

    def sk(x):  # common weight function
Esempio n. 4
0
    # reformate to mswine simplices
    old_tris = [[n for n in tri] for tri in tris]
    for tri in tris:
        tri[0]+=1
        tri[1]+=1
        tri[2]+=1
   
    # draw deformation basis
    for i in range(len(obasis)):
        canvas1.create_line(obasis[i][0], obasis[i][1],  obasis[i][0], obasis[i][1]-obasis[i][2], fill="#FFAAAA")
        canvas1.create_line(nbasis[i][0], nbasis[i][1],  nbasis[i][0], nbasis[i][1]-nbasis[i][2], fill="#FFAAAA")
        canvas1.create_line(obasis[i][0], obasis[i][1]-obasis[i][2],  nbasis[i][0], nbasis[i][1]-nbasis[i][2], fill="#AA2222", arrow="last", width=2)

    # basis functions
    # for surface
    fs = mswine.get_linear_functions(xs, ys, tris)

    # for deformation
    fdx = mswine.get_constant_functions(obasis, [nbasis[i][0]-obasis[i][0] for i in range(len(obasis))], [])
    fdy = mswine.get_constant_functions(obasis, [nbasis[i][1]-obasis[i][1] for i in range(len(obasis))], [])
    fdz = mswine.get_constant_functions(obasis, [nbasis[i][2]-obasis[i][2] for i in range(len(obasis))], [])


    # quasi-isometric plot
    colors=["#880000","#008800","#000088","#888800","#008888","#880088"];

    def sk(x):   # common weight function
        if x>EPS:
            return 1/float(x*x)
        else:
            return 1/EPS  # to avoid zero division