|
1 | 1 | from math import radians |
2 | 2 |
|
| 3 | +from compas.colors import Color |
3 | 4 | from compas.geometry import Box |
| 5 | +from compas.geometry import Brep |
4 | 6 | from compas.geometry import Plane |
5 | 7 | from compas.geometry import Rotation |
6 | | -from compas_occ.brep import OCCBrep as Brep |
| 8 | +from compas.geometry import is_point_infrontof_plane |
7 | 9 | from compas_viewer import Viewer |
8 | 10 |
|
9 | 11 | box = Box(1).to_brep() |
10 | 12 |
|
11 | 13 | R = Rotation.from_axis_and_angle([0, 1, 0], radians(30)) |
12 | 14 | plane = Plane.worldXY() |
13 | 15 | plane.transform(R) |
| 16 | +splitter = Brep.from_plane(plane, domain_u=(-2, +2), domain_v=(-2, +2)) |
14 | 17 |
|
15 | | -result = box.split(Brep.from_planes([plane])) |
| 18 | +result = box.split(splitter) |
16 | 19 |
|
17 | 20 | # ============================================================================= |
18 | 21 | # Visualization |
|
23 | 26 | # viewer.view.camera.position = [2, -4, 1] |
24 | 27 | # viewer.view.camera.look_at([0, 0, 0]) |
25 | 28 |
|
26 | | -# viewer.scene.add(plane, linewidth=2, opacity=0.3) # there is a debug print statement in the viewer that needs to be removed |
27 | | - |
28 | | -# for brep in result: |
29 | | -# if is_point_infrontof_plane(brep.centroid, plane): |
30 | | -# viewer.scene.add( |
31 | | -# brep, |
32 | | -# facecolor=Color.red().lightened(50), |
33 | | -# linecolor=Color.red(), |
34 | | -# linewidth=2, |
35 | | -# ) |
36 | | -# else: |
37 | | -# viewer.scene.add( |
38 | | -# brep, |
39 | | -# facecolor=Color.blue().lightened(50), |
40 | | -# linecolor=Color.blue(), |
41 | | -# linewidth=2, |
42 | | -# ) |
| 29 | +viewer.scene.add(splitter, linewidth=2, opacity=0.3) |
| 30 | + |
| 31 | +for brep in result: # type: ignore |
| 32 | + if is_point_infrontof_plane(brep.centroid, plane): |
| 33 | + viewer.scene.add( |
| 34 | + brep, |
| 35 | + surfacecolor=Color.red().lightened(50), |
| 36 | + linecolor=Color.red(), |
| 37 | + linewidth=2, |
| 38 | + show_points=False, |
| 39 | + ) |
| 40 | + else: |
| 41 | + viewer.scene.add( |
| 42 | + brep, |
| 43 | + surfacecolor=Color.blue().lightened(50), |
| 44 | + linecolor=Color.blue(), |
| 45 | + linewidth=2, |
| 46 | + show_points=False, |
| 47 | + ) |
43 | 48 |
|
44 | 49 | viewer.show() |
0 commit comments