forked from compas-teaching/ITA21
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobb_0.py
46 lines (31 loc) · 1.16 KB
/
obb_0.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from math import radians
from compas.geometry import Pointcloud, Box
from compas.geometry import Frame, Transformation, Rotation, Translation
from compas.geometry import bounding_box
from compas.numerical import pca_numpy
from compas_view2.app import App
pcl = Pointcloud.from_bounds(8, 5, 3, 100)
Rz = Rotation.from_axis_and_angle([0.0, 0.0, 1.0], radians(60))
Ry = Rotation.from_axis_and_angle([0.0, 1.0, 0.0], radians(20))
Rx = Rotation.from_axis_and_angle([1.0, 0.0, 0.0], radians(10))
T = Translation.from_vector([5.0, 8.0, 3.0])
pcl.transform(T * Rz * Ry * Rx)
point, axes, values = pca_numpy(pcl)
world = Frame.worldXY()
frame = Frame(point, axes[0], axes[1])
X = Transformation.from_frame_to_frame(frame, world)
pcl2 = pcl.transformed(X)
box2 = Box.from_bounding_box(bounding_box(pcl2))
box = box2.transformed(X.inverted())
viewer = App(width=1200, height=750)
viewer.view.camera.rz = 0
viewer.view.camera.rx = -65
viewer.view.camera.ty = -2
viewer.view.camera.distance = 15
viewer.add(pcl, pointsize=10)
viewer.add(frame)
viewer.add(pcl2, pointsize=10)
viewer.add(box2, show_faces=False, linewidth=2)
viewer.add(box2.frame)
viewer.add(box, opacity=0.5)
viewer.show()