예제 #1
0
파일: queries.py 프로젝트: yijiangh/compas
def is_polygon_convex(polygon):
    """Determine if a polygon is convex.

    Parameters
    ----------
    polygon : sequence of sequence of floats
        The XYZ coordinates of the corners of the polygon.

    Notes
    -----
    Use this function for *spatial* polygons.
    If the polygon is in a horizontal plane, use :func:`is_polygon_convex_xy` instead.

    See Also
    --------
    is_polygon_convex_xy

    """
    c = centroid_polygon(polygon)

    for i in range(-1, len(polygon) - 1):
        p0 = polygon[i]
        p1 = polygon[i - 1]
        p2 = polygon[i + 1]
        v0 = subtract_vectors(c, p0)
        v1 = subtract_vectors(p1, p0)
        v2 = subtract_vectors(p2, p0)
        a1 = angle_vectors(v1, v0)
        a2 = angle_vectors(v0, v2)
        if a1 + a2 > pi:
            return False

    return True
예제 #2
0
파일: polygon.py 프로젝트: yijiangh/compas
 def center(self):
     """Point: The center (of mass) of the polygon."""
     return Point(*centroid_polygon(self.points))