|
|
import math |
|
|
import random |
|
|
import string |
|
|
|
|
|
import numpy as np |
|
|
|
|
|
|
|
|
def generate_random_string(length): |
|
|
letters = string.ascii_letters + string.digits |
|
|
return "".join(random.choice(letters) for _ in range(length)) |
|
|
|
|
|
|
|
|
def calculate_angle_clockwise(A_pos, B_pos, x_right=False): |
|
|
|
|
|
if x_right: |
|
|
vector_A_to_B = (A_pos[0] - B_pos[0], B_pos[1] - A_pos[1]) |
|
|
else: |
|
|
vector_A_to_B = (B_pos[0] - A_pos[0], B_pos[1] - A_pos[1]) |
|
|
|
|
|
|
|
|
angle_rad = math.atan2(vector_A_to_B[0], vector_A_to_B[1]) |
|
|
angle_deg = math.degrees(angle_rad) |
|
|
|
|
|
|
|
|
|
|
|
angle_deg = (angle_deg + 360) % 360 |
|
|
clock_position = 12 - angle_deg // 30 |
|
|
clock_position = clock_position if clock_position > 0 else 12 + clock_position |
|
|
|
|
|
return clock_position |
|
|
|
|
|
|
|
|
def is_aligned_vertically(A, B): |
|
|
|
|
|
A_points = np.asarray(A["pcd"].points) |
|
|
B_points = np.asarray(B["pcd"].points) |
|
|
|
|
|
|
|
|
A_min, A_max = np.min(A_points[:, 1]), np.max(A_points[:, 1]) |
|
|
|
|
|
B_min, B_max = np.min(B_points[:, 1]), np.max(B_points[:, 1]) |
|
|
|
|
|
|
|
|
overlap = max(0, min(A_max, B_max) - max(A_min, B_min)) |
|
|
A_overlap_percentage = overlap / (A_max - A_min) if A_max != A_min else 0 |
|
|
B_overlap_percentage = overlap / (B_max - B_min) if B_max != B_min else 0 |
|
|
|
|
|
|
|
|
return A_overlap_percentage > 0.5 and B_overlap_percentage > 0.5 |
|
|
|
|
|
|
|
|
def is_aligned_horizontally(A, B): |
|
|
|
|
|
|
|
|
|
|
|
A_box = A["pcd"].get_axis_aligned_bounding_box() |
|
|
B_box = B["pcd"].get_axis_aligned_bounding_box() |
|
|
|
|
|
|
|
|
A_min_x, A_max_x = A_box.get_min_bound()[0], A_box.get_max_bound()[0] |
|
|
B_min_x, B_max_x = B_box.get_min_bound()[0], B_box.get_max_bound()[0] |
|
|
|
|
|
|
|
|
A_width, B_width = A_max_x - A_min_x, B_max_x - B_min_x |
|
|
is_almost_same_size = max(A_width, B_width) / min(A_width, B_width) <= 1.5 |
|
|
if not is_almost_same_size: |
|
|
return False |
|
|
|
|
|
overlap_min, overlap_max = max(A_min_x, B_min_x), min(A_max_x, B_max_x) |
|
|
overlap_width = max(0, overlap_max - overlap_min) |
|
|
overlap_percent = max(overlap_width / A_width, overlap_width / B_width) |
|
|
|
|
|
return overlap_percent > 0.95 |
|
|
|
|
|
|
|
|
def is_y_axis_overlapped(A, B): |
|
|
|
|
|
A_box = A["pcd"].get_axis_aligned_bounding_box() |
|
|
B_box = B["pcd"].get_axis_aligned_bounding_box() |
|
|
|
|
|
|
|
|
A_min_y, A_max_y = A_box.get_min_bound()[1], A_box.get_max_bound()[1] |
|
|
B_min_y, B_max_y = B_box.get_min_bound()[1], B_box.get_max_bound()[1] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
overlap = (A_min_y <= B_max_y and A_max_y >= B_min_y) or (B_min_y <= A_max_y and B_max_y >= A_min_y) |
|
|
|
|
|
return overlap |
|
|
|
|
|
|
|
|
def is_supporting(A, B): |
|
|
|
|
|
A_box = A["pcd"].get_axis_aligned_bounding_box() |
|
|
B_box = B["pcd"].get_axis_aligned_bounding_box() |
|
|
|
|
|
|
|
|
A_min, A_max = A_box.get_min_bound(), A_box.get_max_bound() |
|
|
B_min, B_max = B_box.get_min_bound(), B_box.get_max_bound() |
|
|
|
|
|
|
|
|
|
|
|
vertical_contact = (A_min[2] <= B_max[2] and A_min[2] >= B_min[2]) or ( |
|
|
B_min[2] <= A_max[2] and B_min[2] >= A_min[2] |
|
|
) |
|
|
|
|
|
if not vertical_contact: |
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
if A_min[2] < B_min[2]: |
|
|
top, bottom = B, A |
|
|
top_min, top_max = B_min, B_max |
|
|
bottom_min, bottom_max = A_min, A_max |
|
|
else: |
|
|
top, bottom = A, B |
|
|
top_min, top_max = A_min, A_max |
|
|
bottom_min, bottom_max = B_min, B_max |
|
|
|
|
|
|
|
|
|
|
|
horizontal_coverage = ( |
|
|
top_min[0] <= bottom_min[0] |
|
|
and top_max[0] >= bottom_max[0] |
|
|
and top_min[1] <= bottom_min[1] |
|
|
and top_max[1] >= bottom_max[1] |
|
|
) |
|
|
|
|
|
return horizontal_coverage |
|
|
|