|
7 | 7 | from compas.geometry import Transformation |
8 | 8 | from compas_model.datastructures import KDTree |
9 | 9 | from compas_model.elements import Element |
| 10 | +from compas_model.interactions import Contact |
10 | 11 | from compas_model.interactions import Modifier |
11 | 12 | from compas_model.materials import Material |
12 | 13 |
|
@@ -446,8 +447,32 @@ def add_modifier(self, a: Element, b: Element, modifier_type: type[Modifier] = N |
446 | 447 | self._guid_element[str(b.guid)].is_dirty = True |
447 | 448 | return node_a, node_b |
448 | 449 |
|
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) |
451 | 476 |
|
452 | 477 | # def compute_contact(self, a: Element, b: Element, type: str = "") -> tuple[int, int]: |
453 | 478 | # """Add a contact interaction between two elements. |
|
0 commit comments