How to use compas - 10 common examples

To help you get started, we’ve selected a few compas examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github compas-dev / compas / tests / compas / datastructures / test_mesh.py View on Github external
def test_is_vertex_on_boundary():
    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.is_vertex_on_boundary(0)
    assert not mesh.is_vertex_on_boundary(15)
github compas-dev / compas / tests / compas / datastructures / test_mesh.py View on Github external
def test_faces_on_boundary():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert list(mesh.faces_on_boundary()) == [45, 46, 47, 48, 49, 50, 51, 52, 60, 70, 40, 6, 8, 2, 75, 62, 55, 59, 20, 14, 71, 13, 78, 27, 21, 15, 9, 76, 61, 3, 79, 80]
github compas-dev / compas / tests / compas / datastructures / test_mesh.py View on Github external
def test_vertex_normal():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert mesh.vertex_normal(0) == [-0.7875436283909406, 0.07148692938164082, 0.6120985642103861]
    assert mesh.vertex_normal(5) == [-0.482011312317331, -0.32250183520381565, 0.814651864963369]
github compas-dev / compas / tests / compas / datastructures / test_mesh.py View on Github external
def test_face_curvature():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert mesh.face_curvature(0) == 0.0035753184898039566

    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.face_curvature(0) == 0
github compas-dev / compas / tests / compas / datastructures / test_mesh_operations.py View on Github external
def mesh_0():
    vertices = [
        [1.0, 0.0, 0.0],
        [1.0, 2.0, 0.0],
        [0.0, 1.0, 0.0],
        [2.0, 1.0, 0.0],
        [0.0, 0.0, 0.0]
    ]
    faces = [
        [0, 1, 2],
        [0, 3, 1]
    ]

    return Mesh.from_vertices_and_faces(vertices, faces)
github compas-dev / compas / docs / examples / plotter / network-shortest-path.py View on Github external
"""

from random import choice

import compas

from compas.utilities import pairwise
from compas.datastructures import Network
from compas.topology import dijkstra_path
from compas_plotters import NetworkPlotter


# make a network from a sample file

network = Network.from_obj(compas.get('grid_irregular.obj'))


# start and end

leaves = list(network.vertices_where({'vertex_degree': 1}))

start = end = 0
while start == end:
    start = choice(leaves)
    end = choice(leaves)

# construc an adjacency dict
# add weight to the edges corresponding to their length
# compute the shortest path

adjacency = {key: network.vertex_neighbors(key) for key in network.vertices()}
github compas-dev / compas / tests / compas / geometry / test_basics.py View on Github external
def test_centroid_points(points, centroid):
    if centroid is None:
        x, y, z = 0.0, 0.0, 0.0
    else:
        x, y, z = centroid
    assert centroid_points(points) == [pytest.approx(x, 0.001), pytest.approx(y, 0.001), pytest.approx(z, 0.001)]
github compas-dev / compas / tests / compas / datastructures / test_network.py View on Github external
def k5_network():
    network = Network()
    network.add_edge('a', 'b')
    network.add_edge('a', 'c')
    network.add_edge('a', 'd')
    network.add_edge('a', 'e')

    network.add_edge('b', 'c')
    network.add_edge('b', 'd')
    network.add_edge('b', 'e')

    network.add_edge('c', 'd')
    network.add_edge('c', 'e')

    network.add_edge('d', 'e')

    return network
github compas-dev / compas / docs / _downloads / mesh-remeshing.py View on Github external
__copyright__ = 'Copyright 2017, BRG - ETH Zurich',
__license__   = 'MIT'
__email__     = 'van.mele@arch.ethz.ch'


def callback(mesh, k, args):
    conduit = args[0]
    conduit.redraw(k)


boundary = rs.GetObject("Select Boundary Curve", 4)
length   = rs.GetReal("Select Edge Target Length", 2.0)
points   = rs.DivideCurve(boundary, rs.CurveLength(boundary) / length)

faces = mesh_delaunay_from_points(points, points)
mesh  = Mesh.from_vertices_and_faces(points, faces)

conduit = MeshConduit(mesh, refreshrate=2)

with conduit.enabled():
    trimesh_remesh(
        mesh,
        target=length,
        kmax=500,
        allow_boundary_split=True,
        allow_boundary_swap=True,
        callback=callback,
        callback_args=(conduit, )
    )

compas_rhino.mesh_draw(mesh, vertexcolor={key: '#ff0000' for key in mesh.vertices_on_boundary()})
github compas-dev / compas / src / compas / numerical / algorithms / dr_6dof.py View on Github external
))

    K1 = zero123
    K3 = zero123
    K2 = mdotm(-L2, (M3 * Szu + M2 * Sxu)) + mdotm(L3, (M3 * Syu - M1 * Sxu))
    K4 = mdotm( L2, (M3 * Szv - M5 * Sxv)) - mdotm(L3, (M3 * Syv + M4 * Sxv))

    Kg3 = hstack((K1, K2, K3, K4))

    K11 *= 0.
    K13 *= 0.
    K31 *= 0.
    K33 *= 0.

    Sr0Syu = mdotm(-Sr0, Syu)
    Sr0Syv = mdotm(-Sr0, Syv)
    Sr0Szu = mdotm(-Sr0, Szu)
    Sr0Szv = mdotm(-Sr0, Szv)
    Sr1Sxu = mdotm(Sr1, Sxu)
    Sr1Sxv = mdotm(Sr1, Sxv)
    Sr1Szu = mdotm(Sr1, Szu)
    Sr1Szv = mdotm(Sr1, Szv)
    Sr2Sxu = mdotm(Sr2, Sxu)
    Sr2Sxv = mdotm(Sr2, Sxv)
    Sr2Syu = mdotm(Sr2, Syu)
    Sr2Syv = mdotm(Sr2, Syv)

    K22 = +M3 * (Sr1Szu - Sr2Syu) + M2 * (Sr0Syu + Sr1Sxu) + M1 * (Sr0Szu + Sr2Sxu)
    K44 = -M3 * (Sr1Szv - Sr2Syv) + M5 * (Sr0Syv + Sr1Sxv) + M4 * (Sr0Szv + Sr2Sxv)

    Kg4 = vstack((
        hstack((K11, K12, K13, K14)),