import open3d as o3d
import numpy as np
# OBB 생성
center = np.array([0, 0, 0])
axis_angles1 = np.array([0, 0, 0]) # 회전 없음
rotation1 = o3d.geometry.get_rotation_matrix_from_axis_angle(axis_angles1)
extent = np.array([1, 1, 1])
obb1 = o3d.geometry.OrientedBoundingBox(center, rotation1, extent)
obb1.color = [1, 0, 0]
# 꼭짓점 얻기 (OBB 기준)
box_points = np.asarray(obb1.get_box_points())
# 면의 대각선 인덱스 (X자 6면 = 12줄)
face_diagonals = [
(0, 7), (1, 6), # 앞면 (y = min)
(2, 5), (3, 4), # 뒷면 (y = max)
(0, 3), (1, 2), # 왼쪽면 (x = min)
(4, 7), (5, 6), # 오른쪽면 (x = max)
]
# 선 추가
line_points = []
line_indices = []
colors = []
for i, (start_idx, end_idx) in enumerate(face_diagonals):
line_points.append(box_points[start_idx])
line_points.append(box_points[end_idx])
line_indices.append([2 * i, 2 * i + 1])
colors.append([1, 0, 0]) # 빨강
# 같은 색 두 번 (X자 하나 = 선 2개)
# LineSet 생성
x_lines = o3d.geometry.LineSet()
x_lines.points = o3d.utility.Vector3dVector(line_points)
x_lines.lines = o3d.utility.Vector2iVector(line_indices)
x_lines.colors = o3d.utility.Vector3dVector(colors)
# 좌표축
axis_frame = o3d.geometry.TriangleMesh.create_coordinate_frame(size=0.5, origin=[0, 0, 0])
# 시각화
o3d.visualization.draw_geometries([obb1, x_lines, axis_frame],width=500,height=500)