bbi.math.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.