bbi.math

calculate_look_at_rotation(source_position: Vector3, target_position: Vector3) Vector3

Calculate the rotation needed to look from one point towards another point.

Note

When turning to look at a point, only pitch and yaw are relevant. Roll is unnecessary and will be set to zero.

Parameters:
  • source_position (Vector3) – The position to look from

  • target_position (Vector3) – The position to look at

Returns:

The rotation in degrees (0, pitch, yaw)

Return type:

Vector3

calculate_rotation_matrix_for_vector(from_vec: Vector3, to_vec: Vector3) ndarray

Calculates the 3D rotation matrix that rotates one Vector3 to align with another Vector3.

Parameters:
  • from_vec (Vector3) – Initial 3D vector to be rotated.

  • to_vec (Vector3) – Target 3D vector to align with.

Returns:

A 3x3 rotation matrix.

Return type:

ndarray

matrix_to_euler_degrees(r_mat: ndarray) Vector3

Extract Euler angles (roll, pitch, yaw) from a rotation matrix. The results are left-handed, x-foward z-up y-right coordinate system.

Parameters:

R (ndarray) – A 3x3 rotation matrix.

Returns:

Vector containing the Euler angles (yaw, pitch, roll) in degrees.

Return type:

Vector3

class Vector3(x: float = 0, y: float = 0, z: float = 0)

Bases: object

A 3D vector defined by x, y, and z values.

By convention, units for world space are in meters.

Parameters:
  • x (float, optional) – The x value. Defaults to 0.

  • y (float, optional) – The y value. Defaults to 0.

  • z (float, optional) – The z value. Defaults to 0.

static zero() Vector3

Returns a zero vector Vector3(0, 0, 0).

static one() Vector3

Returns a one vector Vector3(1, 1, 1).

This is useful for setting a default scale.

to_direction() Vector3

Converts a rotation Vector3 (roll, pitch, yaw) to a directional unit Vector3.

to_rotation() Vector3

Converts a directional Vector3 to a rotation Vector3 (roll, pitch, yaw).

Roll is always 0.

numpy() ndarray

Returns the vector as a NumPy array of shape (3,).

magnitude() float

Returns the magnitude of the vector.

normalized() Vector3

Returns a new normalized vector.

cross(other: Vector3) Vector3

Returns the cross product of two vectors.

dot(other: Vector3) float

Returns the dot product of two vectors.

distance_to_point(other: Vector3) float

Calculates the distance to another point.

distance_to_line_segment(start: Vector3, end: Vector3) float

Calculates the shortest distance to a line segment defined by two points.

isclose(other: Vector3, rel_tol: float = 1.0e-5, abs_tol: float = 1.0e-8) bool

Returns True if two vectors are element-wise equal within a tolerance.

The tolerance values are positive, typically very small numbers. The relative difference (rel_tol * abs(b)) and the absolute difference abs_tol are added together to compare against the absolute difference between a and b.

NaNs are treated as equal if they are in the same place and if equal_nan=True. Infs are treated as equal if they are in the same place and of the same sign in both arrays.

Parameters:
  • other (Vector3) – The other vector to compare.

  • rel_tol (float, optional) – The relative tolerance. Defaults to 1.e-5.

  • abs_tol (float, optional) – The absolute tolerance. Defaults to 1.e-8.

to_dict() dict

Returns a dictionary representation of the vector for JSON serialization.

class Vector4(x: float = 0, y: float = 0, z: float = 0, w: float = 0)

Bases: object

A 3D vector defined by x, y, z and w values.

By convention, units for world space are in meters.

Parameters:
  • x (float, optional) – The x value. Defaults to 0.

  • y (float, optional) – The y value. Defaults to 0.

  • z (float, optional) – The z value. Defaults to 0.

  • w (float, optional) – The w value. Defaults to 0.

static zero() Vector4

Returns a zero vector Vector4(0, 0, 0, 0).

numpy() ndarray

Returns the vector as a NumPy array of shape (4,).