コード例 #1
0
def create_segments(segment, ref=None):
    """Creates Segment list breaking the segment if direction [1, 0] intersects
    it. This function is used to avoid the case in which the points are sorted
    counterclockwise with reference to ref and theta1 > theta2.
    """
    if ref is None:
        ref = np.array([0, 0])

    p1 = segment.p1
    p2 = segment.p2
    x1 = p1[0] - ref[0]
    y1 = p1[1] - ref[1]
    x2 = p2[0] - ref[0]
    y2 = p2[1] - ref[1]

    if x1 * y2 - x2 * y1 < 0:
        p1, p2 = p2, p1
        x1, y1, x2, y2 = x2, y2, x1, y1

    theta1 = my_atan2(y1, x1)
    theta2 = my_atan2(y2, x2)

    hor = np.array([1, 0])
    intersects, intersection = segment.intersect(ref, hor)
    if intersects:
        if abs(theta2) < EPS and abs(theta1) > EPS:
            return [Segment(p1, p2, theta1, 2 * math.pi, ref)]
        elif abs(theta1) < EPS and abs(theta2) > EPS:
            return [Segment(p1, p2, 0, theta2, ref)]
        return [
            Segment(intersection, p2, 0, theta2, ref),
            Segment(p1, intersection, theta1, 2 * math.pi, ref),
        ]
    return [Segment(p1, p2, theta1, theta2, ref)]
コード例 #2
0
ファイル: segment.py プロジェクト: Marcompp/Projeto2Robotica
 def theta2(self):
     if self._theta2 is None:
         self._theta2 = my_atan2(self.p2[1] - self.ref[1],
                                 self.p2[0] - self.ref[0])
         if self._theta2 < EPS and self._theta2 < self._theta1:
             self._theta2 = 2 * math.pi
     return self._theta2
コード例 #3
0
def create_intersecting_segments(pts1, pts2, segs1, segs2, angles, ref):
    """Creates list with the Segments that are visible from ref for the case
    when the two line segments intersect. In counterclockwise order pts1 is
    initially closer to ref, then, after the intersection, pts2 is closer to
    ref.

    Args:
        pts1 (list[np.array]): list of 2D points that are the intersection of
            the rays from ref in the directions indicated by angles with the
            first Segment
        pts2 (list[np.array]): list of 2D points that are the intersection of
            the rays from ref in the directions indicated by angles with the
            second Segment
        segs1 (list[Segment]): list of Segment between the points in pts1
        segs2 (list[Segment]): list of Segment between the points in pts2
        angles (list[float]): list of directions (radians) of the rays from ref
            the angles are obtained from the two extremes of each original
            Segment. The list always has 4 elements (even if repeated)
        ref (np.array): reference point
    """
    inters = segs1[1].intersect(segs2[1].p1, segs2[1].p2-segs2[1].p1)[1]
    inters_centered = inters - ref
    inters_ang = my_atan2(inters_centered[1], inters_centered[0])
    segments = []
    segments.append(Segment(pts1[1], inters, angles[1], inters_ang, ref))
    segments.append(Segment(inters, pts2[2], inters_ang, angles[2], ref))
    if pts1[0] is not None:
        segments[0].merge(Segment(pts1[0], pts1[1], angles[0], angles[1], ref))
    if pts2[3] is not None:
        segments[1].merge(Segment(pts2[2], pts2[3], angles[2], angles[3], ref))
    if segs2[0] is not None:
        segments = [Segment(pts2[0], pts2[1], angles[0], angles[1], ref)] + segments
    if segs1[2] is not None:
        segments.append(Segment(pts1[2], pts1[3], angles[2], angles[3], ref))
    return segments
コード例 #4
0
def create_segments(segment, ref=None):
    """Creates Segment list breaking the segment if direction [1, 0] intersects
    it. This function is used to avoid the case in which the points are sorted
    counterclockwise with reference to ref and theta1 > theta2.
    """
    rx, ry = 0, 0
    if ref is None:
        ref = [0, 0]
    else:
        rx, ry = ref

    p1 = segment.p1
    p2 = segment.p2
    x1 = p1[0] - rx
    y1 = p1[1] - ry
    x2 = p2[0] - rx
    y2 = p2[1] - ry

    if x1 * y2 - x2 * y1 < 0:
        p1, p2 = p2, p1
        x1, y1, x2, y2 = x2, y2, x1, y1

    theta1 = my_atan2(y1, x1)
    theta2 = my_atan2(y2, x2)

    cx = _crossing_x(x1, y1, x2, y2)
    if cx > 0:
        intersection = [cx + rx, ry]
        if abs(theta2) < EPS and abs(theta1) > EPS:
            return [Segment(p1, p2, theta1, 2 * math.pi, ref)]
        elif abs(theta1) < EPS and abs(theta2) > EPS:
            return [Segment(p1, p2, 0, theta2, ref)]
        return [
            Segment(intersection, p2, 0, theta2, ref),
            Segment(p1, intersection, theta1, 2 * math.pi, ref),
        ]
    if abs(theta2) < EPS and theta2 < theta1:
        theta2 = 2 * math.pi
    return [Segment(p1, p2, theta1, theta2, ref)]
コード例 #5
0
ファイル: segment.py プロジェクト: Marcompp/Projeto2Robotica
 def theta1(self):
     if self._theta1 is None:
         self._theta1 = my_atan2(self.p1[1] - self.ref[1],
                                 self.p1[0] - self.ref[0])
     return self._theta1