Skip to content

Commit 92a31d5

Browse files
committed
add contact computation
1 parent e548e69 commit 92a31d5

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/compas_model/models/model.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from compas.geometry import Transformation
88
from compas_model.datastructures import KDTree
99
from compas_model.elements import Element
10+
from compas_model.interactions import Contact
1011
from compas_model.interactions import Modifier
1112
from compas_model.materials import Material
1213

@@ -446,8 +447,32 @@ def add_modifier(self, a: Element, b: Element, modifier_type: type[Modifier] = N
446447
self._guid_element[str(b.guid)].is_dirty = True
447448
return node_a, node_b
448449

449-
def compute_contacts(self):
450-
raise NotImplementedError
450+
def compute_contacts(self, tolerance=1e-6, minimum_area=1e-2, k=2) -> None:
451+
"""Compute the contacts between the block elements of this model.
452+
453+
Parameters
454+
----------
455+
tolerance : float, optional
456+
The distance tolerance.
457+
minimum_area : float, optional
458+
The minimum contact size.
459+
k : int, optional
460+
The number of element neighbours to consider.
461+
462+
Returns
463+
-------
464+
None
465+
466+
"""
467+
for element in self.elements():
468+
u = element.graphnode
469+
nnbrs = self.element_nnbrs(element, k=k)
470+
for nbr, _ in nnbrs:
471+
v = nbr.graphnode
472+
if not self.graph.has_edge((u, v), directed=False):
473+
contacts = element.contacts(nbr, tolerance=tolerance, minimum_area=minimum_area)
474+
if contacts:
475+
self.graph.add_edge(u, v, contacts=contacts)
451476

452477
# def compute_contact(self, a: Element, b: Element, type: str = "") -> tuple[int, int]:
453478
# """Add a contact interaction between two elements.

0 commit comments

Comments
 (0)