Ejemplo n.º 1
0
def reflect(p, vector_coords):
    # Implementation of a formula
    # new_V = 2 * scalar_prod(V, Q) / scalar_prod(Q, Q) * Q - V

    # Previous direction
    v = p.direction
    # Polygon side
    q = Vector2d(vector_coords[0], vector_coords[1])

    scal = 2 * (Vector2d.scalar_product(v, q) / Vector2d.scalar_product(q, q))
    prod = Vector2d.s_mult(q, scal)
    new_direction = Vector2d.s_minus(prod, v)
    return new_direction
Ejemplo n.º 2
0
    def getLinkData(self, linkGeom):
        coords = linkGeom.coords
        start = coords[0]
        end = coords[-1]
        linkVector = Vector2d(end[0] - start[0], end[1] - start[1]).normalize()
        linkBuffer = linkGeom.envelope.buffer(maxDistance)

        return linkVector, linkBuffer
Ejemplo n.º 3
0
    def getVectors(self, intersections):
        vectors = {}

        for key, val in intersections.items():
            try:
                coords = val.coords
                start = coords[0]
                end = coords[-1]
                vectors[key] = Vector2d(end[0]-start[0], \
                    end[1]-start[1]).normalize()
            except NotImplementedError:
                pass

        return vectors
Ejemplo n.º 4
0
def on_update_board(data):
    print("Message recieved: " + str(data))
    paramsDict = supp.getParamsValMap(data)

    # get board from database
    if clients[request.sid] is not None:
        query = "select * from chess.get_current_game_board_state({0})".format(clients[request.sid])
    else:
        return
    try:
        rec = execute_one_res_async(query)
        print("Game state is " + str(rec))
        board = rec[0]
        side = int(rec[1])
    except:
        print("Game doesn't exists")
        return
    # print("server_board is " + str(rec))
    # convert to game_controller
    print("Board is " + str(board))
    print("Side is " + str(side))
    if board is not None:
        cur_game_controller = game_controller.GameController(None, str(board))
    else:
        cur_game_controller = game_controller.GameController(Board())

    move = vec.Move(vec.Vector2d(int(paramsDict['p1']), int(paramsDict['p2'])),
                    vec.Vector2d(int(paramsDict['p3']), int(paramsDict['p4'])))

    res = cur_game_controller.check_move(move, Side(side))

    if res == game_controller.MoveResult.INCORRECT:
        print("Wrong move send")
        return

    is_playing = 1
    game_result = None
    pawn_swaped_figure = paramsDict['swapped_figure']

    print('Swaped figure is ' + str(pawn_swaped_figure))

    cur_game_controller.update(move, Side(side))

    if pawn_swaped_figure is not None:
        cur_game_controller.swap_pawn(move.point_to, pawn_swaped_figure)
        res = cur_game_controller.check_board_res(Side(side))

    if res == game_controller.MoveResult.STALEMATE:
        is_playing = 0
    elif res == game_controller.MoveResult.MATE:
        is_playing = 0
        game_result = 0 if Side(side) is Side.WHITE else 1

    if game_result is None:
        execute_no_res_async("call chess.update_game_state({0}, '{1}', "
                             "{2}::bit, NULL)".format(clients[request.sid],
                                                      cur_game_controller.serialize_to_str(),
                                                      is_playing))
    else:
        execute_no_res_async("call chess.update_game_state({0}, '{1}', "
                             "{2}::bit, {3}::bit)".format(clients[request.sid],
                                                          cur_game_controller.serialize_to_str(),
                                                          is_playing,
                                                          game_result))
Ejemplo n.º 5
0
    small_polygon = [
        Point(3, 3),
        Point(4, 4),
        Point(6, 4),
        Point(7, 6),
        Point(9, 6),
        Point(7, 2),
        Point(6, 3)
    ]

    # Our points
    points_set = [
        Point(2, 2),
        Point(4, 2),
        Point(4, 5),
        Point(4, 6),
        Point(6, 6),
        Point(6, 8),
        Point(10, 2),
        Point(12, 2),
        Point(4, 5),
        Point(10, 6)
    ]

    # Set points direction
    for point in points_set:
        point.set_direction(Vector2d.get_vector(random.uniform(0, 2 * pi),
                                                0.1))

    plot_task(big_polygon, small_polygon, points_set)
Ejemplo n.º 6
0
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 29 21:54:48 2018

@author: jiyun
"""
from Vector import Vector
from Vector2d import Vector2d

v1 = Vector([3, 4, 5])

print(v1 + (1, 2, 3))
v2d = Vector2d(1, 2)
print(v1 + v2d)

#    def __radd__(self,other):
#        return self+other

print(v2d + v1)  # 역순 메서드 구현

#    def __add__(self, other):
#        try:
#            pairs = itertools.zip_longest(self, other, fillvalue = 0.0)
#            return Vector(a + b for a,b in pairs)
#        except TypeError:
#            return NotImplemented
#
#    def __radd__(self,other):
#        return self+other

#print(v1 + 1)
Ejemplo n.º 7
0
def perimeter(polygon):
    s = 0
    n = len(polygon)
    for i in range(0, n):
        s += Vector2d.get_length(polygon[i], polygon[next_el(i, n)])
    return round(s)