Closeness Constraint with Target

This example demonstrates how to use COMPAS ShapeOp to create a tensioned cable net structure with control over specific vertex positions. The example is similar to “vertex_force_and_closeness_constraint” example, but with the addition of closeness constraints with target positions and shrinking edge constraints to create tension in the structure.

../_images/closeness_constraint_with_target.png
from compas.datastructures import Mesh
from compas_viewer import Viewer

from compas_shapeop.meshsolver import MeshSolver

mesh = Mesh.from_meshgrid(10.0, 10, 10.0, 10)
mesh.translate([-5, -5, 0])

v = list(mesh.vertices_where({"vertex_degree": 2}))
p = mesh.vertices_attributes(keys=v, names="xyz")

t = [
    [p[0][0], p[0][1], 3],
    [p[1][0], p[1][1], 5],
    [p[2][0], p[2][1], 5],
    [p[3][0], p[3][1], -1],
]

s = MeshSolver(mesh)
s.fix_vertices(vertices=v, targets=t)
s.constrain_edge_lengths(shrink_factor=0.25)
s.solve(100)

viewer = Viewer()
viewer.scene.add(s.mesh)
viewer.show()