Ejemplo n.º 1
0
    def get_intersection_point(self, orig, end):
        p = self.points + [self.points[0]]
        points = []

        point = None

        for i in range(0, len(p) - 1):
            intersection_point = Algebra.get_intersection(
                orig, end, p[i], p[i + 1])
            if intersection_point:
                points.append(intersection_point)

        if not points:
            return None

        max_distance = Algebra.distance(orig, end)

        # Find the intersection point that is furthest away from the start
        if points:
            distances = [Algebra.distance(orig, p) for p in points]
            distances = [i for i in distances if i <= max_distance]
            if distances:
                point = points[np.argmax(distances)]

        return point
Ejemplo n.º 2
0
    def check_circles(self, triple_left, triple_right):
        node_a, node_b, node_c = triple_left
        node_d, node_e, node_f = triple_right

        left_event = CircleEvent.create_circle_event(
            node_a, node_b, node_c, sweep_line=self.sweep_line)
        right_event = CircleEvent.create_circle_event(
            node_d, node_e, node_f, sweep_line=self.sweep_line)

        # Check if the circles converge
        if left_event:
            if not Algebra.check_clockwise(
                    node_a.data.origin, node_b.data.origin, node_c.data.origin,
                    left_event.center):
                self.notify_observers(
                    Message.DEBUG,
                    payload=f"Circle {left_event.point_triple} not clockwise.")
                left_event = None

        if right_event:
            if not Algebra.check_clockwise(
                    node_d.data.origin, node_e.data.origin, node_f.data.origin,
                    right_event.center):
                self.notify_observers(
                    Message.DEBUG,
                    payload=f"Circle {right_event.point_triple} not clockwise."
                )
                right_event = None

        if left_event is not None:
            self.event_queue.put(left_event)
            node_b.data.circle_event = left_event

        if right_event is not None and left_event != right_event:
            self.event_queue.put(right_event)
            node_e.data.circle_event = right_event

        if left_event is not None:
            self.notify_observers(
                Message.DEBUG,
                payload=
                f"Left circle event created for {left_event.yd}. Arcs: {left_event.point_triple}"
            )
        if right_event is not None:
            self.notify_observers(
                Message.DEBUG,
                payload=
                f"Right circle event created for {right_event.yd}. Arcs: {right_event.point_triple}"
            )

        return left_event, right_event
Ejemplo n.º 3
0
 def get_ordered_vertices(self, vertices):
     vertices = [vertex for vertex in vertices if vertex.xd is not None]
     clockwise = sorted(
         vertices,
         key=lambda vertex:
         (-180 - Algebra.calculate_angle(vertex, self.center)) % 360)
     return clockwise
Ejemplo n.º 4
0
 def get_closest_point(position, points):
     distances = [Algebra.distance(position, p) for p in points]
     index = np.argmin(distances)
     return points[index]
Ejemplo n.º 5
0
 def order_points(self, points):
     clockwise = sorted(
         points,
         key=lambda point:
         (-180 - Algebra.calculate_angle(point, self.center)) % 360)
     return clockwise