MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / unit_vector

Function unit_vector

src/bcf/bcf/geometry.py:44–55  ·  view source on GitHub ↗

Return the unit vector of a vector. Args: v: vector Returns: unit vector.

(v: NDArray[np.float64])

Source from the content-addressed store, hash-verified

42
43
44def unit_vector(v: NDArray[np.float64]) -> NDArray[np.float64]:
45 """
46 Return the unit vector of a vector.
47
48 Args:
49 v: vector
50
51 Returns:
52 unit vector.
53 """
54 norm = np.linalg.norm(v)
55 return v if norm == 0 else v / norm

Callers 1

Calls 1

normMethod · 0.80

Tested by

no test coverage detected