Vector helpers

Vector predicates and scalar-vector operations (BOSL2 vectors.scad).

pybosl2.vectors.is_vector(v, length=None, zero=None, eps=1e-09)[source]

Check if v is a list/tuple/ndarray of finite numbers.

Optionally of a given length and/or zero-ness.

Parameters:
v : Point | Sequence[float] | ndarray

The vector.

length : int | None

Target length to scale the vector to.

zero : bool | None

What to return when the vector has no length.

eps : float

Tolerance below which a component counts as zero.

Return type:

bool

pybosl2.vectors.add_scalar(v, s)[source]

Return v with scalar s added to every entry.

Parameters:
v : Point | Sequence[float] | ndarray

The vector.

s : float

The scalar to combine with the vector.

Return type:

ndarray

pybosl2.vectors.unit(v, error=None)[source]

Normalize v to unit length.

If v has (near) zero length, returns error if given, else raises ValueError (matching BOSL2’s default assert-on-zero-vector behavior).

Parameters:
v : Point | Sequence[float] | ndarray

The vector.

error : Point | Sequence[float] | ndarray | None

Raise instead of returning zero when the vector has no length.

Return type:

ndarray

pybosl2.vectors.v_theta(vec)[source]

Return the angle in degrees of the 2-D vector vec, measured counter-clockwise from +X.

Equivalent to math.degrees(math.atan2(vec[1], vec[0])).

Parameters:
vec : Sequence[float]

The vector.

Return type:

float