1010# TODO: makes the function return the angle between 0 to 360 degrees
1111def _angle_of_2_vectors (u , v ):
1212 """Calculate the angle between two 3D vectors u and v in radians. Can be
13- used to calcualte the span of a GCR.
13+ used to calcualte the span of a GCR, it will return the degree between 0 to 360 .
1414
1515 Parameters
1616 ----------
@@ -24,11 +24,22 @@ def _angle_of_2_vectors(u, v):
2424 float
2525 The angle between u and v in radians.
2626 """
27+ # First calculate the direction of the normal, which can determine if the angle is greater than 180 degrees
28+ # The direction of the normal is determined by the cross product of the two vectors
29+ normal = np .cross (u , v )
30+
31+ # Calculate the angle between the two vectors,between 0 to 180 degrees
2732 v_norm_times_u = np .linalg .norm (v ) * u
2833 u_norm_times_v = np .linalg .norm (u ) * v
2934 vec_minus = v_norm_times_u - u_norm_times_v
3035 vec_sum = v_norm_times_u + u_norm_times_v
3136 angle_u_v_rad = 2 * np .arctan2 (np .linalg .norm (vec_minus ), np .linalg .norm (vec_sum ))
37+
38+ # If the normal is positive, the angle is less than 180 degrees (counter-clockwise)
39+ if np .dot (normal , np .array ([0.0 , 0.0 , 1.0 ])) >= 0 :
40+ return angle_u_v_rad
41+ else :
42+ return 2 * np .pi - angle_u_v_rad
3243 return angle_u_v_rad
3344
3445
0 commit comments