Exemplo n.º 1
0
def pd_isotopy(knot):
    cross_info = []
    ne = knot.nedges
    for a in knot.crossings:
        temp = [-1, -1, -1, -1, -1]
        for b in range(2):
            temp[a.overstrand_pos()[b]] = a.overstrand_indices()[b]
        for b in range(2):
            temp[a.understrand_pos()[b]] = a.understrand_indices()[b]
        temp[4] = a.sign
        cross_info.append(temp)
    verts = []
    for a in cross_info:
        new_vert = []
        for b in range(4):
            old_val = a[b]
            new_vert.append((old_val + 1) % ne)

        while new_vert[0] > new_vert[1] or new_vert[0] > new_vert[
                2] or new_vert[0] > new_vert[3]:
            new_vert = [new_vert[1], new_vert[2], new_vert[3], new_vert[0]]

        new_vert.append(a[4])
        verts.append(new_vert)
    verts.sort()
    knot2 = PlanarDiagram.from_pdcode(verts)
    for a in range(len(verts)):
        knot2.crossings[a].sign = verts[a][4]
    return knot2
Exemplo n.º 2
0
def odd_point_star(k, permutation=[]):
    # This function creates a simple odd pointed star diagram in the same
    # fashion as the Petaluma model.
    # odd_point_star(number of sticks , permutation) yields a Planar Diagram object.
    if permutation == []:
        permutation = numpy.random.permutation(k)
    SS = []
    p = permutation
    for e in range(k):
        for e1 in range(k):
            if (permutation[e] == permutation[e1]) and (e != e1):
                print 'This is not a correct permutation'
                return 'error'
    if len(p) != k:
        print 'This is not a correct permutation'
        return 'error'
    for m in range(k):
        for i in range((k - 3) / 2):
            SS.append((m + (k - 2 * i - 3)) % k)
        for i in range((k - 3) / 2):
            SS.append((m + (k - 2 * i - 2)) % k)
            Stick_crossing_order = {}
        for m in range(k):
            Stick_crossing_order[m] = SS[(((k - 3) * m)):((k - 3) * (m + 1))]
    ES = []
    for y in range(k):
        for x in range(k - 2):
            ES.append((x + (k - 3) * y) % (k * (k - 3)))
    edges_stick = {}
    for z in range(k):
        edges_stick[z] = ES[(z * (k - 2)):(z * (k - 2) + (k - 2))]

    nv = (((k * k) - (3 * k)) / 2)
    count = -1
    total = {}
    crossing_values = []
    for stick in range(k):
        for position in range(k - 3):
            x = Stick_crossing_order[Stick_crossing_order[stick]
                                     [position]].index(stick)
            if x < (k - 3) / 2:
                edge_and_next = [
                    edges_stick[Stick_crossing_order[stick][position]][x],
                    edges_stick[Stick_crossing_order[stick][position]][x + 1]
                ]
            if x >= (k - 3) / 2:
                edge_and_next = [
                    edges_stick[Stick_crossing_order[stick][position]][x + 1],
                    edges_stick[Stick_crossing_order[stick][position]][x]
                ]

            if stick < Stick_crossing_order[stick][position]:
                if ((stick % 2) == 0) and (
                    (Stick_crossing_order[stick][position] % 2) == 0):
                    if p[stick] < p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(True)
                    if p[stick] > p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(False)
                    if p[stick] == p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append('skip1')
                if ((stick % 2) == 0) and (
                    (Stick_crossing_order[stick][position] % 2) == 1):
                    if p[stick] > p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(True)
                    if p[stick] < p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(False)
                    if p[stick] == p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append('skip2')
                if ((stick % 2) == 1) and (
                    (Stick_crossing_order[stick][position] % 2) == 0):
                    if p[stick] > p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(True)
                    if p[stick] < p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(False)
                    if p[stick] == p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append('skip3')
                if ((stick % 2) == 1) and (
                    (Stick_crossing_order[stick][position] % 2) == 1):
                    if p[stick] < p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(True)
                    if p[stick] > p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(False)
                    if p[stick] == p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append('skip4')

            if stick > Stick_crossing_order[stick][position]:
                if ((stick % 2) == 0) and (
                    (Stick_crossing_order[stick][position] % 2) == 0):
                    if p[stick] > p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(True)
                    if p[stick] < p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(False)
                    if p[stick] == p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append('skip5')
                if ((stick % 2) == 0) and (
                    (Stick_crossing_order[stick][position] % 2) == 1):
                    if p[stick] < p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(True)
                    if p[stick] > p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(False)
                    if p[stick] == p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append('skip6')
                if ((stick % 2) == 1) and (
                    (Stick_crossing_order[stick][position] % 2) == 0):
                    if p[stick] < Stick_crossing_order[stick][position]:
                        edge_and_next.append(True)
                    if p[stick] > p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(False)
                    if p[stick] == p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append('skip7')
                if ((stick % 2) == 1) and (
                    (Stick_crossing_order[stick][position] % 2) == 1):
                    if p[stick] > p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(True)
                    if p[stick] < p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(False)
                    if p[stick] == p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append('skip8')

            if stick == Stick_crossing_order[stick][position]:
                edge_and_next.append('skip9')
            if len(edge_and_next) != 3:
                edge_and_next.append('skip10')
            count += 1
            total[count] = edge_and_next
    temp_vert = []
    verts = []
    for x in range(2 * nv):
        verts.append([
            x % (2 * nv), (total[x][0]) % (2 * nv), (x + 1) % (2 * nv),
            (total[x][1]) % (2 * nv), total[x][2]
        ])

    for z in range(2 * nv):
        if verts[z][4] == True:
            verts[z][4] = 1
        if verts[z][4] == False:
            verts[z][4] = 0
        if verts[z][4] == 'skip':
            print 'skipped'
            del (verts[z])
            verts.insert(z, [0, 0, 0, 0])
    for t in range(8 * nv):
        if (verts[t % (2 * nv)][0] <= verts[t % (2 * nv)][1]) and (
                verts[t % (2 * nv)][0] <= verts[t % (2 * nv)][2] and
            (verts[t % (2 * nv)][0] <= verts[t % (2 * nv)][3])):
            continue
        if (verts[t % (2 * nv)][0] >= verts[t % (2 * nv)][1]) or (
                verts[t % (2 * nv)][0] >= verts[t % (2 * nv)][2] or
            (verts[t % (2 * nv)][0] >= verts[t % (2 * nv)][3])):
            temp_vert = [
                verts[t % (2 * nv)][1], verts[t % (2 * nv)][2],
                verts[t % (2 * nv)][3], verts[t % (2 * nv)][0],
                verts[t % (2 * nv)][4]
            ]
            verts[t % (2 * nv)] = [
                temp_vert[0], temp_vert[1], temp_vert[2], temp_vert[3],
                temp_vert[4]
            ]
    ne = 2 * nv
    for clean_up in range(ne):
        for search in range(ne):
            if (([
                    verts[clean_up][0], verts[clean_up][1], verts[clean_up][2],
                    verts[clean_up][3]
            ] == [
                    verts[search][0], verts[search][1], verts[search][2],
                    verts[search][3]
            ]) and (clean_up != search)) and ([
                    verts[clean_up][0], verts[clean_up][1], verts[clean_up][2],
                    verts[clean_up][3]
            ] != [0, 0, 0, 0]):
                del (verts[search])
                verts.insert(search, [0, 0, 0, 0])
    count = 0
    for clean_up_2 in range(ne * ne):
        if verts[clean_up_2 % ne] == [0, 0, 0, 0]:
            del (verts[clean_up_2 % ne])
            verts.append([])
            count = 0
        count += 1
        if count >= (ne + 1):
            break
    del (verts[nv:ne])
    for r in range(nv):
        if verts[r][0] == 0 and r != 0:
            temp = verts[r]
            del (verts[r])
            verts.insert(0, temp)
    knot = PlanarDiagram.from_pdcode(verts)
    for v in range(nv):
        knot.crossings[v].sign = verts[v][4]
    return knot
Exemplo n.º 3
0
def complex_star(number_of_sticks, *args):

    # First I want to create the equations of each line of the shadows.
    sticks = {
    }  # Creating a dictionary to keep track of which stick goes with which equation.
    k = number_of_sticks
    n = (k - 1) / 2
    permutation_1 = []
    permutation_2 = []
    mapping = []
    if 'args' in locals():
        for ar in range(len(args)):
            if type(args[ar]) == list and permutation_1 == [] and len(
                    args[ar]) == k:
                permutation_1 = args[ar]
            elif type(args[ar]) == list and permutation_1 != [] and len(
                    args[ar]) == k:
                permutation_2 = args[ar]
            elif type(args[ar]) == list:
                print "Incorrect Permutations"
            else:
                mapping = int(args[ar])
    if mapping == []:
        mapping = n
    else:
        mapping = int(mapping)
    if permutation_1 == []:
        permutation_1 = numpy.random.permutation(k)
    if permutation_2 == []:
        permutation_2 = numpy.random.permutation(k)
    delt_ang = (2 * pi) / k
    # Creates the change in angle to find the points.
    x_1 = {}
    x_2 = {}
    y_1 = {}
    y_2 = {}
    z_1 = {}
    z_2 = {}
    m = {}
    delt_x = {}
    delt_y = {}
    delt_z = {}
    circ_points = {}
    for p in range(k):
        x_1[p] = 10000 * cos(((mapping * p) % k) * delt_ang)
        x_2[p] = 10000 * cos(((mapping * p + mapping) % k) * delt_ang)
        y_1[p] = 10000 * sin(((mapping * p) % k) * delt_ang)
        y_2[p] = 10000 * sin(((mapping * p + mapping) % k) * delt_ang)
        z_1[p] = permutation_1[p]
        z_2[p] = permutation_2[p]
        delt_x[p] = x_2[p] - x_1[p]
        delt_y[p] = y_2[p] - y_1[p]
        delt_z[p] = z_2[p] - z_1[p]
        m[p] = (y_2[p] - y_1[p]) / (x_2[p] - x_1[p])
        circ_points[p] = [
            10000 * cos(p * delt_ang), 100000 * sin(p * delt_ang)
        ]

    def find_int_xy(
        a, b, m, x_1, y_1, circ_points, k
    ):  #To find the intersection between two sticks a and b *add in stick numbering errors and gives the
        if m[a] == m[b]:
            print 'AHHH', a, b
        x = (m[a] * x_1[a] - m[b] * x_1[b] + y_1[b] - y_1[a]) / (m[a] - m[b])
        y = m[a] * (x - x_1[a]) + y_1[a]
        point = [x, y]
        return point

    stick_pairs_heights = {}
    vertex_positions = {}
    t_value_y = {}
    heights_for_inter = {}
    t_values = {}
    stick_ints = {}
    for pair in range(k):
        for pair2 in range(
                k - 3
        ):  #this would be a nice place to order the intersections in the correct order...
            #The mapping MUST come into play here as well, solution is to find the intersection of EACH combination.
            vertex_positions[str(pair) + ',' + str(
                (pair + pair2 + 2) % k
            )] = find_int_xy(
                pair,
                (pair + pair2 + 2) %
                k, m, x_1, y_1, circ_points,
                k
            )  #the order        t_value_x[str(pair)+','+str((pair + pair2 + 2)%k)] = (vertex_positions[str(pair)+','+str((pair + pair2 + 2)%k)][0]-x_1[pair])/(x_2[pair]-x_1[pair])
            t_value_y[str(pair) + ',' + str(
                (pair + pair2 + 2) %
                k)] = (vertex_positions[str(pair) + ',' + str(
                    (pair + pair2 + 2) % k)][1] - y_1[pair]) / (y_2[pair] -
                                                                y_1[pair])
            t_value_x = t_value_y
            # Note: the t value for each stick "Should" be consistent regardless of x,y, or z..
        t_values[pair] = []
        for pair2 in range(k - 3):
            t_values[pair].append((t_value_x[str(pair) + ',' + str(
                (pair + pair2 + 2) % k)], (pair + pair2 + 2) % k))
            stick_pairs_heights[str(pair) + ',' + str(
                (pair + pair2 + 2) % k)] = (z_1[pair] +
                                            t_value_x[str(pair) + ',' + str(
                                                (pair + pair2 + 2) % k)] *
                                            (delt_z[pair]),
                                            z_1[(pair + pair2 + 2) % k] +
                                            t_value_x[str(pair) + ',' + str(
                                                (pair + pair2 + 2) % k)] *
                                            (delt_z[(pair + pair2 + 2) % k]))
        t_values[pair].sort()
        stick_ints[pair] = []
        for stick in range(len(t_values[pair])):
            stick_ints[pair].append(t_values[pair][stick][1])
    #Now to create the edge information for each stick..
    edges_per_stick = []
    ne = k * k - 3 * k
    for stick in range(k):
        temp = []
        for edge in range(k - 2):
            temp.append((stick * (k - 3) + edge) % ne)
        edges_per_stick.append(temp)
    #Now that we have all of the information needed let's create the vertices!
    vertices = []
    count = 0
    for stick in range(k):
        for position in range(k - 3):
            if ((stick_ints[stick][position] % 2 == 0 and stick % 2 == 0) or
                (stick % 2 == 1 and stick_ints[stick][position] % 2 == 1)):
                x = 1
                y = 0
                if stick_pairs_heights[str(stick) + ',' + str(
                        stick_ints[stick][position])][0] < stick_pairs_heights[
                            str(stick) + ',' +
                            str(stick_ints[stick][position])][1]:
                    v = 1
                if stick_pairs_heights[str(stick) + ',' + str(
                        stick_ints[stick][position])][0] > stick_pairs_heights[
                            str(stick) + ',' +
                            str(stick_ints[stick][position])][1]:
                    v = 0
            if (stick_ints[stick][position] % 2 == 0 and stick % 2 == 1) or (
                    stick % 2 == 0 and stick_ints[stick][position] % 2 == 1):
                x = 0
                y = 1
                if stick_pairs_heights[str(stick) + ',' + str(
                        stick_ints[stick][position])][0] < stick_pairs_heights[
                            str(stick) + ',' +
                            str(stick_ints[stick][position])][1]:
                    v = 0
                if stick_pairs_heights[str(stick) + ',' + str(
                        stick_ints[stick][position])][0] > stick_pairs_heights[
                            str(stick) + ',' +
                            str(stick_ints[stick][position])][1]:
                    v = 1
            vertices.append([
                edges_per_stick[stick][position],
                edges_per_stick[t_values[stick][position][1]][
                    stick_ints[t_values[stick][position][1]].index(stick) + x],
                edges_per_stick[stick][position + 1],
                edges_per_stick[t_values[stick][position][1]]
                [stick_ints[t_values[stick][position][1]].index(stick) + y], v
            ])
    final_verts = []
    for cutting in range((k * (k - 3)) / 2):
        final_verts.append(vertices[cutting])
    while final_verts[(k * (k - 3)) / 2 - 1][0] != 0:
        final_verts[(k * (k - 3)) / 2 - 1] = [
            final_verts[(k * (k - 3)) / 2 - 1][1],
            final_verts[(k * (k - 3)) / 2 - 1][2],
            final_verts[(k * (k - 3)) / 2 - 1][3],
            final_verts[(k * (k - 3)) / 2 - 1][0],
            final_verts[(k * (k - 3)) / 2 - 1][4]
        ]
    final_verts.insert(0, final_verts[(k * (k - 3)) / 2 - 1])
    final_verts.pop((k * (k - 3)) / 2)
    knot = PlanarDiagram.from_pdcode(final_verts)
    return knot