MCPcopy Create free account
hub / github.com/PJLab-ADG/OASim / angle_between

Function angle_between

limsim/evaluation/math_utils.py:5–18  ·  view source on GitHub ↗

compute the angle between two vectors, i.e. theta = arccos( / (||v1||_2 * ||v2||_2)) Args: v1 (np.ndarray): first vector v2 (np.ndarray): second vector of same length as first vector Returns: float: angle in radians, between [0, pi]

(v1: np.ndarray, v2: np.ndarray)

Source from the content-addressed store, hash-verified

3
4
5def angle_between(v1: np.ndarray, v2: np.ndarray) -> float:
6 """compute the angle between two vectors, i.e.
7 theta = arccos(<v1, v2> / (||v1||_2 * ||v2||_2))
8
9 Args:
10 v1 (np.ndarray): first vector
11 v2 (np.ndarray): second vector of same length as first vector
12
13 Returns:
14 float: angle in radians, between [0, pi]
15 """
16 if np.all(v1 <= 1e-8) or np.all(v2 <= 1e-8):
17 return 0.0
18 return np.arccos(np.dot(v1, v2) / (np.linalg.norm(v1) * np.linalg.norm(v2) + 1e-9))
19
20
21def project(v1: np.ndarray, v2: np.ndarray) -> float:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected