diff --git a/main.py b/main.py index c42347b..b91fffd 100644 --- a/main.py +++ b/main.py @@ -150,23 +150,27 @@ # Function to compute angle between first two vectors in VECTORS -def compute_and_format_angle(pts: List[Tuple[float, float, float]]) -> str: - if len(VECTORS) < 2: - return "Angle v1-v2: N/A" - (a1, b1, _, _) = VECTORS[1] - (a2, b2, _, _) = VECTORS[2] +def compute_and_format_angle( + pts: List[Tuple[float, float, float]], vec1: int, vec2: int +) -> str: + + hstr = f"Angle v{vec1 + 1}-v{vec2 + 1} " + if vec1 >= len(VECTORS) or vec2 >= len(VECTORS): + return hstr + "N/A" + (a1, b1, _, _) = VECTORS[vec1] + (a2, b2, _, _) = VECTORS[vec2] p1s, p1e, p2s, p2e = pts[a1], pts[b1], pts[a2], pts[b2] v1 = (p1e[0] - p1s[0], p1e[1] - p1s[1], p1e[2] - p1s[2]) v2 = (p2e[0] - p2s[0], p2e[1] - p2s[1], p2e[2] - p2s[2]) norm1 = math.sqrt(v1[0] ** 2 + v1[1] ** 2 + v1[2] ** 2) norm2 = math.sqrt(v2[0] ** 2 + v2[1] ** 2 + v2[2] ** 2) if norm1 < 1e-9 or norm2 < 1e-9: - return "Angle v1-v2: N/A" + return hstr + "N/A" dot = v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2] cos_val = max(-1.0, min(1.0, dot / (norm1 * norm2))) angle_rad = math.acos(cos_val) angle_deg = math.degrees(angle_rad) - return f"Angle v1-v2: {angle_deg:.2f}°" + return hstr + f"{angle_deg:.2f} deg" # Function to visualize thumb data with a slider @@ -250,8 +254,8 @@ arrow_labels.append(lbl) # Angle display between v1 and v2 (figure-relative text) - angle_text = fig.text(0.02, 0.95, "", fontsize=12, weight="bold") - angle_text.set_text(compute_and_format_angle(points)) + angle_text1 = fig.text(0.02, 0.95, "", fontsize=12, weight="bold") + angle_text1.set_text(compute_and_format_angle(points, 0, 1)) ax.set_xlabel("X") ax.set_ylabel("Y") @@ -293,7 +297,7 @@ arrow_labels[i_pair].set_position(mid_pts) # Update angle text between v1 and v2 - angle_text.set_text(compute_and_format_angle(points)) + angle_text1.set_text(compute_and_format_angle(points, 0, 1)) ax.set_title(f"Frame {data[frame_idx].frame_number}") fig.canvas.draw_idle() @@ -302,7 +306,7 @@ # Button: switch view to direction from points[0] towards points[4] ax_button = plt.axes([0.02, 0.02, 0.1, 0.04]) - btn_top = Button(ax_button, "P0→P4") + btn_top = Button(ax_button, "v4 view") def set_top_view(points): # Calculate direction from points[0] to points[4]