|
| 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 | +# OBB |
| 24 | +# ============================================================================== |
| 25 | + |
| 26 | +box = surface.obb() |
| 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()) |
| 41 | +view.add(box, show_faces=False) |
| 42 | + |
| 43 | +view.run() |
0 commit comments