maspack.spatialmotion

Class SpatialVector

• All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Vector, Clonable
Direct Known Subclasses:
Twist, Wrench

```public abstract class SpatialVector
extends VectorBase
implements java.io.Serializable```
A spatial vector, which is a 6-vector composed of two 3-vectors: a free vector and a line vector. Spatial vectors are described in Featherstone, Robot Dynamics Algorithms, and are used to represent quantities such as spatial velocities (or twists), spatial forces (or wrenchs).

Spatial vectors are either contarvariant (those associated with motion), or covariant (those associated with forces). For a contravariant spatial vector, elements 0-2 correspond to the free vector and elements 3-5 correspond to the line vector. For a covarient spatial vector, elements 0-2 correspond to the line vector and elements 3-5 correspond to the free vector (note that this transposing of element ordering is different from the treatment in Featherstone, which always asigns elements 0-2 to the line vector).

Serialized Form
• Method Summary

All Methods
Modifier and Type Method and Description
`void` `absolute()`
Sets the elements of this spatial vector to their absolute values.
`SpatialVector` `clone()`
`void` ```cross(SpatialVector v1, SpatialVector v2)```
`double` `dot(SpatialVector v1)`
Returns the dot product of this spatial vector and the spatial vector v1.
`boolean` ```epsilonEquals(SpatialVector v1, double eps)```
Returns true if the elements of this spatial vector equal those of vector `v1`within a prescribed tolerance `epsilon`.
`boolean` `equals(SpatialVector v1)`
Returns true if the elements of this spatial vector exactly equal those of vector `v1`.
`void` `get(double[] values)`
Copies the elements of this spatial vector into an array of doubles.
`double` `get(int i)`
Gets a single element of this spatial vector.
`void` `get(Matrix1x6 M)`
Copies the value of this spatial vector into a Matrix1x6.
`void` `get(Matrix6x1 M)`
Copies the value of this spatial vector into a Matrix6x1.
`double` `infinityNorm()`
Returns the infinity norm of this spatial vector.
`void` `inverseTransform(RigidTransform3d X)`
Applies an inverse rigid spatial transformation to this vector, in place.
`void` `inverseTransform(RotationMatrix3d R)`
Applies an inverse rotational transformation to this spatial vector, in place.
`boolean` `isContravariant()`
Returns true if this spatial vector is contravariant.
`double` `maxElement()`
Returns the maximum element value of this spatial vector.
`double` `minElement()`
Returns the minimum element value of this spatial vector.
`void` ```mul(Matrix6d M, SpatialVector v1)```
Multiplies a spatial vector v1 by a Matrix6d and places the result in this spetial vector.
`void` `negate()`
Negates this spatial vector in place.
`double` `norm()`
Returns the 2 norm of this spatial vector.
`void` `normalize()`
Normalizes this spatial vector in place.
`double` `normSquared()`
Returns the square of the 2 norm of this spatial vector.
`double` `oneNorm()`
Returns the 1 norm of this spatial vector.
`void` `scale(double s)`
Scales the elements of this spatial vector by `s`.
`void` `set(double[] values)`
Sets the elements of this spatial vector from an array of doubles.
`int` ```set(double[] values, int idx)```
Sets the elements of this spatial vector from an array of doubles, starting from a particular location.
`void` ```set(int i, double value)```
Sets a single element of this spatial vector.
`void` `set(Matrix6x1 M)`
Sets the value of this spatial vector from the contents of a Matrix6x1.
`void` `setRandom()`
Sets the elements of this vector to uniformly distributed random values in the range -0.5 (inclusive) to 0.5 (exclusive).
`void` ```setRandom(double lower, double upper)```
Sets the elements of this vector to uniformly distributed random values in a specified range.
`void` ```setRandom(double lower, double upper, java.util.Random generator)```
Sets the elements of this vector to uniformly distributed random values in a specified range, using a supplied random number generator.
`void` `setZero()`
Sets the elements of this spatial vector to zero.
`int` `size()`
Returns the size of this spatial vector (which is always 6)
`java.lang.String` `toString(NumberFormat fmt)`
Returns a String representation of this vector, in which each element is formatted using a C `printf` style format as decribed by the parameter `NumberFormat`.
`void` `transform(RigidTransform3d X)`
Applies a rigid spatial transformation to this spatial vector, in place.
`void` `transform(RotationMatrix3d R)`
Applies a rotational transformation to this spatial vector, in place.
• Methods inherited from class maspack.matrix.VectorBase

`containsNaN, copy, copyAndAdd, copyAndNegate, copyAndScale, copyAndSub, copyAndSubLeft, dot, epsilonEquals, equals, get, getDefaultFormat, hasInf, hasNaN, isColumnVectorStringsVertical, isFixedSize, isRowVector, isWritable, scan, scan, set, set, setColumnVectorStringsVertical, setDefaultFormat, setRowVector, setSize, toString, toString, write, write, write, writeToFile`
• Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• Method Detail

• size

`public int size()`
Returns the size of this spatial vector (which is always 6)
Specified by:
`size` in interface `Vector`
Specified by:
`size` in class `VectorBase`
Returns:
6
• isContravariant

`public boolean isContravariant()`
Returns true if this spatial vector is contravariant.
Returns:
true for contravariant vectors.
• get

`public double get(int i)`
Gets a single element of this spatial vector. The element ordering depends on whether the vector is contravariant or covariant.
Specified by:
`get` in interface `Vector`
Specified by:
`get` in class `VectorBase`
Parameters:
`i` - element index
Returns:
element value throws ArrayIndexOutOfBoundsException if i is not in the range 0 to 5.
• get

`public void get(double[] values)`
Copies the elements of this spatial vector into an array of doubles. The array must have a length `>=` 6. The element ordering depends on whether the vector is contravariant or covariant.
Specified by:
`get` in interface `Vector`
Overrides:
`get` in class `VectorBase`
Parameters:
`values` - array into which values are copied
• get

`public void get(Matrix6x1 M)`
Copies the value of this spatial vector into a Matrix6x1.
Parameters:
`M` - matrix to be set
• get

`public void get(Matrix1x6 M)`
Copies the value of this spatial vector into a Matrix1x6.
Parameters:
`M` - matrix to be set
• set

```public void set(int i,
double value)```
Sets a single element of this spatial vector. The element ordering depends on whether the vector is contravariant or covariant.
Specified by:
`set` in interface `Vector`
Specified by:
`set` in class `VectorBase`
Parameters:
`i` - element index
`value` - element value
Throws:
`java.lang.ArrayIndexOutOfBoundsException` - if i is not in the range 0 to 5.
• set

`public void set(double[] values)`
Sets the elements of this spatial vector from an array of doubles. The array must have a length of at least 6. The element ordering depends on whether the vector is contravariant or covariant.
Specified by:
`set` in interface `Vector`
Overrides:
`set` in class `VectorBase`
Parameters:
`values` - array from which values are copied
• set

```public int set(double[] values,
int idx)```
Sets the elements of this spatial vector from an array of doubles, starting from a particular location. The array must extend for at least 6 elements beyond that location.
Specified by:
`set` in interface `Vector`
Parameters:
`values` - array from which values are copied
`idx` - starting point within values from which copying should begin
Returns:
updated idx value
• set

`public void set(Matrix6x1 M)`
Sets the value of this spatial vector from the contents of a Matrix6x1.
Parameters:
`M` - matrix giving new values
• negate

`public void negate()`
Negates this spatial vector in place.
• scale

`public void scale(double s)`
Scales the elements of this spatial vector by `s`.
Parameters:
`s` - scaling factor
• norm

`public double norm()`
Returns the 2 norm of this spatial vector. This is the square root of the sum of the squares of the elements.
Specified by:
`norm` in interface `Vector`
Overrides:
`norm` in class `VectorBase`
Returns:
vector 2 norm
• normSquared

`public double normSquared()`
Returns the square of the 2 norm of this spatial vector. This is the sum of the squares of the elements.
Specified by:
`normSquared` in interface `Vector`
Overrides:
`normSquared` in class `VectorBase`
Returns:
square of the 2 norm
• maxElement

`public double maxElement()`
Returns the maximum element value of this spatial vector.
Specified by:
`maxElement` in interface `Vector`
Overrides:
`maxElement` in class `VectorBase`
Returns:
maximal element
• minElement

`public double minElement()`
Returns the minimum element value of this spatial vector.
Specified by:
`minElement` in interface `Vector`
Overrides:
`minElement` in class `VectorBase`
Returns:
minimal element
• infinityNorm

`public double infinityNorm()`
Returns the infinity norm of this spatial vector. This is the maximum absolute value over all elements.
Specified by:
`infinityNorm` in interface `Vector`
Overrides:
`infinityNorm` in class `VectorBase`
Returns:
vector infinity norm
• oneNorm

`public double oneNorm()`
Returns the 1 norm of this spatial vector. This is the sum of the absolute values of the elements.
Specified by:
`oneNorm` in interface `Vector`
Overrides:
`oneNorm` in class `VectorBase`
Returns:
vector 1 norm
• dot

`public double dot(SpatialVector v1)`
Returns the dot product of this spatial vector and the spatial vector v1.
Returns:
dot product
• normalize

`public void normalize()`
Normalizes this spatial vector in place.
• epsilonEquals

```public boolean epsilonEquals(SpatialVector v1,
double eps)```
Returns true if the elements of this spatial vector equal those of vector `v1`within a prescribed tolerance `epsilon`.
Parameters:
`v1` - vector to compare with
`eps` - comparison tolerance
Returns:
false if the vectors are not equal within the specified tolerance
• equals

`public boolean equals(SpatialVector v1)`
Returns true if the elements of this spatial vector exactly equal those of vector `v1`.
Parameters:
`v1` - vector to compare with
Returns:
false if the vectors are not equal
• setZero

`public void setZero()`
Sets the elements of this spatial vector to zero.
• absolute

`public void absolute()`
Sets the elements of this spatial vector to their absolute values.
• cross

```public void cross(SpatialVector v1,
SpatialVector v2)```
• transform

`public void transform(RotationMatrix3d R)`
Applies a rotational transformation to this spatial vector, in place.
Parameters:
`R` - rotational transformation matrix
• inverseTransform

`public void inverseTransform(RotationMatrix3d R)`
Applies an inverse rotational transformation to this spatial vector, in place.
Parameters:
`R` - rotational transformation matrix
• transform

`public void transform(RigidTransform3d X)`
Applies a rigid spatial transformation to this spatial vector, in place.
Parameters:
`X` - rigid spatial transformation
• inverseTransform

`public void inverseTransform(RigidTransform3d X)`
Applies an inverse rigid spatial transformation to this vector, in place.
Parameters:
`X` - rigid spatial transformation
• toString

`public java.lang.String toString(NumberFormat fmt)`
Returns a String representation of this vector, in which each element is formatted using a C `printf` style format as decribed by the parameter `NumberFormat`.
Specified by:
`toString` in interface `Vector`
Overrides:
`toString` in class `VectorBase`
Parameters:
`fmt` - numeric format
Returns:
String representation of this vector
`VectorBase.isColumnVectorStringsVertical()`
• setRandom

`public void setRandom()`
Sets the elements of this vector to uniformly distributed random values in the range -0.5 (inclusive) to 0.5 (exclusive).
• setRandom

```public void setRandom(double lower,
double upper)```
Sets the elements of this vector to uniformly distributed random values in a specified range.
Parameters:
`lower` - lower random value (inclusive)
`upper` - upper random value (exclusive)
• setRandom

```public void setRandom(double lower,
double upper,
java.util.Random generator)```
Sets the elements of this vector to uniformly distributed random values in a specified range, using a supplied random number generator.
Parameters:
`lower` - lower random value (inclusive)
`upper` - upper random value (exclusive)
`generator` - random number generator
• clone

`public SpatialVector clone()`
Specified by:
`clone` in interface `Clonable`
Overrides:
`clone` in class `VectorBase`
• mul

```public void mul(Matrix6d M,
SpatialVector v1)```
Multiplies a spatial vector v1 by a Matrix6d and places the result in this spetial vector.
Parameters:
`M` - matrix to multiply by
`v1` - vector to multiply