Update tem.txt
Browse files
tem.txt
CHANGED
@@ -1,31 +1,35 @@
|
|
1 |
-
import cv2
|
2 |
import numpy as np
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import numpy as np
|
2 |
|
3 |
+
def calculate_endpoint(A_start, A_end, B, angle_deg):
|
4 |
+
# Calculate vector representing line A
|
5 |
+
vec_A = np.array(A_end) - np.array(A_start)
|
6 |
+
|
7 |
+
# Calculate length of line A
|
8 |
+
length_A = np.linalg.norm(vec_A)
|
9 |
+
|
10 |
+
# Calculate unit vector of line A
|
11 |
+
unit_vec_A = vec_A / length_A
|
12 |
+
|
13 |
+
# Convert angle from degrees to radians
|
14 |
+
angle_rad = np.deg2rad(angle_deg)
|
15 |
+
|
16 |
+
# Calculate rotation matrix for 30-degree angle
|
17 |
+
rotation_matrix = np.array([[np.cos(angle_rad), -np.sin(angle_rad)],
|
18 |
+
[np.sin(angle_rad), np.cos(angle_rad)]])
|
19 |
+
|
20 |
+
# Rotate unit vector of line A by 30 degrees
|
21 |
+
rotated_unit_vec_A = np.dot(rotation_matrix, unit_vec_A)
|
22 |
+
|
23 |
+
# Scale rotated unit vector by length of line A and add to point B to get endpoint coordinates
|
24 |
+
endpoint = np.array(B) + length_A * rotated_unit_vec_A
|
25 |
+
|
26 |
+
return endpoint
|
27 |
+
|
28 |
+
# Example usage
|
29 |
+
A_start = (0, 0)
|
30 |
+
A_end = (3, 4)
|
31 |
+
B = (1, 1)
|
32 |
+
angle_deg = 30
|
33 |
+
|
34 |
+
endpoint = calculate_endpoint(A_start, A_end, B, angle_deg)
|
35 |
+
print("Coordinates of the endpoint:", endpoint)
|