Vector#

class blueprints.Vector[source]#

Bases: object

This class implements multiple functions to modify vectors and orientations of MoveableThings.

Methods Summary

distance(a, b)

This method returns the distance between two vectors or MoveableThings.

equal(a, b[, sensitivity])

Compares whether two vectors are equal within a margin of error as given by sensitivity.

get_axis(axis)

This method returns a vector that represents the axis which is either given as a str or as a 1D array like object.

global_position(node[, pos])

This method converts the local position of a Thing (typically a node in a kinematic tree) to its global position relative to the nodes root.

normalize(vector)

This method normalizes a vector to a unit lenth of 1.

Methods Documentation

static distance(a, b)[source]#

This method returns the distance between two vectors or MoveableThings.

Parameters:
  • a (np.ndarray | blue.MoveableThingType) – A vector or MoveableThings global position for which the distance is computed w.r.t. b.

  • b (np.ndarray | blue.MoveableThingType) – A vector or MoveableThings global position for which the distance is computed w.r.t. a.

Returns:

The distance betweent the two vectors or MoveableThings.

Return type:

float

static equal(a, b, sensitivity=8)[source]#

Compares whether two vectors are equal within a margin of error as given by sensitivity.

>>> a = np.array([3.2, 0., 0.])
>>> b = np.array([3.8, 0., 0.])
>>> c = np.array([3.2, 5., 0.])
>>> Vector.equal(a, b, sensitivity=0)
True
>>> Vector.equal(a, b, sensitivity=1)
False
>>> Vector.equal(a, c, sensitivity=0)
False
>>> Vector.equal(a, c, sensitivity=-1)
True
Parameters:
  • a (np.ndarray) – A vector to be compared.

  • b (np.ndarray) – A vector to be compared.

  • sensitivity (int, optional) – The floating point decimal cutoff.

Returns:

A boolean indicating whether the two vectors are equal within the specified margin of error.

Return type:

bool

classmethod get_axis(axis)[source]#

This method returns a vector that represents the axis which is either given as a str or as a 1D array like object.

>>> Vector.get_axis("x")
array([1., 0., 0.])
>>> Vector.get_axis([0., 1., 0.])
array([0., 1., 0.])
>>> Vector.get_axis(np.array([0., 0., 1.]))
array([0., 0., 1.])
Parameters:

axis (str | list[int | float] | np.ndarray) – The axis argument may be either a 1D array like object or a string (‘x’, ‘y’, ‘z’).

Returns:

The specified axis converted to a numpy array.

Return type:

np.ndarray

Raises:
  • ValueError

  • If the axis argument is a string` and neither 'x', 'y' or 'z' a ValueError is raise

classmethod global_position(node, pos=None)[source]#

This method converts the local position of a Thing (typically a node in a kinematic tree) to its global position relative to the nodes root.

Parameters:
  • node (Thing) – A Thing (typically a node in a kinematic tree).

  • pos (None, optional) – An initial position that is assumed to be located relative to the node.

Returns:

The global position relative to root of the given node, or the initial position relative to the node is pos was specified.

Return type:

np.ndarray

static normalize(vector)[source]#

This method normalizes a vector to a unit lenth of 1.

Parameters:

vector (np.ndarray) – A vector to be normalized.

Returns:

The normalized vector.

Return type:

np.ndarray

__init__()#
classmethod __new__(*args, **kwargs)#