コード例 #1
0
    return [x, y, z]


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

if __name__ == "__main__":

    from compas.plotters import Plotter
    from compas.geometry import intersection_line_line
    from compas.geometry import midpoint_point_point
    from compas.geometry import centroid_points
    from compas.geometry import Polyhedron

    polyhedron = Polyhedron.generate(6)

    print(centroid_polyhedron(polyhedron))

    vertices = [[1.0, 1.0, 2.0], [0.0, 0.0, 0.0], [1.0, 0.0, 2.0],
                [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [1.0, 1.0, 0.0],
                [0.0, 1.0, 1.0], [0.0, 0.0, 1.0]]

    faces = [[4, 6, 7, 1], [5, 0, 6, 4], [4, 1, 3, 5], [3, 2, 0, 5],
             [1, 7, 2, 3], [6, 0, 2, 7]]

    faces[:] = [face[::-1] for face in faces]

    polyhedron = Polyhedron.from_vertices_and_faces(vertices, faces)

    print(centroid_polyhedron(polyhedron))
コード例 #2
0

@pytest.mark.parametrize(("points"),
                         [
    [[0.0, 0.0, 0.0], [0.0, 0.0]],
    [[0.0, 0.0]],
]
)
def test_centroid_points_fails_when_input_is_not_complete_points(points):
    with pytest.raises(ValueError):
        centroid_points(points)


@pytest.mark.parametrize(("polyhedron", "centroid"),
                         [
    (Polyhedron.generate(6), [0.0, 0.0, 0.0]),
]
)
def test_centroid_polyhedron(polyhedron, centroid):
    x, y, z = centroid
    assert centroid_polyhedron(polyhedron) == [pytest.approx(x, 0.001), pytest.approx(y, 0.001), pytest.approx(z, 0.001)]


# ==============================================================================
# size
# ==============================================================================


@pytest.mark.parametrize(("polyhedron", "volume"),
                         [
    (Polyhedron.generate(6), None)
コード例 #3
0
        self.clear_faces()
        self.clear_edges()


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

if __name__ == "__main__":

    from compas.datastructures import Mesh
    from compas.geometry import Polyhedron

    from compas_rhino.helpers.artists.meshartist import MeshArtist

    poly = Polyhedron.generate(12)

    mesh = Mesh.from_vertices_and_faces(poly.vertices, poly.faces)

    artist = MeshArtist(mesh, layer='MeshArtist')

    artist.clear_layer()

    artist.draw_vertices()
    artist.redraw(0.0)

    artist.draw_vertexlabels()
    artist.redraw(1.0)

    artist.draw_faces()
    artist.redraw(1.0)
コード例 #4
0
            ab = subtract_vectors(b, a)
            ac = subtract_vectors(c, a)
            n = cross_vectors(ab, ac)
            V += dot_vectors(a, n)
    return V / 6.


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

if __name__ == "__main__":

    from compas.geometry import Polyhedron

    cube = Polyhedron.generate(6)

    L = length_vector(subtract_vectors(cube.vertices[0], cube.vertices[1]))

    V1 = L * L * L
    V2 = volume_polyhedron(cube)

    print(V1 - V2 <= 1e-6)

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

    # polygon = [
    #     [0, 0, 0],
    #     [1.0, 0, 0],
    #     [1.0, 1.0, 0],
    #     [0.5, 0.0, 0],