maspack.matrix
Class Vector4d

java.lang.Object
  extended by maspack.matrix.VectorBase
      extended by maspack.matrix.Vector4d
All Implemented Interfaces:
java.lang.Cloneable, Vector, Clonable

public class Vector4d
extends VectorBase
implements Clonable

Implements a 4 element vector, along with its most commonly used operations.

The size of these vectors is fixed.


Field Summary
 double w
          Fourth element
static Vector4d W_UNIT
          Global unit vector along the w axis.
 double x
          First element
static Vector4d X_UNIT
          Global unit vector along the x axis.
 double y
          Second element
static Vector4d Y_UNIT
          Global unit vector along the y axis.
 double z
          Third element
static Vector4d Z_UNIT
          Global unit vector along the z axis.
static Vector4d ZERO
          Global zero vector.
 
Constructor Summary
Vector4d()
          Creates a 4-vector and initializes its elements to 0.
Vector4d(double x, double y, double z, double w)
          Creates a 4-vector with the supplied element values.
Vector4d(Vector4d v)
          Creates a 4-vector by copying an existing one.
 
Method Summary
 void absolute()
          Sets the elements of this vector to their absolute values.
 void absolute(Vector4d v1)
          Sets the elements of this vector to the absolute value of v1.
 void add(double dx, double dy, double dz, double dw)
          Adds specified increments to the components of this vector.
 void add(Vector4d v1)
          Adds this vector to v1 and places the result in this vector.
 void add(Vector4d v1, Vector4d v2)
          Adds vector v1 to v2 and places the result in this vector.
 double angle(Vector4d v1)
          Returns the angle between this vector and v1.
 Vector4d clone()
           
 void combine(double s1, Vector4d v1, double s2, Vector4d v2)
          Computes s1 v1 + s2 v2 and places the result in this vector.
 double distance(Vector4d v)
          Returns the Euclidean distance between this vector and vector v.
 double distanceSquared(Vector4d v)
          Returns the squared of the Euclidean distance between this vector and vector v.
 double dot(Vector4d v1)
          Returns the dot product of this vector and v1.
 boolean epsilonEquals(Vector4d v1, double eps)
          Returns true if the elements of this vector equal those of vector v1within a prescribed tolerance epsilon.
 boolean equals(Vector4d v1)
          Returns true if the elements of this vector exactly equal those of vector v1.
 void get(double[] values)
          Copies the elements of this vector into an array of doubles.
 double get(int i)
          Gets a single element of this vector.
 void get(Vector3d v)
          Gets the first three values of this vector.
 void get(VectorNd v1, int idx)
          Copies the values of this vector into a general length vector v1, starting at a specified index.
 double infinityNorm()
          Returns the infinity norm of this vector.
 void interpolate(double s, Vector4d v1)
          Computes the interpolation (1-s) this + s v1 and places the result in this vector.
 void interpolate(Vector4d v1, double s, Vector4d v2)
          Computes the interpolation (1-s) v1 + s v2 and places the result in this vector.
 void inverseTransform(RigidTransform3d X)
           
 void inverseTransform(RigidTransform3d X, Vector4d v1)
           
 void inverseTransform(RotationMatrix3d R)
           
 void inverseTransform(RotationMatrix3d R, Vector4d v1)
           
 double length()
          Returns the 2 norm of this vector.
 double lengthSquared()
          Returns the square of the 2 norm of this vector.
 void max(Vector4d v)
          Computes the element-wise maximum of this vector and vector v and places the result in this vector.
 int maxAbsIndex()
          Returns the index (0, 1, 2, or 3) of the element of v with the largest absolute value.
 double maxElement()
          Returns the maximum element value of this vector.
 void min(Vector4d v)
          Computes the element-wise minimum of this vector and vector v and places the result in this vector.
 int minAbsIndex()
          Returns the index (0, 1, 2, or 3) of the element of v with the smallest absolute value.
 double minElement()
          Returns the minimum element value of this vector.
 void mul(Matrix4dBase X, Vector4d v1)
          Multiplies matrix X by vector v1 and places the result in this vector.
 void negate()
          Negates this vector in place.
 void negate(Vector4d v1)
          Sets this vector to the negative of v1.
 void normalize()
          Normalizes this vector in place.
 void normalize(Vector4d v1)
          Computes a unit vector in the direction of v1 and places the result in this vector.
 double oneNorm()
          Returns the 1 norm of this vector.
 void scale(double s)
          Scales the elements of this vector by s.
 void scale(double s, Vector4d v1)
          Scales the elements of vector v1 by s and places the results in this vector.
 void scaledAdd(double s, Vector4d v1)
          Computes s v1 and adds the result to this vector.
 void scaledAdd(double s, Vector4d v1, Vector4d v2)
          Computes s v1 + v2 and places the result in this vector.
 void set(double[] values)
          Sets the elements of this vector from an array of doubles.
 void set(double x, double y, double z, double w)
          Sets the elements of this vector to the prescribed values.
 void set(int i, double value)
          Sets a single element of this vector.
 void set(Vector3d v, double w)
          Sets the elements of this vector to the prescribed values.
 void set(Vector4d v1)
          Sets the values of this vector to those of v1.
 void set(VectorNd v1, int idx)
          Sets the values of this vector from the elements of a general length vector v1, starting at a specified index.
 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 setToHomogeneous(Vector3d v1, double w)
          Sets the values of this vector to a homogeneous representation formed from a 3-vector and a weighting factor w.
 void setZero()
          Sets the elements of this vector to zero.
 int size()
          Returns the size of this vector (which is always 4)
 void sort()
          Sorts the contents of this vector by element value, with x being set to the largest value and w being set to the smallest value.
 void sort(Vector4d v1)
          Sorts the contents of vector v1 by element value, with x being set to the largest value and w being set to the smallest value, and places the results in this vector.
 void sortAbsolute()
          Sorts the contents of the vector by the absolute value of its components.
 void sub(Vector4d v1)
          Subtracts v1 from this vector and places the result in this vector.
 void sub(Vector4d v1, Vector4d v2)
          Subtracts vector v1 from v2 and places the result in this vector.
 void transform(AffineTransform3dBase X)
           
 void transform(AffineTransform3dBase X, Vector4d v1)
           
 void transform(RotationMatrix3d R)
           
 void transform(RotationMatrix3d R, Vector4d v1)
           
 void updateBounds(Vector4d vmin, Vector4d vmax)
          Updates a bounding box to include this vector.
 
Methods inherited from class maspack.matrix.VectorBase
containsNaN, copy, copyAndAdd, copyAndNegate, copyAndScale, copyAndSub, copyAndSubLeft, dot, epsilonEquals, equals, get, getDefaultFormat, hasNaN, isColumnVectorStringsVertical, isFixedSize, isRowVector, norm, normSquared, scan, set, set, setColumnVectorStringsVertical, setDefaultFormat, setRowVector, setSize, toString, toString, toString, write, write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO

public static final Vector4d ZERO
Global zero vector. Should not be modified.


X_UNIT

public static final Vector4d X_UNIT
Global unit vector along the x axis. Should not be modified.


Y_UNIT

public static final Vector4d Y_UNIT
Global unit vector along the y axis. Should not be modified.


Z_UNIT

public static final Vector4d Z_UNIT
Global unit vector along the z axis. Should not be modified.


W_UNIT

public static final Vector4d W_UNIT
Global unit vector along the w axis. Should not be modified.


x

public double x
First element


y

public double y
Second element


z

public double z
Third element


w

public double w
Fourth element

Constructor Detail

Vector4d

public Vector4d()
Creates a 4-vector and initializes its elements to 0.


Vector4d

public Vector4d(Vector4d v)
Creates a 4-vector by copying an existing one.

Parameters:
v - vector to be copied

Vector4d

public Vector4d(double x,
                double y,
                double z,
                double w)
Creates a 4-vector with the supplied element values.

Parameters:
x - first element
y - second element
z - third element
w - fourth element
Method Detail

size

public int size()
Returns the size of this vector (which is always 4)

Specified by:
size in interface Vector
Specified by:
size in class VectorBase
Returns:
4

get

public void get(Vector3d v)
Gets the first three values of this vector.

Parameters:
v - returns the first three values

get

public double get(int i)
Gets a single element of this vector. Elements 0, 1, 2, and 3 correspond to x, y, z, and w.

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 3.

get

public void get(double[] values)
Copies the elements of this vector into an array of doubles.

Specified by:
get in interface Vector
Overrides:
get in class VectorBase
Parameters:
values - array into which values are copied

get

public void get(VectorNd v1,
                int idx)
Copies the values of this vector into a general length vector v1, starting at a specified index.

Parameters:
v1 - vector into which values are to be copied
idx - starting index for copying values
Throws:
ArrayIndexOfOutBoundsException - if idx specifies a region within v1 that exceeds its bounds

set

public void set(int i,
                double value)
Sets a single element of this vector. Elements 0, 1, 2, and 3 correspond to x, y, z, and w.

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 3.

set

public void set(double[] values)
Sets the elements of this vector from an array of doubles.

Specified by:
set in interface Vector
Overrides:
set in class VectorBase
Parameters:
values - array from which values are copied

set

public void set(Vector4d v1)
Sets the values of this vector to those of v1.

Parameters:
v1 - vector whose values are copied

set

public void set(VectorNd v1,
                int idx)
Sets the values of this vector from the elements of a general length vector v1, starting at a specified index.

Parameters:
v1 - vector from which new values are copied
idx - starting index for new values
Throws:
ArrayIndexOfOutBoundsException - if idx specifies a region within v1 that exceeds its bounds

add

public void add(Vector4d v1,
                Vector4d v2)
Adds vector v1 to v2 and places the result in this vector.

Parameters:
v1 - left-hand vector
v2 - right-hand vector

add

public void add(Vector4d v1)
Adds this vector to v1 and places the result in this vector.

Parameters:
v1 - right-hand vector

add

public void add(double dx,
                double dy,
                double dz,
                double dw)
Adds specified increments to the components of this vector.

Parameters:
dx - x increment
dy - y increment
dz - z increment
dw - w increment

sub

public void sub(Vector4d v1,
                Vector4d v2)
Subtracts vector v1 from v2 and places the result in this vector.

Parameters:
v1 - left-hand vector
v2 - right-hand vector

sub

public void sub(Vector4d v1)
Subtracts v1 from this vector and places the result in this vector.

Parameters:
v1 - right-hand vector

negate

public void negate(Vector4d v1)
Sets this vector to the negative of v1.

Parameters:
v1 - vector to negate

negate

public void negate()
Negates this vector in place.


scale

public void scale(double s)
Scales the elements of this vector by s.

Parameters:
s - scaling factor

scale

public void scale(double s,
                  Vector4d v1)
Scales the elements of vector v1 by s and places the results in this vector.

Parameters:
s - scaling factor
v1 - vector to be scaled

interpolate

public void interpolate(Vector4d v1,
                        double s,
                        Vector4d v2)
Computes the interpolation (1-s) v1 + s v2 and places the result in this vector.

Parameters:
v1 - left-hand vector
s - interpolation factor
v2 - right-hand vector

interpolate

public void interpolate(double s,
                        Vector4d v1)
Computes the interpolation (1-s) this + s v1 and places the result in this vector.

Parameters:
s - interpolation factor
v1 - right-hand vector

scaledAdd

public void scaledAdd(double s,
                      Vector4d v1)
Computes s v1 and adds the result to this vector.

Parameters:
s - scaling factor
v1 - vector to be scaled and added

scaledAdd

public void scaledAdd(double s,
                      Vector4d v1,
                      Vector4d v2)
Computes s v1 + v2 and places the result in this vector.

Parameters:
s - scaling factor
v1 - vector to be scaled
v2 - vector to be added

combine

public void combine(double s1,
                    Vector4d v1,
                    double s2,
                    Vector4d v2)
Computes s1 v1 + s2 v2 and places the result in this vector.

Parameters:
s1 - left-hand scaling factor
v1 - left-hand vector
s2 - right-hand scaling factor
v2 - right-hand vector

length

public double length()
Returns the 2 norm of this vector. This is the square root of the sum of the squares of the elements.

Returns:
vector 2 norm

lengthSquared

public double lengthSquared()
Returns the square of the 2 norm of this vector. This is the sum of the squares of the elements.

Returns:
square of the 2 norm

distance

public double distance(Vector4d v)
Returns the Euclidean distance between this vector and vector v.

Returns:
distance between this vector and v

distanceSquared

public double distanceSquared(Vector4d v)
Returns the squared of the Euclidean distance between this vector and vector v.

Returns:
squared distance between this vector and v

maxElement

public double maxElement()
Returns the maximum element value of this 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 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 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 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(Vector4d v1)
Returns the dot product of this vector and v1.

Parameters:
v1 - right-hand vector
Returns:
dot product

angle

public double angle(Vector4d v1)
Returns the angle between this vector and v1. The angle is defined as acos(c), where c is the dot product of unit vectors parallel to this vector and v1.

Parameters:
v1 - right-hand vector
Returns:
angle between vectors, in radians

normalize

public void normalize()
Normalizes this vector in place.


normalize

public void normalize(Vector4d v1)
Computes a unit vector in the direction of v1 and places the result in this vector.

Parameters:
v1 - vector to normalize

epsilonEquals

public boolean epsilonEquals(Vector4d v1,
                             double eps)
Returns true if the elements of this vector equal those of vector v1within 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(Vector4d v1)
Returns true if the elements of this 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 vector to zero.


set

public void set(double x,
                double y,
                double z,
                double w)
Sets the elements of this vector to the prescribed values.

Parameters:
x - value for first element
y - value for second element
z - value for third element
w - value for fourth element

set

public void set(Vector3d v,
                double w)
Sets the elements of this vector to the prescribed values.

Parameters:
v - vector giving the first three element values
w - value for the fourth element

setToHomogeneous

public void setToHomogeneous(Vector3d v1,
                             double w)
Sets the values of this vector to a homogeneous representation formed from a 3-vector and a weighting factor w. The weighting factor scales the x, y, and z elements of v1 and sets the w field of this vector.

Parameters:
v1 - 3-vector
w - weighting factor

absolute

public void absolute()
Sets the elements of this vector to their absolute values.


absolute

public void absolute(Vector4d v1)
Sets the elements of this vector to the absolute value of v1.

Parameters:
v1 - vector to take the absolute value of

sortAbsolute

public void sortAbsolute()
Sorts the contents of the vector by the absolute value of its components.


maxAbsIndex

public int maxAbsIndex()
Returns the index (0, 1, 2, or 3) of the element of v with the largest absolute value.

Returns:
index

minAbsIndex

public int minAbsIndex()
Returns the index (0, 1, 2, or 3) of the element of v with the smallest absolute value.

Returns:
index

sort

public void sort(Vector4d v1)
Sorts the contents of vector v1 by element value, with x being set to the largest value and w being set to the smallest value, and places the results in this vector.

Parameters:
v1 - vector to sort

sort

public void sort()
Sorts the contents of this vector by element value, with x being set to the largest value and w being set to the smallest value.


mul

public void mul(Matrix4dBase X,
                Vector4d v1)
Multiplies matrix X by vector v1 and places the result in this vector.

Parameters:
X - matrix
v1 - vector

transform

public void transform(RotationMatrix3d R)

transform

public void transform(RotationMatrix3d R,
                      Vector4d v1)

inverseTransform

public void inverseTransform(RotationMatrix3d R)

inverseTransform

public void inverseTransform(RotationMatrix3d R,
                             Vector4d v1)

inverseTransform

public void inverseTransform(RigidTransform3d X)

inverseTransform

public void inverseTransform(RigidTransform3d X,
                             Vector4d v1)

transform

public void transform(AffineTransform3dBase X)

transform

public void transform(AffineTransform3dBase X,
                      Vector4d v1)

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

updateBounds

public void updateBounds(Vector4d vmin,
                         Vector4d vmax)
Updates a bounding box to include this vector. The box is described by minimum and maximum corner points, which are changed if necessary.

Parameters:
vmin - minimum corner of the bounding box
vmax - maximum corner of the bounding box

max

public void max(Vector4d v)
Computes the element-wise maximum of this vector and vector v and places the result in this vector.

Parameters:
v - vector to compare with

min

public void min(Vector4d v)
Computes the element-wise minimum of this vector and vector v and places the result in this vector.

Parameters:
v - vector to compare with

clone

public Vector4d clone()
Specified by:
clone in interface Clonable
Overrides:
clone in class VectorBase