Skip to content

Commit 4c5d7ce

Browse files
committed
aabb
1 parent 623f7ad commit 4c5d7ce

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed
1.18 MB
Loading

docs/examples/surface_aabb.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from math import radians
2+
from compas.geometry import Translation, Rotation
3+
from compas.geometry import Point, Polyline
4+
from compas_occ.geometry import NurbsSurface
5+
6+
from compas_view2.app import App
7+
8+
points = [
9+
[Point(0, 0, 0), Point(1, 0, 0), Point(2, 0, 0), Point(3, 0, 0), Point(4, 0, 0)],
10+
[Point(0, 1, 0), Point(1, 1, 2), Point(2, 1, 2), Point(3, 1, 0), Point(4, 1, 0)],
11+
[Point(0, 2, 0), Point(1, 2, 2), Point(2, 2, 2), Point(3, 2, 0), Point(4, 2, 0)],
12+
[Point(0, 3, 0), Point(1, 3, 0), Point(2, 3, 0), Point(3, 3, 0), Point(4, 3, 0)],
13+
]
14+
15+
surface = NurbsSurface.from_points(points=points)
16+
17+
T = Translation.from_vector([0, -1.5, 0])
18+
R = Rotation.from_axis_and_angle([0, 0, 1], radians(45))
19+
20+
surface.transform(R * T)
21+
22+
# ==============================================================================
23+
# AABB
24+
# ==============================================================================
25+
26+
box = surface.aabb()
27+
28+
# ==============================================================================
29+
# Visualisation
30+
# ==============================================================================
31+
32+
view = App()
33+
34+
for row in surface.points:
35+
view.add(Polyline(row), show_points=True, pointsize=20, pointcolor=(1, 0, 0), linewidth=2, linecolor=(1.0, 0, 0))
36+
37+
for col in zip(* surface.points):
38+
view.add(Polyline(col), linewidth=2, linecolor=(0, 1.0, 0))
39+
40+
view.add(surface.to_mesh(u=50))
41+
view.add(box, show_faces=False)
42+
43+
view.run()

docs/examples/surface_aabb.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
********************************************************************************
2+
Surface Axis-Aligned Bounding Box
3+
********************************************************************************
4+
5+
.. figure:: /_images/example_surface_aabb.png
6+
:figclass: figure
7+
:class: figure-img img-fluid
8+
9+
.. literalinclude:: surface_aabb.py
10+
:language: python

src/compas_occ/geometry/surfaces/nurbs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,8 @@ def copy(self) -> NurbsSurface:
527527
def transform(self, T: Transformation) -> None:
528528
"""Transform this surface."""
529529
_T = gp_Trsf()
530-
_T.SetValues(* T.list)
531-
self.occ_surface.Transform(T)
530+
_T.SetValues(* T.list[:12])
531+
self.occ_surface.Transform(_T)
532532

533533
def transformed(self, T: Transformation) -> NurbsSurface:
534534
"""Transform an independent copy of this surface."""
@@ -609,7 +609,7 @@ def closest_point(self, point, distance=None) -> Point:
609609
def aabb(self, precision: float = 0.0) -> Box:
610610
"""Compute the axis aligned bounding box of the surface."""
611611
box = Bnd_Box()
612-
BndLib_AddSurface_Add(GeomAdaptor_Surface(self.occ_curve), precision, box)
612+
BndLib_AddSurface_Add(GeomAdaptor_Surface(self.occ_surface), precision, box)
613613
return Box.from_diagonal((
614614
Point.from_occ(box.CornerMin()),
615615
Point.from_occ(box.CornerMax())

0 commit comments

Comments
 (0)