Exemplo n.º 1
0
def PointInsidePolygon(p: point, poly: Polygon):

    extremePoint = point(inf, p.y)
    s = segment(p, extremePoint)

    i = 0  # number of intersections of extreme point and sides od Polygon
    counter = 0
    length = len(poly.points)

    while i < length:
        s1 = segment(poly.points[i], poly.points[(i + 1) % length])

        if intersection(s, s1):

            counter = counter + 1
            if orientation(poly.points[i], p, poly.points[(i + 1) % length]) == 0:
                # print('collinear')
                return False
                    #onSegment(poly.points[i], poly.points[(i + 1) % length], p)
        i += 1
    # print(counter)
    if counter % 2 == 0:
        return False
    else:
        return True
Exemplo n.º 2
0
    def drawTwo(self, canvas) -> None:
        """
        Draws polygon object onto the canvas.Takes translation into
        consideration.

        Args:
            canvas: Canvas object on which line segment will be drawn to.
        """

        first = self.points[0]

        for i in range(0, len(self.points) - 1):
            segment(self.points[i], self.points[i + 1]).drawSec(canvas)

        segment(self.points[-1], first).drawSec(canvas)
Exemplo n.º 3
0
 def GetEdges(self) -> list:
     edges = []
     i = 0
     length = self.points.__len__()
     while i < length:
         s = segment(self.points[i], self.points[(i + 1) % length])
         i += 1
     return edges
Exemplo n.º 4
0
 def draw(self):
     i = 0
     length = self.points.__len__()
     while i < length:
         s = segment(self.points[i], self.points[(i + 1) % length])
         s.draw()
         i += 1
     turtle.done()
Exemplo n.º 5
0
def IntersectionP1(p: Polygon, s: segment) -> bool:
    i = 0
    counter = 0
    length = len(p.points)
    while i < length:
        s1 = segment(p.points[i], p.points[(i + 1) % length])

        if real_intersection(s1, s):
            #counter = counter + 1
            return True
        i += 1
    # print(counter) check how many times segment intersect with polygon

    return False
Exemplo n.º 6
0
def run_naive_algorithm(filename)-> List[point]:

    input_list = create_coordinates(filename)
    guards = []
    visible_vertex = []

    polygon = Polygon(input_list)

    polygon_vertices = input_list

    while len(visible_vertex) < len(polygon_vertices):

        print("novi while")
        random_guard = generate_point_inside_polygon(filename, polygon)
        print("izabrao random tacku")

        for vertex in polygon_vertices:
            print("vertex", vertex)

            if vertex not in visible_vertex:
                s = segment(random_guard, vertex)
                p1 = point((vertex.x + random_guard.x)/2, (vertex.y+random_guard.y)/2)

                if not IntersectionP1(polygon, s) and PointInsidePolygon(p1, polygon):
                    visible_vertex.append(vertex)
                    if random_guard not in guards:
                        guards.append(random_guard)
                        print("dosao do guarda")

                    # slucaj kada se segmenti preklapaju, tj kada cuvar sa refleksne ivice vidi susjedni vrh
                else:
                    for i in range(0, len(polygon.points)):
                        seg = segment(polygon.points[i], polygon.points[(i + 1) % len(polygon.points)])
                        if same_segments(seg, s):
                            visible_vertex.append(vertex)

    return guards
Exemplo n.º 7
0
        while orientation(s.next_to_top(), s.peek(), input_list1[i]) < 0:
            s.pop()
            # print(s.next_to_top(), s.peek(), input_list1[i])

        s.push(input_list1[i])

    l = []

    while not s.is_empty():
        l.append(s.peek())
        s.pop()
    return Polygon(l)


s = segment(point(0, 0), point(5, 5))

s1 = segment(point(5, 5), point(5, 10))

# print(intersection(s, s1))



#-----------------------------------

# generate polygon

#---------------------------------------


def generate_polygon() -> Polygon:
Exemplo n.º 8
0
 def get_sides(self) -> List[segment]:
     return [segment(self.first, self.second),
             segment(self.second, self.third),
             segment(self.third, self.first)]