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

Function camera_vectors_from_target_position

src/bcf/bcf/geometry.py:23–41  ·  view source on GitHub ↗

Calculate the vectors of a camera pointing to a target point. Args: target_position: point the camera is pointing to. camera_offset: offset of the camera from the target point. Returns: Camera position, direction and up vectors

(
    target_position: NDArray[np.float64], offset: Optional[NDArray[np.float64]] = None
)

Source from the content-addressed store, hash-verified

21
22
23def camera_vectors_from_target_position(
24 target_position: NDArray[np.float64], offset: Optional[NDArray[np.float64]] = None
25) -> tuple[list[float], list[float], list[float]]:
26 """
27 Calculate the vectors of a camera pointing to a target point.
28
29 Args:
30 target_position: point the camera is pointing to.
31 camera_offset: offset of the camera from the target point.
32
33 Returns:
34 Camera position, direction and up vectors
35 """
36 camera_offset = np.array((5, 5, 5)) if offset is None else offset
37 camera_position = target_position + camera_offset
38 camera_direction = unit_vector(-camera_offset) # pylint: disable=invalid-unary-operand-type
39 camera_right = unit_vector(np.cross(np.array([0.0, 0.0, 1.0]), camera_direction))
40 camera_up = unit_vector(np.cross(camera_direction, camera_right))
41 return camera_position.tolist(), camera_direction.tolist(), camera_up.tolist()
42
43
44def unit_vector(v: NDArray[np.float64]) -> NDArray[np.float64]:

Calls 1

unit_vectorFunction · 0.85

Tested by

no test coverage detected