def test_basic_functionalities(self) -> None:
        # create 3-dimnesional segment collection
        regular_triangle = RegularPolygon(3)

        coor_2d_array = vstack((regular_triangle.vertex_coor_array,
                                regular_triangle.vertex_coor_array[0]))
        coor_3d_array = hstack(
            (coor_2d_array, zeros((coor_2d_array.shape[0], 1))))

        north_point = [0, 0, sqrt(2.0)]

        seg_collection_ndim = LineSegmentNDimCollection(3, coor_3d_array)
        for idx in range(len(coor_3d_array) - 1):
            vertex = coor_3d_array[idx]
            print(vertex.shape)
            seg_collection_ndim.add_segments(vstack((vertex, north_point)))

        for segment in seg_collection_ndim.line_segment_ndim_list:
            print(segment)

        fig: Figure = get_figure(1, 2, projection="3d")
        axis1, axis2 = fig.get_axes()

        seg_collection_ndim.draw3d(axis1)
        seg_collection_ndim.draw3d(axis2)

        axis1.axis("off")

        fig.show()

        self.assertEqual(True, True)
Beispiel #2
0
    def test_get_polygon_from_edges_and_angles_with_starting_vector(self):
        start_point_list: list = list()
        start_vector_list: list = list()
        edge_list_list: list = list()
        angle_list_list: list = list()

        start_point_list.append((1, 1))
        start_vector_list.append((2, 2))
        edge_list_list.append([2, 3])
        angle_list_list.append([45, 120])

        start_point_list.append((1, 1))
        start_vector_list.append((2, 2))
        edge_list_list.append([
            5,
            (Vector2D(start_vector_list[-1]) -
             Vector2D(start_point_list[-1])).norm()
        ])
        angle_list_list.append([90, 90])

        figure = get_figure(len(start_point_list), 1)

        for idx, axis in enumerate(figure.get_axes()):
            Polygon.get_polygon_from_edges_and_angles_with_two_start_points(
                start_point_list[idx], start_vector_list[idx],
                edge_list_list[idx], angle_list_list[idx]).draw(axis)
            axis.axis("equal")

        figure.show()

        self.assertEqual(True, True)
    def test_polygon_ndim(self) -> None:
        regular_polygon = RegularPolygon(5)
        polygon_3d = Polygon2DInNDim(regular_polygon, [0.0])

        fig: Figure = get_figure(1, 1, projection="3d")
        axis, = fig.get_axes()

        polygon_3d.draw3d(axis)

        axis.axis("off")

        fig.show()

        self.assertTrue(True)
    def test_polygonal_prism_3d(self) -> None:
        polygon: Polygon = RegularPolygon(5)
        # base_polygon = Polygon([[0, 0], [1, 1], [5, 8], [-2, 10], [-3, 1]])
        polygonal_prism_3d = PolygonalPrism3D(polygon, 2.0)

        fig: Figure = get_figure(1, 1, projection="3d")
        axis, = fig.get_axes()

        polygonal_prism_3d.draw3d(axis)

        axis.axis("off")

        fig.show()

        self.assertTrue(True)
    def test_basic_transformations(self) -> None:
        regular_tetrahedron: PolygonalPyramid3D = Test3DObjectTransformation.regular_tetrahedron

        shift_vector: ndarray = Test3DObjectTransformation.SHIFT_DELTA * ones(
            regular_tetrahedron.get_num_dimensions())

        scaling: Scaling = Scaling(Test3DObjectTransformation.SCALE_FACTOR)
        shift: Shifting = Shifting(shift_vector)
        rotation: RotationAroundSubspaceAxis = RotationAroundSubspaceAxis(
            Test3DObjectTransformation.ROTATION_ANGLE, ((0, 0, 1), ))

        scaled_regular_tetrahedron: LineSegmentNDimCollection = regular_tetrahedron.apply_transformation(
            scaling)
        shifted_regular_tetrahedron: LineSegmentNDimCollection = regular_tetrahedron.apply_transformation(
            shift)
        rotated_regular_tetrahedron: LineSegmentNDimCollection = regular_tetrahedron.apply_transformation(
            rotation)

        fig: Figure = get_figure(1, 1, projection="3d")
        axis1 = fig.get_axes()[0]

        regular_tetrahedron.draw3d(axis1)

        scaled_regular_tetrahedron.draw3d(axis1)
        shifted_regular_tetrahedron.draw3d(axis1)

        for idx in range(10):
            rotated_regular_tetrahedron: LineSegmentNDimCollection = rotated_regular_tetrahedron.apply_transformation(
                rotation)
            rotated_regular_tetrahedron.draw3d(axis1)

        rotated_regular_tetrahedron.draw3d(axis1)

        axis1.axis("off")

        fig.show()

        self.assertEqual(True, True)
    # polygonal pyramids

    polygon: RegularPolygon = RegularPolygon(num_vertices, (0, 0), 1, 0.0)

    apex_x_coordinate_array: np.ndarray = np.linspace(
        -far_right_apex_x_coordinate, far_right_apex_x_coordinate,
        num_pyramids)

    polygonal_pyramid_list: List[PolygonalPyramid3D] = [
        PolygonalPyramid3D(polygon, (apex_x_coordinate, 0.0, pyramid_height))
        for apex_x_coordinate in apex_x_coordinate_array
    ]

    figure: Figure = get_figure(num_pyramids,
                                1,
                                vertical_padding=0.0,
                                projection="3d")
    idx: int
    axis: Axes
    for idx, axis in enumerate(figure.get_axes()):
        polygonal_pyramid = polygonal_pyramid_list[idx]
        polygonal_pyramid.draw3d(axis)

    figure.show()

    # polygonal pyramid nets

    polygonal_pyramid_net_list: List[GeoObjectCollection2D] = [
        polygonal_pyramid.to_2d_net()
        for polygonal_pyramid in polygonal_pyramid_list
    ]
Beispiel #7
0
    def _get_fig_and_axes(num_rows: int,
                          num_cols: int) -> Tuple[Figure, List[Axes]]:
        fig: Figure = get_figure(num_rows, num_cols)
        axes: List[Axes] = fig.get_axes()

        return fig, axes
Beispiel #8
0
from atoms.regular_polygon import RegularPolygon
from drawing.utils import get_figure
from utils import FIGURES_DIR

if __name__ == "__main__":

    num_vertices: int = 5

    polygon: RegularPolygon = RegularPolygon(num_vertices, (0, 0), 2, 0.0)
    polygon: RegularPolygon = RegularPolygon(num_vertices=5,
                                             center=(0, 1),
                                             radius=3,
                                             angle_of_one_point=60)

    figure: Figure = get_figure(1, 1)
    axis: Axes = figure.get_axes()[0]
    polygon.draw(axis)

    for angle in [0, 60, 90, 180]:
        polygon: RegularPolygon = RegularPolygon(num_vertices=5,
                                                 center=(0, 1),
                                                 radius=3,
                                                 angle_of_one_point=angle)
        polygon.draw(axis)

    axis.set_xlim((-5, 5))
    axis.set_ylim((-5, 5))

    # axis.axis("off")
    axis.axis("equal")