Révision b516a1d6 modules/screening.py

b/modules/screening.py
66 66
    return [conf_list[idx] for idx in selected_ids]
67 67

  
68 68

  
69
def get_vect_angle(v1: list, v2: list, degrees=False):
69
def get_vect_angle(v1: list, v2: list, ref=None, degrees=False):
70 70
    """Computes the angle between two vectors.
71 71

  
72 72
    @param v1: The first vector.
73 73
    @param v2: The second vector.
74
    @param ref: Orthogonal vector to both v1 and v2,
75
        along which the sign of the rotation is defined (i.e. positive if
76
        counterclockwise angle when facing ref)
74 77
    @param degrees: Whether the result should be in radians (True) or in
75 78
        degrees (False).
76 79
    @return: The angle in radians if degrees = False, or in degrees if
......
79 82
    v1_u = v1 / np.linalg.norm(v1)
80 83
    v2_u = v2 / np.linalg.norm(v2)
81 84
    angle = np.arccos(np.clip(np.dot(v1_u, v2_u), -1.0, 1.0))
85
    if ref is not None:
86
        # Give sign according to ref direction
87
        angle *= (1 if np.dot(np.cross(v1, v2), ref) >= 0 else -1)
88

  
82 89
    return angle if not degrees else angle * 180 / np.pi
83 90

  
84 91

  

Formats disponibles : Unified diff