Vectors#

class sigmaepsilon.math.linalg.Vector(*args, frame: FrameLike | None = None, **kwargs)[source]#

Extends NumPy’s ndarray class to handle arrays with associated reference frames. The class also provides a mechanism to transform vectors between different frames. Use it like if it was a numpy.ndarray instance.

All parameters are identical to those of numpy.ndarray, except that this class allows to specify an embedding frame.

Parameters:
  • args (tuple, Optional) – Positional arguments forwarded to numpy.ndarray.

  • frame (FrameLike, Optional) – The reference frame the vector is represented by its coordinates.

  • kwargs (dict, Optional) – Keyword arguments forwarded to numpy.ndarray.

Examples

Import the necessary classes:

>>> import numpy as np
>>> from sigmaepsilon.math.linalg import Vector, ReferenceFrame

Create a default frame in 3d space, and create 2 others, each being rotated with 30 degrees around the third axis.

>>> A = ReferenceFrame(dim=3)
>>> B = A.orient_new('Body', [0, 0, 30*np.pi/180], 'XYZ')
>>> C = B.orient_new('Body', [0, 0, 30*np.pi/180], 'XYZ')

To create a vector in a frame:

>>> vA = Vector([1.0, 1.0, 0.0], frame=A)

To create a vector with a relative transformation to another one:

>>> vB = vA.orient_new('Body', [0, 0, -30*np.pi/180], 'XYZ')

Use the array property to get the componets of a Vector:

>>> vB.array
Array([1.3660254, 0.3660254, 0.       ])

If you want to obtain the components of a vector in a specific target frame C, do this:

>>> vB.show(C)
array([ 1., -1.,  0.])

The reason why the result is represented now as ‘array’ insted of ‘Array’ as in the previous case is that the Vector class is an array container. When you type vB.array, what is returned is a wrapped object, an instance of Array, which is also a class of this library. When you say vB.show(C), a NumPy array is returned. Since the Array class is a direct subclass of NumPy’s ndarray class, it doesn’t really matter and the only difference is the capital first letter.

To create a vector in a target frame C, knowing the components in a source frame A:

>>> vC = Vector(vA.show(C), frame=C)
copy(deep: bool = False, name: str = None) Vector[source]#

Returns a shallow or deep copy of this object, depending of the argument deepcopy (default is False).

deepcopy(name: str = None) Vector[source]#

Returns a deep copy of the frame.

dual() Vector[source]#

Returns the vector described in the dual (or reciprocal) frame.

orient(*args, dcm: ndarray = None, **kwargs) Vector[source]#

Orients the vector inplace. If the transformation is not specified by ‘dcm’, all arguments are forwarded to orient_new.

Parameters:

dcm (numpy.ndarray, Optional) – The DCM matrix of the transformation.

Returns:

The same vector the function is called upon.

Return type:

Vector

See also

orient_new()

orient_new(*args, **kwargs) Vector[source]#

Returns a transformed version of the instance.

Returns:

A new vector.

Return type:

Vector

See also

orient()

property rank: int#

Returns the tensor rank (or order).

show(target: ReferenceFrame = None, *, dcm: ndarray = None) ndarray[source]#

Returns the components in a target frame. If the target is None, the components are returned in the ambient frame.

The transformation can also be specified with a proper DCM matrix.

Parameters:
Returns:

The components of the vector in a specified frame, or the ambient frame, depending on the arguments.

Return type:

numpy.ndarray