Example #1
0
        matrix : list of list
            The transformation matrix.

        Returns
        -------
        Polygon
            The transformed copy.

        """
        polygon = self.copy()
        polygon.transform(matrix)
        return polygon


# ==============================================================================
# Main
# ==============================================================================

if __name__ == '__main__':

    from compas_plotters import Plotter

    polygon = Polygon([[1, 1, 0], [0, 1, 0], [0, 0, 0], [1, 0, 0]])

    for point in polygon.points:
        print(point[0:2])

    plotter = Plotter(figsize=(10, 7))
    plotter.draw_polygons([{'points': polygon.points}])
    plotter.show()
Example #2
0
    from compas_plotters import Plotter

    plotter = Plotter(figsize=(10, 7))

    points = [[0, 0, 0], [1.0, 0, 0], [1.0, 1.0, 0], [0.5, 0.0, 0],
              [0, 1.0, 0]]
    polygon = points[::-1]

    print(polygon)
    print(area_polygon(polygon))

    n = normal_polygon(polygon, unitized=False)
    print(n)

    if n[2] > 0:
        color = '#ff0000'
    else:
        color = '#0000ff'

    polygons = [{'points': polygon}]
    points = [{
        'pos': centroid_points(polygon),
        'radius': 0.025,
        'facecolor': color
    }]

    plotter.draw_polygons(polygons)
    plotter.draw_points(points)

    plotter.show()

if __name__ == "__main__":

    # Test task 1.1
    u = [10, 10.0, 0.0]
    v = [-10.0, 10.0, 0.0]
    i, j, k = orthonormals_from_two_vectors(u, v)
    print(i, j, k)

    # Test task 1.2

    plotter = Plotter()

    my_polygon = [[0.0, 0.0], [1.0, 0.0], [1.0, 0.5], [0.5, 2.0], [0.0, 1.0]]

    plotter.draw_polygons([{'points': my_polygon}])
    plotter.show()

    print('The area of the polygon is: ', convex_polygon_area(my_polygon))
    print('The area of the polygon using compas is: ',
          convex_polygon_area_compas(my_polygon))

    # Test task 1.3
    arr_1 = [[2.0, 0.0, 0.0], [1.0, 0.0, 1.0], [1.0, 0.5, 0.0]]
    arr_2 = [[0.5, 3.0, 0.0], [1.0, 0.0, 0.0], [1.0, 5.0, 2.0]]
    ## pure python
    print(cross_array_of_vectors_py(arr_1, arr_2))
    ## using numpy
    print(cross_array_of_vectors_np(arr_1, arr_2))