Example #1
0
def construct_polygon(
    prop: CSProperties,
    points: List[Coordinate2],
    normal: Axis,
    elevation: float,
    priority: int,
    transform: CSTransform = None,
):
    """
    """
    poly_points = _poly_points(points)
    if transform is None:
        prim = _add_polygon(
            prop=prop,
            priority=priority,
            points=poly_points,
            norm_dir=normal.intval(),
            elevation=elevation,
        )
        return prim

    fp_warning(construct_polygon)

    first_coord_center = np.average(poly_points[0])
    second_coord_center = np.average(poly_points[1])
    if normal.intval() == 0:
        center = Coordinate3(
            elevation, first_coord_center, second_coord_center
        )
    elif normal.intval() == 1:
        center = Coordinate3(
            first_coord_center, elevation, second_coord_center
        )
    else:
        center = Coordinate3(
            first_coord_center, second_coord_center, elevation
        )

    centered_pts = [
        np.subtract(pts, cent)
        for pts, cent in zip(
            poly_points, [first_coord_center, second_coord_center]
        )
    ]

    prim = _add_polygon(
        prop=prop,
        priority=priority,
        points=centered_pts,
        norm_dir=normal.intval(),
        elevation=0,
    )
    apply_transform(prim, transform)
    tr = CSTransform()
    tr.AddTransform("Translate", center.coordinate_list())
    apply_transform(prim, tr)

    return prim
Example #2
0
def construct_circle(
    prop: CSProperties,
    center: C3Tuple,
    radius: float,
    normal: Axis,
    priority: int,
    poly_faces: float = 60,
    transform: CSTransform = None,
) -> CSPrimitives:
    """
    :param normal: Normal direction to the surface of the circle. 0, 1, or 2.
    :param poly_faces: A circle is actually drawn as a polygon.  This
        specifies the number of polygon faces.  Obviously, the greater
        the number of faces, the more accurate the circle.
    """
    center = c3_maybe_tuple(center)
    prim = construct_polygon(
        prop=prop,
        points=_circle_points(
            center=center, radius=radius, normal=normal, poly_faces=poly_faces,
        ),
        normal=normal,
        elevation=center[normal.intval()],
        priority=priority,
        transform=transform,
    )

    return prim
Example #3
0
def _circle_points(
    center: C3Tuple, radius: float, normal: Axis, poly_faces: int
) -> List[Coordinate2]:
    """
    """
    pts1 = np.multiply(radius, np.cos(np.linspace(0, 2 * np.pi, poly_faces)))
    pts2 = np.multiply(radius, np.sin(np.linspace(0, 2 * np.pi, poly_faces)))
    if normal.intval() == 0:
        pts1 += center.y
        pts2 += center.z
    elif normal.intval() == 1:
        pts1 += center.x
        pts2 += center.z
    else:
        pts1 += center.x
        pts2 += center.y

    lst = []
    for pt1, pt2 in zip(pts1, pts2):
        lst.append(Coordinate2(pt1, pt2))

    return lst