Karana.Math

Contents

Karana.Math#

Collection of classes to represent mathematical object used in Karana Dynamics simulations.

Examples include unit quaternions, homogenous transforms, and spatial vectors.

Submodules#

Attributes#

Classes#

AABB

AkimaSplineInterpolator

Akima spline interpolation method

BaseInterpolator

Base class for interpolation methods */

ConstantInterpolator

Constant value implementation of BaseInterpolator

EulerAngles

EulerSystem

Members:

HomTran

HybridNonLinearSolverStatus

Status of the HybridNonLinearSolver solver

Jacobian

@class Jacobian Class used to create a Jacobian for a given function

LevenbergMarquardtStatus

Status of the LevenbergMarquardt solver

LinearInterpolator

Piecewise linear interpolation method */

NearestNeighborInterpolator

Nearest neighbor interpolation method */

NonlinearSolver

NonlinearSolver class manages a nonlinear problem and associated

RotationMatrix

RotationVector

SimTran

SpatialInertia

SpatialVector

StateSpace

@class StateSpace Use provided non-linear equations to create a state

UnitQuaternion

solver_enum

Solver types used by the Nonlinear solver

ss

State space return type. This holds the A, B, C, and D matrices that

ArkExplicitIntegrator

The multistep ArkODE explicit integrator from the SUNDIALS suite

ArkExplicitIntegratorOptions

Struct with options for this integrator

CVodeIntegrator

The multistep CVode integrator from the SUNDIALS suite

CVodeIntegratorOptions

Struct with options for this integrator

EulerIntegrator

The fixed-step Euler one step integrator.

Integrator

Base class for numerical integrators

IntegratorOptions

A struct with integrator options. This struct can be sub-classed by

IntegratorType

Members:

RK4Integrator

Fixed-step Runge-Kutta 4th order integrator

Functions#

buildNaNWithPayload(→ float)

Create a NaN double with a particular mantissa payload

floatingPointExceptions(→ None)

Function to enable/disable exceptions when there are floating point

isNaNWithPayload(→ bool)

Whether a double is a NaN with a given mantissa payload

isUninitializedNaN(→ bool)

Whether a double is a NaN inidicating an uninitialized value

ktimeToSeconds(→ float)

Convert a Ktime value to a double (units in seconds).

secondsToKtime(→ numpy.timedelta64)

Convert a seconds (double) time value to Ktime

tilde(→ Annotated[numpy.typing.NDArray[numpy.float64], ...)

Calcualte the 3x3 skew cross-product matrix for the input vector.

strToIntegratorType(→ IntegratorType)

Package Contents#

class Karana.Math.AABB#
class Karana.Math.AABB(min: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]], max: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]], fix_minmax: bool = True)
class Karana.Math.AABB(other: AABB)
__add__(other: AABB) AABB#

Combines this AABB with another AABB.

The resulting AABB will be a new box that encompasses both the original AABB and the ‘other’ AABB.

Parameter other:

The AABB to combine with this one.

Returns:

The combined AABB

__repr__() str#
dump(prefix: str = '', precision: SupportsInt = 10, exponential: bool = False) None#

Prints a string representation of the AABB with options for formatting.

Parameter prefix:

A string to prepend to each line.

Parameter precision:

The number of decimal places for floating-point values.

Parameter exponential:

Whether to use exponential notation.

dumpString(prefix: str = '', precision: SupportsInt = 6, exponential: bool = False) str#

Returns a string representation of the AABB with options for formatting.

Parameter prefix:

A string to prepend to each line.

Parameter precision:

The number of decimal places for floating-point values.

Parameter exponential:

Whether to use exponential notation.

Returns:

A string containing the min and max corners.

max() Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

Get the minimum corner of the AABB.

Returns:

The minimum corner.

min() Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

Get the minimum corner of the AABB.

Returns:

The minimum corner.

rotate(q: UnitQuaternion) AABB#

Computes a new AABB by rotating this AABB by a given unit quaternion.

Parameter q:

The unit quaternion to rotate by.

Returns:

A new AABB that has been translated.

scale(s: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]]) AABB#
scale(s: SupportsFloat) AABB

Computes a new AABB by scaling this AABB by a given scalar.

Parameter s:

The scalar to scale by.

Returns:

A new AABB that has been scaled.

transform(t: HomTran) AABB#

Computes a new AABB by transforming this AABB by a given HomTran.

Parameter t:

The 3-vector to scale by.

Returns:

A new AABB that has been transformed.

translate(t: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]]) AABB#

Computes a new AABB by translating this AABB by a given vector.

Parameter t:

The 3-vector to translate by.

Returns:

A new AABB that has been translated.

class Karana.Math.AkimaSplineInterpolator(indep: Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]], dep: Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]], extrapolation: AkimaSplineInterpolator.Extrapolation | None = None)#

Bases: BaseInterpolator

Akima spline interpolation method

Uses a piecewise-cubic spline well-suited to cases where the underlying data has a rapidly varying second derivative.

class Extrapolation(value: SupportsInt)#

Members:

Constant

Linear

Cubic

Constant: ClassVar[AkimaSplineInterpolator]#
Cubic: ClassVar[AkimaSplineInterpolator]#
Linear: ClassVar[AkimaSplineInterpolator]#
__members__: ClassVar[dict[str, AkimaSplineInterpolator]]#
__eq__(other: Any) bool#
__getstate__() int#
__hash__() int#
__index__() int#
__int__() int#
__ne__(other: Any) bool#
__repr__() str#
__setstate__(state: SupportsInt) None#
__str__() str#
property name: str#
property value: int#
Constant: ClassVar[AkimaSplineInterpolator]#
Cubic: ClassVar[AkimaSplineInterpolator]#
Linear: ClassVar[AkimaSplineInterpolator]#
class Karana.Math.BaseInterpolator#

Base class for interpolation methods */

__call__(x: SupportsFloat) float#
__call__(x: Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]], out: Annotated[numpy.typing.NDArray[numpy.float64], [m, 1], flags.writeable]) None
__call__(x: Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]) Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]

Calculate the jacobian of the supplied function.

Parameter x:

The input vector we want to calculate the jacobian with respect to.

Returns:

The jacobian of the supplied function about x.

class Karana.Math.ConstantInterpolator(constant: SupportsFloat)#

Bases: BaseInterpolator

Constant value implementation of BaseInterpolator

This just interpolates to the same constant value everywhere, which may be useful when a BaseInterpolator is expected but only a constant value is needed.

class Karana.Math.EulerAngles(alpha: SupportsFloat, beta: SupportsFloat, gamma: SupportsFloat, euler_system: EulerSystem = EulerSystem.XYZ)#
__hash__: ClassVar[None] = None#
__eq__(arg0: EulerAngles) bool#
__repr__() str#
alpha() float#

First Euler angle.

alphaAxisVector() Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

First Euler angle axis.

angles() Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

The three Euler angles.

beta() float#

Second Euler angle.

betaAxisVector() Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

Second Euler angle axis.

gamma() float#

Third Euler angle.

gammaAxisVector() Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

Third Euler angle axis.

isApprox(other: EulerAngles, prec: SupportsFloat = 1e-12) bool#
property euler_system: EulerSystem#
class Karana.Math.EulerSystem(value: SupportsInt)#

Members:

XYZ

XYX

XZY

XZX

YZX

YZY

YXZ

YXY

ZXY

ZXZ

ZYX

ZYZ

XYX: ClassVar[EulerSystem]#
XYZ: ClassVar[EulerSystem]#
XZX: ClassVar[EulerSystem]#
XZY: ClassVar[EulerSystem]#
YXY: ClassVar[EulerSystem]#
YXZ: ClassVar[EulerSystem]#
YZX: ClassVar[EulerSystem]#
YZY: ClassVar[EulerSystem]#
ZXY: ClassVar[EulerSystem]#
ZXZ: ClassVar[EulerSystem]#
ZYX: ClassVar[EulerSystem]#
ZYZ: ClassVar[EulerSystem]#
__members__: ClassVar[dict[str, EulerSystem]]#
__eq__(other: Any) bool#
__getstate__() int#
__hash__() int#
__index__() int#
__int__() int#
__ne__(other: Any) bool#
__repr__() str#
__setstate__(state: SupportsInt) None#
__str__() str#
property name: str#
property value: int#
class Karana.Math.HomTran(vec: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]], epsilon: SupportsFloat = 1e-12)#
class Karana.Math.HomTran
class Karana.Math.HomTran(q: UnitQuaternion, epsilon: SupportsFloat = 1e-12)
class Karana.Math.HomTran(q: UnitQuaternion, vec: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]], epsilon: SupportsFloat = 1e-12)
__hash__: ClassVar[None] = None#
__eq__(other: HomTran) bool#

Equality operator.

Parameter other:

Another HomTran instance.

Returns:

True if both transforms are equal.

__getstate__() tuple#
__mul__(T: HomTran) HomTran#
__mul__(v: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]]) Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]

Multiply two transforms.

Parameter T:

The other transform to multiply with.

Returns:

Product transform.

__repr__() str#
__setstate__(arg0: tuple) None#
dump(prefix: str = '', precision: SupportsInt = 10, exponential: bool = False) None#

Print transform information to standard output.

Parameter prefix:

Optional prefix for each line.

Parameter precision:

Number of digits to use for floating point values.

Parameter exponential:

Whether to use exponential notation.

dumpString(prefix: str = '', precision: SupportsInt = 10, exponential: bool = False) str#

Get a string representation of the transform.

Parameter prefix:

Optional prefix for each line.

Parameter precision:

Number of digits to use for floating point values.

Parameter exponential:

Whether to use exponential notation.

Returns:

String dump of the transform.

getMatrix() Annotated[numpy.typing.NDArray[numpy.float64], [4, 4]]#

Get the 4x4 homogeneous transformation matrix representation.

Returns:

The transformation matrix.

getTranslation() Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

Get the translation vector.

Returns:

Translation vector.

getUnitQuaternion() UnitQuaternion#

Get the unit quaternion.

Returns:

Unit quaternion.

hasRotation() bool#

Check if transform has rotation.

Returns:

True if the unit quaternion is non-identity.

hasTranslation() bool#

Check if transform has translation.

Returns:

True if translation is non-zero.

inverse() HomTran#

Get the inverse of this transform.

Returns:

Inverse transform.

isApprox(other: HomTran, prec: SupportsFloat = 1e-12) bool#

Check if two transforms are approximately equal.

Parameter other:

The other HomTran to compare with.

Parameter prec:

Tolerance for comparison.

Returns:

True if approximately equal.

isIdentity() bool#

Check if transform is identity.

Returns:

True if identity.

phi(arg0: SpatialVector) SpatialVector#

Apply the “phi” rigid body transform to a spatial vector.

See rigid body transformation matrix for a definition of the transformation matrix.

Parameter V:

Spatial vector.

Returns:

Transformed spatial vector.

See also

phiStar(), phiMatrix()

phiMat(arg0: Annotated[numpy.typing.ArrayLike, numpy.float64, [6, n]]) Annotated[numpy.typing.NDArray[numpy.float64], [6, n]]#

Apply phi transform to a 6xN matrix.

See rigid body transformation matrix for a definition of the transformation matrix.

Parameter m:

Input matrix.

Returns:

Transformed matrix.

See also

phiStar(), phiMatrix()

phiMatrix() Annotated[numpy.typing.NDArray[numpy.float64], [6, 6]]#

Get the phi rigid body transformation matrix.

See rigid body transformation matrix for a definition of the transformation matrix.

Returns:

Phi matrix.

See also

phi(), phiStar()

phiStar(arg0: SpatialVector) SpatialVector#

Apply the phi^* dual rigid body transformation to a spatial vector.

See rigid body transformation matrix for a definition of the transformation matrix.

Parameter V:

Input spatial vector.

Returns:

Transformed vector.

See also

phi(), phiMatrix()

phiStarMat(arg0: Annotated[numpy.typing.ArrayLike, numpy.float64, [6, n]]) Annotated[numpy.typing.NDArray[numpy.float64], [6, n]]#

Apply the phi^* dual rigid body transformation to a 6xN matrix.

See rigid body transformation matrix for a definition of the transformation matrix.

Parameter m:

Input matrix.

Returns:

Transformed matrix.

phiStarSymmetric(sv: Annotated[numpy.typing.ArrayLike, numpy.float64, [6, 6]]) Annotated[numpy.typing.NDArray[numpy.float64], [6, 6]]#

Compute the phi^* * m * phi dual rigid body symmetric transformation for a 6x6 matrix.

See rigid body transformation matrix for a definition of the transformation matrix.

Parameter m:

Input matrix.

Returns:

Transformed symmetric matrix.

See also

phi(), phiMatrix()

phiStarVec(arg0: Annotated[numpy.typing.ArrayLike, numpy.float64, [6, 1]]) SpatialVector#

Apply the phi^* dual rigid body transformation to a 6D vector.

See rigid body transformation matrix for a definition of the transformation matrix.

Parameter V:

Input 6-vector.

Returns:

Transformed 6-vector.

See also

phi(), phiMatrix()

phiSymmetric(arg0: Annotated[numpy.typing.ArrayLike, numpy.float64, [6, 6]]) Annotated[numpy.typing.NDArray[numpy.float64], [6, 6]]#

Compute phi * m * phi^* symmetric rigid body transformation to a 6x6 matrix.

See rigid body transformation matrix for a definition of the transformation matrix.

Parameter m:

Input matrix.

Returns:

Transformed symmetric matrix.

See also

phiStar(), phiMatrix()

phiVec(arg0: Annotated[numpy.typing.ArrayLike, numpy.float64, [6, 1]]) SpatialVector#

Apply “phi” rigid body transform to a 6D vector.

See rigid body transformation matrix for a definition of the transformation matrix.

Parameter V:

Input 6-vector.

Returns:

Transformed 6-vector.

See also

phiStar(), phiMatrix()

setIdentity() None#

Set the transform to identity.

setTranslation(vec: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]], epsilon: SupportsFloat = 1e-12) None#

Set the translation vector.

Parameter vec:

The translation vector.

Parameter epsilon:

Tolerance for checking whether the translation is zero.

setUnitQuaternion(q: UnitQuaternion, epsilon: SupportsFloat = 1e-12) None#

Set the unit quaternion (rotation part).

Parameter q:

Unit quaternion.

Parameter epsilon:

Tolerance for checking whether the unit quaternion is identity.

toVector6() Annotated[numpy.typing.NDArray[numpy.float64], [6, 1]]#

Convert to a 6D vector [rotation_vector; translation].

Returns:

The 6D vector representation.

typeString() str#

Get a string representing the type.

Returns:

The string “HomTran”.

class Karana.Math.HybridNonLinearSolverStatus(value: SupportsInt)#

Status of the HybridNonLinearSolver solver

Members:

Running

ImproperInputParameters

RelativeErrorTooSmall

TooManyFunctionEvaluation

TolTooSmall

NotMakingProgressJacobian

NotMakingProgressIterations

UserAsked

ImproperInputParameters: ClassVar[HybridNonLinearSolverStatus]#
NotMakingProgressIterations: ClassVar[HybridNonLinearSolverStatus]#
NotMakingProgressJacobian: ClassVar[HybridNonLinearSolverStatus]#
RelativeErrorTooSmall: ClassVar[HybridNonLinearSolverStatus]#
Running: ClassVar[HybridNonLinearSolverStatus]#
TolTooSmall: ClassVar[HybridNonLinearSolverStatus]#
TooManyFunctionEvaluation: ClassVar[HybridNonLinearSolverStatus]#
UserAsked: ClassVar[HybridNonLinearSolverStatus]#
__members__: ClassVar[dict[str, HybridNonLinearSolverStatus]]#
__eq__(other: Any) bool#
__getstate__() int#
__hash__() int#
__index__() int#
__int__() int#
__ne__(other: Any) bool#
__repr__() str#
__setstate__(state: SupportsInt) None#
__str__() str#
property name: str#
property value: int#
class Karana.Math.Jacobian(input_dim: SupportsInt, value_dim: SupportsInt, f: collections.abc.Callable[[Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]], Annotated[numpy.typing.NDArray[numpy.float64], [m, 1], flags.writeable]], None], mode: Literal['forward', 'central'] = 'forward')#

@class Jacobian Class used to create a Jacobian for a given function using numerical differencing.

__call__(arg0: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]#

Calculate the jacobian of the supplied function.

Parameter x:

The input vector we want to calculate the jacobian with respect to.

Returns:

The jacobian of the supplied function about x.

getF() collections.abc.Callable[[Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]], Annotated[numpy.typing.NDArray[numpy.float64], [m, 1], flags.writeable]], None]#

Get the function that this Jacobian class calculates the jacobian of.

Returns:

f The function that this Jacobian class calculates the jacobian of.

getMode() str#

Get the finite difference mode.

Returns:

f The finite difference mode.

setF(f: collections.abc.Callable[[Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]], Annotated[numpy.typing.NDArray[numpy.float64], [m, 1], flags.writeable]], None]) None#

Set the function that this class calcualtes the jacobian of.

Parameter f:

The function that you want to calcualte the jacobian of.

setMode(arg0: str) None#

Sets finite difference mode.

Parameter mode:

The finite difference mode. One of “forward” or “central”.

class Karana.Math.LevenbergMarquardtStatus(value: SupportsInt)#

Status of the LevenbergMarquardt solver

Members:

NotStarted

Running

ImproperInputParameters

RelativeReductionTooSmall

RelativeErrorTooSmall

RelativeErrorAndReductionTooSmall

CosinusTooSmall

TooManyFunctionEvaluation

FtolTooSmall

XtolTooSmall

GtolTooSmall

UserAsked

CosinusTooSmall: ClassVar[LevenbergMarquardtStatus]#
FtolTooSmall: ClassVar[LevenbergMarquardtStatus]#
GtolTooSmall: ClassVar[LevenbergMarquardtStatus]#
ImproperInputParameters: ClassVar[LevenbergMarquardtStatus]#
NotStarted: ClassVar[LevenbergMarquardtStatus]#
RelativeErrorAndReductionTooSmall: ClassVar[LevenbergMarquardtStatus]#
RelativeErrorTooSmall: ClassVar[LevenbergMarquardtStatus]#
RelativeReductionTooSmall: ClassVar[LevenbergMarquardtStatus]#
Running: ClassVar[LevenbergMarquardtStatus]#
TooManyFunctionEvaluation: ClassVar[LevenbergMarquardtStatus]#
UserAsked: ClassVar[LevenbergMarquardtStatus]#
XtolTooSmall: ClassVar[LevenbergMarquardtStatus]#
__members__: ClassVar[dict[str, LevenbergMarquardtStatus]]#
__eq__(other: Any) bool#
__getstate__() int#
__hash__() int#
__index__() int#
__int__() int#
__ne__(other: Any) bool#
__repr__() str#
__setstate__(state: SupportsInt) None#
__str__() str#
property name: str#
property value: int#
class Karana.Math.LinearInterpolator(indep: Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]], dep: Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]], extrapolation: LinearInterpolator.Extrapolation | None = None)#

Bases: BaseInterpolator

Piecewise linear interpolation method */

class Extrapolation(value: SupportsInt)#

Members:

Constant

Linear

Constant: ClassVar[LinearInterpolator]#
Linear: ClassVar[LinearInterpolator]#
__members__: ClassVar[dict[str, LinearInterpolator]]#
__eq__(other: Any) bool#
__getstate__() int#
__hash__() int#
__index__() int#
__int__() int#
__ne__(other: Any) bool#
__repr__() str#
__setstate__(state: SupportsInt) None#
__str__() str#
property name: str#
property value: int#
Constant: ClassVar[LinearInterpolator]#
Linear: ClassVar[LinearInterpolator]#
Karana.Math.MATH_EPSILON: float = 1e-12#
class Karana.Math.NearestNeighborInterpolator(indep: Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]], dep: Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]])#

Bases: BaseInterpolator

Nearest neighbor interpolation method */

class Karana.Math.NonlinearSolver(name: str, input_dim: SupportsInt, value_dim: SupportsInt, f: collections.abc.Callable[[Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]], Annotated[numpy.typing.NDArray[numpy.float64], [m, 1], flags.writeable]], None], j: collections.abc.Callable[[Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]], Annotated[numpy.typing.NDArray[numpy.float64], [m, n], flags.writeable, flags.c_contiguous]], None] = None)#

Bases: Karana.Core.LockingBase

NonlinearSolver class manages a nonlinear problem and associated solver.

static create(name: str, input_dim: SupportsInt, value_dim: SupportsInt, f: collections.abc.Callable[[Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]], Annotated[numpy.typing.NDArray[numpy.float64], [m, 1], flags.writeable]], None], j: collections.abc.Callable[[Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]], Annotated[numpy.typing.NDArray[numpy.float64], [m, n], flags.writeable, flags.c_contiguous]], None] = None) NonlinearSolver#

NonlinearSolver constructor. This is a container that holds the information needed to solve a nonlinear problem. However, the solver itself is not added during construction. You must either pass in a solver with setSolver or create one with createSolver.

Parameter name:

The name of the Nonlinear solver.

Parameter input_dim:

The number of inputs.

Parameter value_dim:

The number of values (outputs).

Parameter f:

The cost function. This should take in a vector of inputs and output a vector of outputs.

Parameter j:

The jacobian function. This is optional, if not specified, the jacobian will be computed by forward numerical differentiation.

Returns:

A ks_ptr to a new Nonlinear solver instance.

createSolver(solver: solver_enum) None#

Create a solver of the given type. This will return a copy of the shared pointer to the solver as well as set the solver for this NonlinearSolver.

Parameter solver:

The solver type to create.

Returns:

The solver that was created.

getF() collections.abc.Callable[[Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]], Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]], None]#

Get the cost function.

Returns:

The cost function.

getJac() collections.abc.Callable[[Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]], Annotated[numpy.typing.ArrayLike, numpy.float64, [m, n]]], None]#

Get the jacobian function.

Returns:

The jacobian function.

setF(f: collections.abc.Callable[[Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]], Annotated[numpy.typing.NDArray[numpy.float64], [m, 1], flags.writeable]], None]) None#

Set the cost function. After setting the function, you will need to re-create the solver if one has already been set. Otherwise, the solver will still retain the old cost function.

Parameter f:

The cost function.

setJac(jac: collections.abc.Callable[[Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]], Annotated[numpy.typing.NDArray[numpy.float64], [m, n], flags.writeable, flags.c_contiguous]], None]) None#

Set the jacobian function. After setting the jacobian.function, you will need to re-create the solver if one has already been set. Otherwise, the solver will still retain the old cost function.

Parameter jac:

The jacobian function.

solve(x: Annotated[numpy.typing.NDArray[numpy.float64], [m, 1], flags.writeable]) float#

Solve the nonlinear system.

Parameter x:

The initial guess.

Returns:

The norm squared of the final cost error.

property status: LevenbergMarquardtStatus | HybridNonLinearSolverStatus#
class Karana.Math.RotationMatrix#
class Karana.Math.RotationMatrix(mat: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 3]], orthogonalize: bool = False, skip_values_check: bool = False)
class Karana.Math.RotationMatrix(rotvec: RotationVector)
__hash__: ClassVar[None] = None#
__eq__(other: RotationMatrix) bool#

Equality operator.

Parameter other:

RotationMatrix to compare with.

Returns:

True if equal, false otherwise.

__repr__() str#
asArray() Annotated[numpy.typing.NDArray[numpy.float64], [3, 3]]#

Return the rotation matrix as a numpy array.

isApprox(other: RotationMatrix, prec: SupportsFloat = 1e-12) bool#

Approximate equality check.

Parameter other:

RotationMatrix to compare with.

Parameter prec:

Precision threshold.

Returns:

True if approximately equal, false otherwise.

setValues(mat: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 3]], orthogonalize: bool = False, skip_values_check: bool = False) None#

Assign external values from a 3x3 matrix

Since there is no guarantee on the values of the input matrix, we need to be careful to enable appropriate checks and orthogonalization as needed.

Parameter mat:

Input matrix.

Parameter orthogonalize:

If true, orthogonalize the input values.

Parameter skip_values_check:

If true, skip check that the matrix is orthogonal.

typeString() str#

Get the type string of this class.

Returns:

“RotationMatrix”

class Karana.Math.RotationVector(v: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]])#
__hash__: ClassVar[None] = None#
__eq__(other: RotationVector) bool#

Equality operator.

Parameter other:

RotationVector to compare with.

Returns:

True if equal, false otherwise.

__repr__() str#
angle() float#

Return rotation angle.

Returns:

The rotation angle.

dumpString(prefix: str = '', precision: SupportsInt = 6, exponential: bool = False) str#

Get a string representation of the RotationVector.

Parameter prefix:

String prefix for each line.

Parameter precision:

Number of digits to use for floating point values.

Parameter exponential:

Use exponential notation if true.

Returns:

String with information about this RotationVector.

isApprox(other: RotationVector, prec: SupportsFloat = 1e-12) bool#

Approximate equality check.

Parameter other:

RotationVector to compare with.

Parameter prec:

Precision threshold.

Returns:

True if approximately equal, false otherwise.

omega2rates(omega: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]], oframe: bool) Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

Compute the coeff rates from the angular velocity

Parameter omega:

The 3-vector angular velocity.

Parameter oframe:

If true, the angular velocity is in the ‘from’ frame, else in the ‘to’ frame.

Returns:

The coefficient rates from the omega angular velocity

omega2ratesMap(arg0: bool) Annotated[numpy.typing.NDArray[numpy.float64], [3, 3]]#

Compute the angular velocity from coeff rates

Parameter rates:

The 3-vector with coefficient rates.

Parameter oframe:

If true, the angular velocity is in the ‘from’ frame, else in the ‘to’ frame.

Returns:

The angular velocity that cooresponds to the rates.

rates2omega(arg0: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]], arg1: bool) Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

Compute the angular velocity from coeff rates

Parameter rates:

The 3-vector with coefficient rates.

Parameter oframe:

If true, the angular velocity is in the ‘from’ frame, else in the ‘to’ frame.

Returns:

The angular velocity that cooresponds to the rates.

rates2omegaMap(arg0: bool) Annotated[numpy.typing.NDArray[numpy.float64], [3, 3]]#

Compute the angular velocity from coeff rates

Parameter rates:

The 3-vector with coefficient rates.

Parameter oframe:

If true, the angular velocity is in the ‘from’ frame, else in the ‘to’ frame.

Returns:

The angular velocity that cooresponds to the rates.

rates2quatratesMap() Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]#

The 4x3 matrix that maps the rotation vector rates to quaternion rates.

Returns:

The 4x3 matrix map.

toVec3() Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

Return the RotationVector as a Vec3.

Returns:

This RotationVector as a Vec3.

unitAxis() Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

Return rotation angle.

Returns:

The rotation angle.

class Karana.Math.SimTran(transform: HomTran)#
class Karana.Math.SimTran(scale: SupportsFloat)
class Karana.Math.SimTran(transform: HomTran, scale: SupportsFloat)
__hash__: ClassVar[None] = None#
__eq__(other: SimTran) bool#

Equality operator.

Parameter other:

SimTran to compare with.

Returns:

True if equal, false otherwise.

__mul__(T: SimTran) SimTran#
__mul__(v: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]]) Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]

Compose this SimTran with another.

Parameter T:

Another SimTran to apply after this one.

Returns:

Combined transform.

__repr__() str#
dump(prefix: str = '', precision: SupportsInt = 10, exponential: bool = False) None#

Print dumpString to std::cout.

Parameter prefix:

String prefix for each line.

Parameter precision:

Number of digits to use for floating point values.

Parameter exponential:

Use exponential notation if true.

dumpString(prefix: str = '', precision: SupportsInt = 10, exponential: bool = False) str#

Get a string representation of the SimTran.

Parameter prefix:

String prefix for each line.

Parameter precision:

Number of digits to use for floating point values.

Parameter exponential:

Use exponential notation if true.

Returns:

String with information about this SimTran.

getMatrix() Annotated[numpy.typing.NDArray[numpy.float64], [4, 4]]#

Get the full 4x4 transformation matrix.

Returns:

4x4 transformation matrix.

getScale() float#

Get the scale factor.

Returns:

Scale factor.

getTranslation() Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

Get the translation vector.

Returns:

Translation vector.

getUnitQuaternion() UnitQuaternion#

Get the rotation of the SimTran as a unit quaternion.

Returns:

Unit quaternion.

hasRotation() bool#

Check if the SimTran has a rotation.

Returns:

True if unit quaternion is non-identity, false otherwise.

hasScale() bool#

Check if the SimTran includes a scale.

Returns:

True if scale is not 1.0, false otherwise.

hasTranslation() bool#

Check if the SimTran has a non-zero translation.

Returns:

True if translation is non-zero, false otherwise.

inverse() SimTran#

Get the inverse of this SimTran.

Returns:

Inverse SimTran.

isApprox(other: SimTran, prec: SupportsFloat = 1e-12) bool#

Approximate equality check.

Parameter other:

SimTran to compare with.

Parameter prec:

Precision threshold.

Returns:

True if approximately equal, false otherwise.

isIdentity() bool#

Check if the SimTran is identity.

Returns:

True if identity, false otherwise.

setIdentity() None#

Set the SimTran to identity.

setScale(scale: SupportsFloat) None#

Set the scale factor.

Parameter scale:

Scale value.

setTranslation(vec: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]], epsilon: SupportsFloat = 1e-12) None#

Set the translation vector.

Parameter vec:

Translation vector.

Parameter epsilon:

Precision threshold used to check if the translation is zero.

setUnitQuaternion(q: UnitQuaternion, epsilon: SupportsFloat = 1e-12) None#

Set the rotation using a unit quaternion.

Parameter q:

Unit quaternion.

Parameter epsilon:

Precision threshold to check if the unit quaternion is identity.

typeString() str#

Get the type string of this class.

Returns:

“SimTran”

class Karana.Math.SpatialInertia#
class Karana.Math.SpatialInertia(mass: SupportsFloat, b2cm: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]], inertia: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 3]], validate: bool = True)
__hash__: ClassVar[None] = None#
__add__(other: SpatialInertia) SpatialInertia#

Add SpatialInertias. The two SpatialInertias are assumed to be about a common frame.

Parameter other:

The SpatialInertia to add to this one.

Returns:

Resultant SpatialInertia.

__eq__(other: SpatialInertia) bool#

Equality operator.

Parameter other:

SpatialInertia to compare with.

Returns:

True if equal, false otherwise.

__iadd__(other: SpatialInertia) SpatialInertia#

Add another SpatialInertia to this one in-place. The two SpatialInertias are assumed to be about a common frame.

Parameter other:

The SpatialInertia to add to this one.

Returns:

Reference to this SpatialInertia.

__isub__(other: SpatialInertia) SpatialInertia#

Subtract another SpatialInertia from this one in-place. The two SpatialInertias are assumed to be about a common frame.

Parameter other:

The SpatialInertia to subtract from this one.

Returns:

Reference to this SpatialInertia.

__mul__(vec: SpatialVector) SpatialVector#

Multiplies the spatial inertia with a spatial vector.

Parameter vec:

The spatial vector to multiply.

Returns:

The resulting spatial vector after multiplication.

__repr__() str#
__sub__(other: SpatialInertia) SpatialInertia#

Subtract SpatialInertias. The two SpatialInertias are assumed to be about a common frame.

Parameter other:

The SpatialInertia to subtract from this one.

Returns:

Resultant SpatialInertia.

b2cm() Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

Returns the vector from the body frame to the center of mass.

Returns:

The vector from the body frame to the center of mass.

cmInertia() Annotated[numpy.typing.NDArray[numpy.float64], [3, 3]]#

Returns the inertia matrix about the center of mass.

Returns:

The inertia matrix about the center of mass.

dump(prefix: str = '', precision: SupportsInt = 10, exponential: bool = False) None#

Print dumpString to std::cout.

Parameter prefix:

String prefix for each line.

Parameter precision:

Number of digits to use for floating point values.

Parameter exponential:

Use exponential notation if true.

dumpString(prefix: str = '', precision: SupportsInt = 10, exponential: bool = False) str#

Get a string representation of this SpatialInertia.

Parameter prefix:

String prefix for each line.

Parameter precision:

Number of digits to use for floating point values.

Parameter exponential:

Use exponential notation if true.

Returns:

String with information about this SpatialInertia.

inertia() Annotated[numpy.typing.NDArray[numpy.float64], [3, 3]]#

Returns the inertia matrix in the body frame.

Returns:

The inertia matrix in the body frame.

isApprox(other: SpatialInertia, prec: SupportsFloat = 1e-12) bool#

Approximate equality check.

Parameter other:

SpatialInertia to compare with.

Parameter prec:

Precision threshold.

Returns:

True if approximately equal, false otherwise.

mass() float#

Returns the mass of the object.

Returns:

The mass of the object.

matrix() Annotated[numpy.typing.NDArray[numpy.float64], [6, 6]]#

Returns the 6x6 matrix representation of the spatial inertia.

Returns:

The 6x6 matrix representation of the spatial inertia.

mp() Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

Returns the b2cm * mass.

Returns:

The mass * b2cm.

parallelAxis(arg0: HomTran) SpatialInertia#

Returns the type name of the object.

Returns:

A string representing the type name of the object.

setZero() None#

Zero out the spatial inertia. */

typeString() str#

Returns the type name of the object.

Returns:

A string representing the type name of the object.

class Karana.Math.SpatialVector#
class Karana.Math.SpatialVector(sv: Annotated[numpy.typing.ArrayLike, numpy.float64, [6, 1]])
class Karana.Math.SpatialVector(w: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]], v: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]])
__hash__: ClassVar[None] = None#
static to_json(o: SpatialVector) dict[str, Any]#

Class method used to represent SpatialVector in a json file.

classmethod from_json(d: dict[str, Any]) Self#

Construct a SpatialVector from json file data.

classmethod from_yaml(loader, node) Self#

Construct a SpatialVector from yaml file data.

classmethod to_yaml(representer, node)#

Class method used to represent SpatialVector in a yaml file.

__add__(other: SpatialVector) SpatialVector#

Component-wise addition.

Parameter other:

The SpatialVector to add to this one.

Returns:

Resulting SpatialVector sum.

__eq__(other: SpatialVector) bool#
__getstate__() tuple#
__mul__(arg0: SpatialVector) float#
__mul__(arg0: SupportsFloat) SpatialVector

Scalar multiplication.

Parameter scale:

Scalar value to multiply by.

Returns:

Scaled SpatialVector.

__repr__()#
__setstate__(arg0: tuple) None#
__sub__(other: SpatialVector) SpatialVector#

Negation operator.

Returns:

Negated SpatialVector.

barprod(other: SpatialVector) SpatialVector#

Compute the bar product with another spatial vector.

f[ bar A B = - {tilde A}^* B = begin{bmatrix} tilde A_w & tilde A_v \ 0 & tilde A_w end{bmatrix} begin{bmatrix} B_w \ B_v end{bmatrix} f]

Parameter other:

The SpatialVector to compute the bar product with.

Returns:

Resulting SpatialVector.

cross(other: SpatialVector) SpatialVector#

Compute 6-D cross product with another spatial vector.

@f[ A times B = tilde A B = begin{bmatrix} tilde A_w & tilde A_v \ 0 & tilde A_w end{bmatrix} begin{bmatrix} B_w \ B_v end{bmatrix} @f]

Parameter other:

The SpatialVector to compute the cross product with.

Returns:

Resulting SpatialVector.

dump(prefix: str = '', precision: SupportsInt = 10, exponential: bool = False) None#

Write dumpString to std::cout.

Parameter prefix:

Optional prefix for each line.

Parameter precision:

Number of digits to use for floating point values.

Parameter exponential:

Use exponential formatting.

dumpString(prefix: str = '', precision: SupportsInt = 10, exponential: bool = False) str#

Dump the object as a formatted string.

Parameter prefix:

Optional prefix for each line.

Parameter precision:

Number of digits to use for floating point values.

Parameter exponential:

Use exponential formatting.

Returns:

Formatted string representation.

getv() Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

Get the linear portion of the spatial vector.

Returns:

Const reference to linear vector.

getw() Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

Get the angular portion of the spatial vector.

Returns:

Const reference to angular vector.

isApprox(other: SpatialVector, prec: SupportsFloat = 1e-12) bool#
isZero(prec: SupportsFloat = 1e-12) bool#

Return true if the spatial vector is zero.

Parameter prec:

Tolerance to use when comparing with zero.

Returns:

True if both angular and linear components are zero.

multiplyFromLeft(mat: Annotated[numpy.typing.ArrayLike, numpy.float64, [6, 6]]) SpatialVector#

Multiply from the vector from left with a matrix, i.e v * mat.

Parameter mat:

Matrix to multiply.

Returns:

Resulting SpatialVector.

setZero() None#

Zero out the spatial vector’s values.

setv(v: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]]) None#

Set the linear portion of the spatial vector.

Parameter v:

New linear vector.

setw(w: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]]) None#

Set the angular portion of the spatial vector.

Parameter w:

New angular vector.

toVector6() Annotated[numpy.typing.NDArray[numpy.float64], [6, 1]]#

Convert to a 6-vector by combining the w and v parts as [w;v].

Returns:

Combined 6D vector.

class Karana.Math.StateSpace(num_inputs: SupportsInt, num_outputs: SupportsInt, num_states: SupportsInt, state_deriv_fn: collections.abc.Callable[[Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]], Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]], Annotated[numpy.typing.NDArray[numpy.float64], [m, 1], flags.writeable]], None], output_fn: collections.abc.Callable[[Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]], Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]], Annotated[numpy.typing.NDArray[numpy.float64], [m, 1], flags.writeable]], None], mode: Literal['forward', 'central'] = 'forward')#

@class StateSpace Use provided non-linear equations to create a state space model of the form: x_dot = A*x + B*u, y = C*x + D*u from a nonlinear set of equations of the form x_dot = f(x,u), y = g(x,u)

generate(x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]], u: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) ss#

Generate a state space model by linearizing the system about x and u.

Parameter x:

The state vector, x, to generate about.

Parameter u:

The input vector, u, to generate about.

Returns:

A structure with the matrices for the state space model.

class Karana.Math.UnitQuaternion(x: SupportsFloat, y: SupportsFloat, z: SupportsFloat, w: SupportsFloat, renormalize: bool = False, skip_values_check: bool = False)#
class Karana.Math.UnitQuaternion(rv: RotationVector)
class Karana.Math.UnitQuaternion(array: Annotated[numpy.typing.ArrayLike, numpy.float64, [4, 1]], renormalize: bool = False, skip_values_check: bool = True)
class Karana.Math.UnitQuaternion(angle: SupportsFloat, axis: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]])
class Karana.Math.UnitQuaternion(v1: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]], v2: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]])
class Karana.Math.UnitQuaternion(rot: RotationMatrix)
class Karana.Math.UnitQuaternion(other: UnitQuaternion)
class Karana.Math.UnitQuaternion(ea: EulerAngles)
__hash__: ClassVar[None] = None#
static to_json(o: UnitQuaternion)#

Represent UnitQuaternion in a json file.

classmethod from_json(d: dict[str, Any]) Self#

Construct a UnitQuaternion from json file data.

classmethod from_yaml(loader, node) Self#

Construct a UnitQuaternion from yaml file data.

classmethod to_yaml(representer, node)#

Class method used to represent UnitQuaternion in a yaml file.

__eq__(arg0: UnitQuaternion) bool#
__getstate__() Annotated[numpy.typing.NDArray[numpy.float64], [4, 1]]#
__mul__(other: UnitQuaternion) UnitQuaternion#
__mul__(arg0: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]]) Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]
__mul__(arg0: SpatialVector) SpatialVector

Rotate the input 3-vector

Parameter vec:

3-vector to transform

Returns:

Transformed vector

__repr__()#
__setstate__(arg0: Annotated[numpy.typing.ArrayLike, numpy.float64, [4, 1]]) None#
dumpString(prefix: str = '', precision: SupportsInt = 6, exponential: bool = False) str#

Get a string representation of the UnitQuaternion.

Parameter prefix:

String prefix for each line.

Parameter precision:

Number of digits to use for floating point values.

Parameter exponential:

Use exponential notation if true.

Returns:

String with information about this UnitQuaternion.

inverse() UnitQuaternion#

Return the inverse of the quaternion

Returns:

the inverse quaternion

isApprox(other: UnitQuaternion, prec: SupportsFloat = 1e-12) bool#

Check whether this quaternion is approximately the same as another.

This method will also return true if the coefficients are approximately negative of all the coefficients of the other (since both unit quaternions then represent the same rotation).

Parameter other:

the other quaternion

Parameter prec:

the tolerance value

Returns:

true, if the quaternions are the same within the specfied tolerance

isIdentity(epsilon: SupportsFloat = 1e-12) bool#

Check whether this quaternion is the identity quaterion

Parameter epsilon:

the tolerance value

Returns:

true, if the quaternion is the identity quaternion; false otherwise.

omega2rates(omega: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]], oframe: bool) Annotated[numpy.typing.NDArray[numpy.float64], [4, 1]]#

Compute the quaternion coeff rates for an angular velocity

Parameter omega:

the input angular velocity

Parameter oframe:

if true, the angular velocity is in the ‘from’ frame, else the ‘to’ frame

Returns:

the 4-vector with coefficient rates

See also

quatVecDot2omegaMap(), omega2quatVecDotMap(), omega2quat0DotMap()

omega2ratesMap(arg0: bool) Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]#

The 4x3 matrix that maps the angular velocity to the coefficient rates

Parameter oframe:

if true, the angular velocity is in the ‘from’ frame, else the ‘to’ frame

Returns:

the 4x3 matrix map

omega2scalarRateMap() Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

The 3-vecor whose dot product with the angular velocity yeilds the scalar coeff rates

This expression is the same whether the angular velocity is in the oframe or not

Returns:

the 3 vector map

See also

quatVecDot2omegaMap(), omega2quatVecDotMap(), omega2quat0DotMap()

omega2vectorRatesMap(oframe: bool) Annotated[numpy.typing.NDArray[numpy.float64], [3, 3]]#

The 3x3 matrix that maps the angular velocity to the quaternion vector rates

Parameter oframe:

if true, the angular velocity is in the ‘from’ frame, else in the ‘to’ frame

Returns:

the 3x3 matrix map

See also

quatVecDot2omegaMap(), omega2quatVecDotMap(), omega2quat0DotMap()

rates2omegaMap(arg0: bool) Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]#

The 3x4 matrix that maps the coefficient rates to the angular velocity

Parameter oframe:

if true, the angular velocity is in the ‘from’ frame, else the ‘to’ frame.

Returns:

the 3x4 matrix map

rates2rotvecratesMap() Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]#

The 3x4 matrix that maps quaternion rates to rot vector rates

Returns:

the 3x4 matrix map

rotate(mat: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 3]]) Annotated[numpy.typing.NDArray[numpy.float64], [3, 3]]#

Apply a rotational transformation symmetrically to a 3x3 matrix.

Multiply the input 3x3 matrix from the left by R, and the right by R transpose: R * M * R_T. Here, R denotes the 3x3 rotation matrix for this quaternion.

Parameter mat:

3x3 matrix to transform

Returns:

Transformed matrix

See also

inverseRotate66()

rotate66(mat: Annotated[numpy.typing.ArrayLike, numpy.float64, [6, 6]]) Annotated[numpy.typing.NDArray[numpy.float64], [6, 6]]#

Apply a rotational transformation symmetrically to a 6x6 matrix.

Multiply the input 6x6 matrix from both sides by (R_block_diag) * M * (R_block_diag)_T. Here, R_block_diag denotes a 6x6 matrix containing the 3x3 rotation matrix for this quaternion repeated along the block diagonal.

Parameter mat:

6x6 matrix to transform

Returns:

Transformed matrix

See also

inverseRotate66()

rotateLeft6N(mat: Annotated[numpy.typing.ArrayLike, numpy.float64, [6, n]]) Annotated[numpy.typing.NDArray[numpy.float64], [6, n]]#

Apply a rotational transformation from the left to a 6xN matrix.

Multiply the input 6xN matrix from the left as (R_block_diag) * M. Here, R_block_diag denotes a 6x6 matrix containing the 3x3 rotation matrix for this quaternion repeated along the block diagonal.

Parameter mat:

6xN matrix to transform

Returns:

Transformed matrix

See also

rotateRightN6()

rotateRightN6(mat: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, n]]) Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]#

Apply a rotational transformation from the right to a Nx6 matrix.

Multiply the input Nx6 matrix from the right as M * (R_block_diag). Here, R_block_diag denotes a 6x6 matrix containing the 3x3 rotation matrix for this quaternion repeated along the block diagonal.

Parameter mat:

Nx6 matrix to transform

Returns:

Transformed matrix

See also

rotateLeft6N()

setIdentity() None#

Set the unit quaternion to the identity value */

toAngleAxis() tuple[float, Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]]#

Return the angle/axis representation for the quaternion.

Returns:

angle/axis representation

toEulerAngles(euler_system: EulerSystem = EulerSystem.XYZ) EulerAngles#

Convert to EulerAngles with the specified EulerSystem.

Returns:

EulerAngles for this quaternion.

toRotationMatrix() RotationMatrix#

Return the rotation matrix for this quaternion.

The rotation matrix is recomputed if the current value is stale, else the cached value is returned.

Returns:

The rotation matrix representation of this UnitQuaternion.

toRotationVector() RotationVector#

Return the RotationVector representation for the quaternion.

Returns:

RotationVector representation

toVector4() Annotated[numpy.typing.NDArray[numpy.float64], [4, 1]]#

Return the quaternion elements as a 4-vector.

Note that the vector elements are in the beginning, and the last element is the scalar.

Returns:

4-vector of coefficients.

vec() Annotated[numpy.typing.NDArray[numpy.float64], [3, 1]]#

Return the 3-vector part of the quaternion coefficients

Returns:

3-vector coefficients.

vectorRates2omegaMap(oframe: bool, epsilon: SupportsFloat = 1e-12) Annotated[numpy.typing.NDArray[numpy.float64], [3, 3]]#

The 3x3 matrix that maps the quaternion vector rates to the angular velocity

Parameter oframe:

if true, the angular velocity is in the ‘from’ frame, else the ‘to’ frame

Parameter epsilon:

tolerance to check if close to 180 degree rotation

Returns:

the 3x3 matrix map

See also

quatVecDot2omegaMap(), omega2quatVecDotMap(), omega2quat0DotMap()

Karana.Math.buildNaNWithPayload(payload: SupportsInt) float#

Create a NaN double with a particular mantissa payload

Parameter payload:

The payload

Karana.Math.floatingPointExceptions(arg0: bool) None#

Function to enable/disable exceptions when there are floating point errors

This method is handy for tracking down the source of NaNs by using a source debugger to break on exceptions. This method is specifically for gcc compiled code.

Parameter enable:

If true, floating point exceptions will be raised, else disabled

Karana.Math.isNaNWithPayload(candidate: SupportsFloat, payload: SupportsInt) bool#

Whether a double is a NaN with a given mantissa payload

Parameter candidate:

The candidate double to check.

Parameter expected:

The payload to check for.

Returns:

Whether candidate is a NaN with the given payload.

Karana.Math.isUninitializedNaN(candidate: SupportsFloat) bool#

Whether a double is a NaN inidicating an uninitialized value

Parameter candidate:

The candidate double to check.

Returns:

Whether candidate is a NaN indicating an uninitialized value.

Karana.Math.ktimeToSeconds(arg0: float | numpy.timedelta64) float#

Convert a Ktime value to a double (units in seconds).

Parameter kt:

The Ktime value to convert.

Returns:

The converted time.

Karana.Math.secondsToKtime(arg0: SupportsFloat) numpy.timedelta64#

Convert a seconds (double) time value to Ktime

Parameter t:

The time in seconds to convert.

Returns:

The input time in seconds converted to a Ktime.

class Karana.Math.solver_enum(value: SupportsInt)#

Solver types used by the Nonlinear solver

Members:

LevenbergMarquardt

HybridNonLinearSolver

HybridNonLinearSolver: ClassVar[solver_enum]#
LevenbergMarquardt: ClassVar[solver_enum]#
__members__: ClassVar[dict[str, solver_enum]]#
__eq__(other: Any) bool#
__getstate__() int#
__hash__() int#
__index__() int#
__int__() int#
__ne__(other: Any) bool#
__repr__() str#
__setstate__(state: SupportsInt) None#
__str__() str#
property name: str#
property value: int#
class Karana.Math.ss#

State space return type. This holds the A, B, C, and D matrices that make up the state space model.

property A: Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]#
property B: Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]#
property C: Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]#
property D: Annotated[numpy.typing.NDArray[numpy.float64], [m, n]]#
Karana.Math.tilde(arg0: Annotated[numpy.typing.ArrayLike, numpy.float64, [3, 1]]) Annotated[numpy.typing.NDArray[numpy.float64], [3, 3]]#

Calcualte the 3x3 skew cross-product matrix for the input vector.

Parameter v:

The vector to compute the skew cross-product matrix for.

Returns:

The skew cross-product matrix.

Karana.Math.uninitializedNaN: float#
Karana.Math.uninitializedPayload: int = 1954#
class Karana.Math.ArkExplicitIntegrator#

Bases: Integrator

The multistep ArkODE explicit integrator from the SUNDIALS suite

class Karana.Math.ArkExplicitIntegratorOptions#

Bases: IntegratorOptions

Struct with options for this integrator

__assign__(arg0: ArkExplicitIntegratorOptions) ArkExplicitIntegratorOptions#
property atol: float#
property max_num_steps: int#

Maximum number of steps the solver can take before erroring

property rtol: float#
class Karana.Math.CVodeIntegrator#

Bases: Integrator

The multistep CVode integrator from the SUNDIALS suite

getErrorContributions() Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]#
class Karana.Math.CVodeIntegratorOptions#

Bases: IntegratorOptions

Struct with options for this integrator

__assign__(arg0: CVodeIntegratorOptions) CVodeIntegratorOptions#
property atol: float#
property max_num_steps: int#
property rtol: float#
property use_jacobian: bool#

set to true to have the integrator use Jacobians (experimental)

class Karana.Math.EulerIntegrator#

Bases: Integrator

The fixed-step Euler one step integrator.

class Karana.Math.Integrator#

Base class for numerical integrators

static create(integrator_tyoe: IntegratorType, nstates: SupportsInt, deriv_fn: collections.abc.Callable[[float | numpy.timedelta64, Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]], Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]], None], options: IntegratorOptions = None) Integrator#

Factory method for creating an Integrator instances

Parameter integrator_type:

the type of integrator to create

Parameter nstates:

the length of the states vector

Parameter deriv_fn:

the derivative function

Parameter options:

options for the integrator

Returns:

a new Integrator instance

advanceTo(to_t: float | numpy.timedelta64) numpy.timedelta64#

Method to advance the sytem state to a specified time

Parameter to_t:

the desired end time

Returns:

the actual end time

derivFunction() collections.abc.Callable[[float | numpy.timedelta64, Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]], Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]], None]#

Return the derivative function

Returns:

the derivative function

getIntegratorType() IntegratorType#

Get the IntegratorType for this integrator.

Returns:

The IntegratorType for this integrator.

getOptions() IntegratorOptions#

Get the options associated with the integrator.

Returns:

The options associated with the integrator.

getTime() numpy.timedelta64#

Return the current integrator time

Returns:

the integrator state time

getX() Annotated[numpy.typing.NDArray[numpy.float64], [m, 1]]#

Return the current integrator state

Returns:

the integrator state vector

hardReset(nstates: SupportsInt) None#

Reset the state size

Parameter nstates:

the new state size

nStates() int#

Return the state size

Returns:

the integrator state size

softReset(new_t: float | numpy.timedelta64, new_x: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, 1]]) None#

Reset the cached time and state and to the new values going forward

Parameter new_t:

the new time

Parameter new_x:

the new state

typeString() str#

Return the integrator type as a string

Returns:

the integrator type

updateJacobian(arg0: Annotated[numpy.typing.ArrayLike, numpy.float64, [m, n]]) None#

Update the stored Jacobian matrix with the provided one

This is currently an experimental feature - and not all integrators support the use of Jacobians.

Parameter mat:

the new Jacobian matrix

class Karana.Math.IntegratorOptions#

A struct with integrator options. This struct can be sub-classed by specialized classes to add custom options.

__assign__(arg0: IntegratorOptions) IntegratorOptions#
class Karana.Math.IntegratorType(value: SupportsInt)#

Members:

NO_OP

EULER

RK4

CVODE

CVODE_STIFF

CVODE_NEWTON

ARKEXPLICIT

ARKEXPLICIT_HUEN_EULER

ARKEXPLICIT_STIFF

ARKEXPLICIT_CASH

ARKEXPLICIT_FEHLBERG78

ARKEXPLICIT_DOPRI

IDA

ARKEXPLICIT: ClassVar[IntegratorType]#
ARKEXPLICIT_CASH: ClassVar[IntegratorType]#
ARKEXPLICIT_DOPRI: ClassVar[IntegratorType]#
ARKEXPLICIT_FEHLBERG78: ClassVar[IntegratorType]#
ARKEXPLICIT_HUEN_EULER: ClassVar[IntegratorType]#
ARKEXPLICIT_STIFF: ClassVar[IntegratorType]#
CVODE: ClassVar[IntegratorType]#
CVODE_NEWTON: ClassVar[IntegratorType]#
CVODE_STIFF: ClassVar[IntegratorType]#
EULER: ClassVar[IntegratorType]#
IDA: ClassVar[IntegratorType]#
NO_OP: ClassVar[IntegratorType]#
RK4: ClassVar[IntegratorType]#
__members__: ClassVar[dict[str, IntegratorType]]#
static to_json(o: IntegratorType) dict[str, Any]#

Class method used to represent IntegratorType in a json file.

classmethod from_json(d: dict[str, Any]) Self#

Construct a IntegratorType from json file data.

classmethod from_yaml(_, node) Self#

Construct an IntegratorType from yaml file data.

classmethod to_yaml(representer, node)#

Class method used to represent IntegratorType in a yaml file.

__eq__(other: Any) bool#
__getstate__() int#
__getstate__() str
__hash__() int#
__index__() int#
__int__() int#
__ne__(other: Any) bool#
__repr__() str#
__setstate__(state: SupportsInt) None#
__setstate__(arg0: str) None
__str__() str#
property name: str#
property value: int#
class Karana.Math.RK4Integrator#

Bases: Integrator

Fixed-step Runge-Kutta 4th order integrator

Karana.Math.strToIntegratorType(arg0: str) IntegratorType#