public class Vector3d extends VectorBase implements java.io.Serializable, Clonable, VectorObject<Vector3d>
The size of these vectors is fixed.
Modifier and Type | Field and Description |
---|---|
static Vector3d |
NEG_X_UNIT
Global unit vector along the negative x axis.
|
static Vector3d |
NEG_Y_UNIT
Global unit vector along the negative y axis.
|
static Vector3d |
NEG_Z_UNIT
Global unit vector along the negative z axis.
|
static Vector3d |
ONES
Global vector containing ones.
|
double |
x
First element
|
static Vector3d |
X_UNIT
Global unit vector along the x axis.
|
double |
y
Second element
|
static Vector3d |
Y_UNIT
Global unit vector along the y axis.
|
double |
z
Third element
|
static Vector3d |
Z_UNIT
Global unit vector along the z axis.
|
static Vector3d |
ZERO
Global zero vector.
|
Constructor and Description |
---|
Vector3d()
Creates a 3-vector and initializes its elements to 0.
|
Vector3d(double[] values)
Creates a 3-vector with the supplied element values.
|
Vector3d(double x,
double y,
double z)
Creates a 3-vector with the supplied element values.
|
Vector3d(Vector v)
Creates a 3-vector by copying an existing Vector.
|
Vector3d(Vector3d v)
Creates a 3-vector by copying an existing one.
|
Vector3d(Vector3i v)
Creates a 3-vector for an integer 3 vector.
|
Modifier and Type | Method and Description |
---|---|
Vector3d |
absolute()
Sets the elements of this vector to their absolute values.
|
Vector3d |
absolute(Vector3d v1)
Sets the elements of this vector to the absolute value of v1.
|
Vector3d |
add(double dx,
double dy,
double dz)
Adds specified increments to the components of this vector.
|
Vector3d |
add(Vector3d v1)
Adds this vector to v1 and places the result in this vector.
|
Vector3d |
add(Vector3d v1,
Vector3d v2)
Adds vector v1 to v2 and places the result in this vector.
|
void |
addObj(Vector3d v1)
Adds
v1 to this vector. |
double |
angle(Vector3d v1)
Returns the angle between this vector and v1.
|
void |
angleWeightedCross(Vector3d p0,
Vector3d p1,
Vector3d p2)
Computes the cross product v2 x v1, where v2 = p1 - p2 and v1 = p1 - p0,
and then sets the length of the result to the angle between v1 and
v2.
|
void |
angleWeightedCrossAdd(Vector3d p0,
Vector3d p1,
Vector3d p2)
Computes the cross product v2 x v1, where v2 = p1 - p2 and v1 = p1 - p0,
and then sets the length of the result to the angle between v1 and
v2.
|
Vector3d |
clone() |
Vector3d |
combine(double s1,
Vector3d v1,
double s2,
Vector3d v2)
Computes
s1 v1 + s2 v2 and places the result in this
vector. |
Vector3d |
cross(Vector3d v1)
Computes the cross product of this vector and v1, and places the result in
this vector.
|
Vector3d |
cross(Vector3d v1,
Vector3d v2)
Computes the cross product of v1 and v2 and places the result in this
vector.
|
Vector3d |
crossAdd(Vector3d v1,
Vector3d v2,
Vector3d v3)
Computes the cross product of v1 and v2, adds this to v3, and places the
result in this vector.
|
double |
distance(Vector3d v)
Returns the Euclidean distance between this vector and vector v.
|
double |
distanceSquared(Vector3d v)
Returns the squared of the Euclidean distance between this vector and
vector v.
|
double |
dot(Vector3d v1)
Returns the dot product of this vector and v1.
|
boolean |
epsilonEquals(Vector3d v1,
double eps)
Returns true if the elements of this vector equal those of vector
v1 within a prescribed tolerance epsilon . |
boolean |
equals(Vector3d 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.
|
float[] |
get(float[] values)
Copies the elements of this vector into an array of floats.
|
double |
get(int i)
Gets a single element of this vector.
|
void |
get(Matrix3x1 M)
Copies the elements of this vector into a Matrix3x1.
|
void |
get(VectorNd v1,
int idx)
Copies the values of this vector into a general length vector v1, starting
at a specified index.
|
boolean |
greater(Vector3d v1)
Returns true if all the elements of this vector are greater than those of
vector
v1 . |
boolean |
greaterEquals(Vector3d v1)
Returns true if all the elements of this vector are greater than or equal
to those of vector
v1 . |
static void |
hermiteInterpolate(Vector3d pr,
Vector3d p0,
Vector3d v0,
Vector3d p1,
Vector3d v1,
double s,
double h)
Interpolates the value at a location along a cubic Hermite spline.
|
static void |
hermiteVelocity(Vector3d vr,
Vector3d p0,
Vector3d v0,
Vector3d p1,
Vector3d v1,
double s,
double h)
Interpolates velocity at a location along a cubic Hermite spline.
|
double |
infinityNorm()
Returns the infinity norm of this vector.
|
void |
interpolate(double s,
Vector3d v1)
Computes the interpolation
(1-s) this + s v1 and places the
result in this vector. |
void |
interpolate(Vector3d v1,
double s,
Vector3d v2)
Computes the interpolation
(1-s) v1 + s v2 and places the
result in this vector. |
void |
inverseTransform(AffineTransform3dBase X)
Applies an inverse affine transformation to this vector, in place.
|
void |
inverseTransform(AffineTransform3dBase X,
Vector3d v1)
Applies an inverse affine transformation to the vector v1, and places the
result in this vector.
|
void |
inverseTransform(RotationMatrix3d R)
Applies an inverse rotational transformation to this vector, in place.
|
void |
inverseTransform(RotationMatrix3d R,
Vector3d v1)
Applies an inverse rotational transformation to the vector v1, and stores
the result in this vector.
|
static void |
main(java.lang.String[] args) |
Vector3d |
max(Vector3d 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, or 2) of the element of this vector with the
largest absolute value.
|
double |
maxElement()
Returns the maximum element value of this vector.
|
Vector3d |
min(Vector3d 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, or 2) of the element of this vector with the
smallest absolute value.
|
double |
minElement()
Returns the minimum element value of this vector.
|
Vector3d |
mul(Matrix3dBase X,
Vector3d v1)
Multiplies matrix X by vector v1 and places the result in this vector.
|
Vector3d |
mulAdd(Matrix3dBase X,
Vector3d v1,
Vector3d v2)
Multiplies matrix X by vector v1, adds vector v2, and places the result in
this vector.
|
Vector3d |
mulTranspose(Matrix3dBase X,
Vector3d v1)
Multiplies the transpose of matrix X by vector v1 and places the result in
this vector.
|
Vector3d |
mulTransposeAdd(Matrix3dBase X,
Vector3d v1,
Vector3d v2)
Multiplies the transpose of matrix X by vector v1, adds vector v2, and
places the result in this vector.
|
Vector3d |
negate()
Negates this vector in place.
|
Vector3d |
negate(Vector3d v1)
Sets this vector to the negative of v1.
|
double |
norm()
Returns the 2 norm of this vector.
|
Vector3d |
normalize()
Normalizes this vector in place.
|
Vector3d |
normalize(Vector3d v1)
Computes a unit vector in the direction of v1 and places the result in
this vector.
|
double |
normSquared()
Returns the square of the 2 norm of this vector.
|
double |
oneNorm()
Returns the 1 norm of this vector.
|
Vector3d |
perpendicular(Vector3d v1)
Sets this vector to one which is perpendicular to v1.
|
Vector3d |
scale(double s)
Scales the elements of this vector by
s . |
Vector3d |
scale(double sx,
double sy,
double sz)
Scales the elements of this vector by the values in the given direction.
|
Vector3d |
scale(double s,
Vector3d v1)
Scales the elements of vector v1 by
s and places the
results in this vector. |
Vector3d |
scaledAdd(double s,
Vector3d v1)
Computes
s v1 and adds the result to this vector. |
Vector3d |
scaledAdd(double s,
Vector3d v1,
Vector3d v2)
Computes
s v1 + v2 and places the result in this vector. |
void |
scaledAddObj(double s,
Vector3d v1)
Scales
v1 by s and adds it to this vector. |
void |
scaleObj(double s)
Scales this vector by
s . |
void |
scan(ReaderTokenizer rtok)
Sets the contents of this vector to values read from a ReaderTokenizer.
|
void |
set(double[] values)
Sets the elements of this vector from an array of doubles.
|
int |
set(double[] values,
int idx)
Sets the elements of this vector from an array of doubles,
starting from a particular location.
|
void |
set(double x,
double y,
double z)
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(Matrix3x1 M)
Sets the elements of this vector from a Matrix3x1.
|
void |
set(Vector3d v1)
Sets the values of this vector to those of v1.
|
void |
set(Vector3i 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 |
setFromHomogeneous(Vector4d v1)
Sets the values of this vector from a homogeneous representation stored in
the 4-vector v1.
|
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 vector to zero.
|
int |
size()
Returns the size of this vector (which is always 3)
|
void |
sort()
Sorts the contents of this vector by element value, with x being set to
the largest value and z being set to the smallest value.
|
void |
sort(Vector3d v1)
Sorts the contents of vector v1 by element value, with x being set to the
largest value and z being set to the smallest value, and places the
results in this vector.
|
void |
sortAbsolute()
Sorts the contents of this vector by absolute element value, with x being
set to the largest value and z being set to the smallest value.
|
Vector3d |
sub(Vector3d v1)
Subtracts v1 from this vector and places the result in this vector.
|
Vector3d |
sub(Vector3d v1,
Vector3d v2)
Subtracts vector v2 from v1 and places the result in this vector.
|
void |
transform(AffineTransform3dBase X)
Applies a affine transformation to this vector, in place.
|
void |
transform(AffineTransform3dBase X,
Vector3d v1)
Applies an affine transformation to the vector v1, and places the result
in this vector.
|
void |
transform(RotationMatrix3d R)
Applies a rotational transformation to this vector, in place.
|
void |
transform(RotationMatrix3d R,
Vector3d v1)
Applies a rotational transformation to the vector v1 and stores the result
in this vector.
|
double |
triangleArea(Vector3d v1,
Vector3d v2)
Returns the area of the triangle whose vertices are formed by this vector,
and the vectors v1 and v2.
|
void |
updateBounds(Vector3d vmin,
Vector3d vmax)
Updates a bounding box to include this vector.
|
void |
write(java.io.PrintWriter pw,
NumberFormat fmt,
boolean withBrackets)
Writes the contents of this vector to a PrintWriter.
|
containsNaN, copy, copyAndAdd, copyAndNegate, copyAndScale, copyAndSub, copyAndSubLeft, dot, epsilonEquals, equals, get, getDefaultFormat, hasInf, hasNaN, isColumnVectorStringsVertical, isFixedSize, isRowVector, isWritable, scan, set, set, setColumnVectorStringsVertical, setDefaultFormat, setRowVector, setSize, toString, toString, toString, write, write, writeToFile
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
getThreeVectorValue
isWritable, scan, write
public static final Vector3d ZERO
public static final Vector3d X_UNIT
public static final Vector3d Y_UNIT
public static final Vector3d Z_UNIT
public static final Vector3d NEG_X_UNIT
public static final Vector3d NEG_Y_UNIT
public static final Vector3d NEG_Z_UNIT
public static final Vector3d ONES
public double x
public double y
public double z
public Vector3d()
public Vector3d(Vector3d v)
v
- vector to be copiedpublic Vector3d(Vector3i v)
v
- vector to be copiedpublic Vector3d(Vector v)
v
- vector to be copiedpublic Vector3d(double x, double y, double z)
x
- first elementy
- second elementz
- third elementpublic Vector3d(double[] values)
values
- element valuespublic int size()
size
in interface Vector
size
in class VectorBase
public double get(int i)
get
in interface Vector
get
in class VectorBase
i
- element indexpublic void get(double[] values)
>=
the size of the vector.get
in interface Vector
get
in class VectorBase
values
- array into which values are copiedpublic float[] get(float[] values)
values
is null
, it is allocated internally.values
- array into which values are copied, or null
if array
should be allocatedpublic void get(VectorNd v1, int idx)
v1
- vector into which values are to be copiedidx
- starting index for copying valuesjava.lang.ArrayIndexOutOfBoundsException
- if idx specifies a region within v1 that exceeds its boundspublic void get(Matrix3x1 M)
M
- matrix into which values are copiedpublic void set(int i, double value)
set
in interface Vector
set
in class VectorBase
i
- element indexvalue
- element valuejava.lang.ArrayIndexOutOfBoundsException
- if i is not in the range 0 to 2.public void set(double[] values)
set
in interface Vector
set
in class VectorBase
values
- array from which values are copiedpublic int set(double[] values, int idx)
public void set(Vector3d v1)
set
in interface VectorObject<Vector3d>
v1
- vector whose values are copiedpublic void set(Vector3i v1)
v1
- vector whose values are copiedpublic void set(VectorNd v1, int idx)
v1
- vector from which new values are copiedidx
- starting index for new valuesjava.lang.ArrayIndexOutOfBoundsException
- if idx specifies a region within v1 that exceeds its boundspublic void set(Matrix3x1 M)
M
- matrix from which values are takenpublic void setFromHomogeneous(Vector4d v1)
v1
- homogenous vectorpublic Vector3d add(Vector3d v1, Vector3d v2)
v1
- left-hand vectorv2
- right-hand vectorpublic Vector3d add(Vector3d v1)
v1
- right-hand vectorpublic Vector3d add(double dx, double dy, double dz)
dx
- x incrementdy
- y incrementdz
- z incrementpublic Vector3d sub(Vector3d v1, Vector3d v2)
v1
- left-hand vectorv2
- right-hand vectorpublic Vector3d sub(Vector3d v1)
v1
- right-hand vectorpublic Vector3d negate(Vector3d v1)
v1
- vector to negatepublic Vector3d negate()
public Vector3d scale(double s)
s
.s
- scaling factorpublic Vector3d scale(double sx, double sy, double sz)
sx
- scaling factor in the x directionsy
- scaling factor in the y directionsz
- scaling factor in the z directionpublic Vector3d scale(double s, Vector3d v1)
s
and places the
results in this vector.s
- scaling factorv1
- vector to be scaledpublic void interpolate(Vector3d v1, double s, Vector3d v2)
(1-s) v1 + s v2
and places the
result in this vector.v1
- left-hand vectors
- interpolation factorv2
- right-hand vectorpublic void interpolate(double s, Vector3d v1)
(1-s) this + s v1
and places the
result in this vector.s
- interpolation factorv1
- right-hand vectorpublic Vector3d scaledAdd(double s, Vector3d v1, Vector3d v2)
s v1 + v2
and places the result in this vector.s
- scaling factorv1
- vector to be scaledv2
- vector to be addedpublic Vector3d scaledAdd(double s, Vector3d v1)
s v1
and adds the result to this vector.s
- scaling factorv1
- vector to be scaled and addedpublic Vector3d combine(double s1, Vector3d v1, double s2, Vector3d v2)
s1 v1 + s2 v2
and places the result in this
vector.s1
- left-hand scaling factorv1
- left-hand vectors2
- right-hand scaling factorv2
- right-hand vectorpublic double norm()
norm
in interface Vector
norm
in class VectorBase
public double normSquared()
normSquared
in interface Vector
normSquared
in class VectorBase
public double distance(Vector3d v)
public double distanceSquared(Vector3d v)
public double maxElement()
maxElement
in interface Vector
maxElement
in class VectorBase
public double minElement()
minElement
in interface Vector
minElement
in class VectorBase
public double infinityNorm()
infinityNorm
in interface Vector
infinityNorm
in class VectorBase
public double oneNorm()
oneNorm
in interface Vector
oneNorm
in class VectorBase
public double dot(Vector3d v1)
v1
- right-hand vectorpublic double angle(Vector3d v1)
acos(c)
, where c
is the dot product of unit
vectors parallel to this vector and v1.v1
- right-hand vectorpublic Vector3d normalize()
public Vector3d normalize(Vector3d v1)
v1
- vector to normalizepublic Vector3d perpendicular(Vector3d v1)
v1
- perpendicular reference vectorpublic boolean epsilonEquals(Vector3d v1, double eps)
v1
within a prescribed tolerance epsilon
.epsilonEquals
in interface VectorObject<Vector3d>
v1
- vector to compare witheps
- comparison tolerancepublic boolean equals(Vector3d v1)
v1
.v1
- vector to compare withpublic boolean greater(Vector3d v1)
v1
.v1
- vector to compare withpublic boolean greaterEquals(Vector3d v1)
v1
.v1
- vector to compare withpublic void setZero()
setZero
in interface VectorObject<Vector3d>
public void set(double x, double y, double z)
x
- value for first elementy
- value for second elementz
- value for third elementpublic Vector3d absolute()
public Vector3d absolute(Vector3d v1)
v1
- vector to take the absolute value ofpublic void sortAbsolute()
public int maxAbsIndex()
public int minAbsIndex()
public void sort(Vector3d v1)
v1
- vector to sortpublic void sort()
public Vector3d cross(Vector3d v1, Vector3d v2)
v1
- left-hand vectorv2
- right-hand vectorpublic Vector3d cross(Vector3d v1)
v1
- right-hand vectorpublic Vector3d crossAdd(Vector3d v1, Vector3d v2, Vector3d v3)
v1
- left-hand vector for cross productv2
- right-hand vector for cross productv3
- vector to addpublic void angleWeightedCross(Vector3d p0, Vector3d p1, Vector3d p2)
p0
- tail point for vector v1p1
- head point for vectors v1 and v2p2
- tail point for vector v2public void angleWeightedCrossAdd(Vector3d p0, Vector3d p1, Vector3d p2)
p0
- tail point for vector v1p1
- head point for vectors v1 and v2p2
- tail point for vector v2public double triangleArea(Vector3d v1, Vector3d v2)
v1
- second vertexv2
- third vertexpublic void transform(RotationMatrix3d R)
R
- rotational transformation matrixpublic void transform(RotationMatrix3d R, Vector3d v1)
R
- rotational transformation matrixv1
- vector to transformpublic void inverseTransform(RotationMatrix3d R)
R
- rotational transformation matrixpublic void inverseTransform(RotationMatrix3d R, Vector3d v1)
R
- rotational transformation matrixv1
- vector to transformpublic void transform(AffineTransform3dBase X)
X
- affine transformationpublic void transform(AffineTransform3dBase X, Vector3d v1)
X
- affine transformationv1
- vector to be transformedpublic void inverseTransform(AffineTransform3dBase X)
X
- affine transformationpublic void inverseTransform(AffineTransform3dBase X, Vector3d v1)
X
- affine transformationv1
- vector to be transformedpublic Vector3d mul(Matrix3dBase X, Vector3d v1)
X
- matrixv1
- vectorpublic Vector3d mulAdd(Matrix3dBase X, Vector3d v1, Vector3d v2)
X
- matrixv1
- vector to multiplyv2
- vector to addpublic Vector3d mulTranspose(Matrix3dBase X, Vector3d v1)
X
- matrixv1
- vector to multiplypublic Vector3d mulTransposeAdd(Matrix3dBase X, Vector3d v1, Vector3d v2)
X
- matrixv1
- vector to multiplyv2
- vector to addpublic void setRandom()
public void setRandom(double lower, double upper)
lower
- lower random value (inclusive)upper
- upper random value (exclusive)public void setRandom(double lower, double upper, java.util.Random generator)
lower
- lower random value (inclusive)upper
- upper random value (exclusive)generator
- random number generatorpublic void updateBounds(Vector3d vmin, Vector3d vmax)
vmin
- minimum corner of the bounding boxvmax
- maximum corner of the bounding boxpublic Vector3d max(Vector3d v)
v
- vector to compare withpublic Vector3d min(Vector3d v)
v
- vector to compare withpublic static void hermiteInterpolate(Vector3d pr, Vector3d p0, Vector3d v0, Vector3d p1, Vector3d v1, double s, double h)
s
in the range [0,1], and the actual time duration of the interval
is given by h
.pr
- returns interpolated positionp0
- position at the interval beginningv0
- velocity at the interval beginningp1
- position at the interval endv1
- velocity at the interval ends
- interpolation location on the interval (in the range [0,1])h
- interval time durationpublic static void hermiteVelocity(Vector3d vr, Vector3d p0, Vector3d v0, Vector3d p1, Vector3d v1, double s, double h)
s
in the range [0,1], and the actual time duration of the interval
is given by h
.vr
- returns interpolated velocityp0
- position at the interval beginningv0
- velocity at the interval beginningp1
- position at the interval endv1
- velocity at the interval ends
- interpolation location on the interval (in the range [0,1])h
- interval time durationpublic Vector3d clone()
clone
in interface Clonable
clone
in class VectorBase
public void write(java.io.PrintWriter pw, NumberFormat fmt, boolean withBrackets) throws java.io.IOException
[ ]
if withBrackets
is set true. Each
element is formatted using a C printf
style as decribed by
the parameter NumberFormat
.write
in interface Vector
write
in class VectorBase
pw
- PrintWriter to write this vector tofmt
- numeric formatwithBrackets
- if true, causes the output to be surrounded by square brackets.java.io.IOException
public void scan(ReaderTokenizer rtok) throws java.io.IOException
[ ]
.
If the input is not surrounded by square brackets, then the number of
values should equal the current size
of this vector.
If the input is surrounded by square brackets, then all values up to the
closing bracket are read, and the resulting number of values should either
equal the current size
of this vector, or this vector should
be resizeable to fit the input. For example,
[ 1.2 4 5 3.1 ]defines a vector of size 4.
scan
in interface Vector
scan
in class VectorBase
rtok
- Tokenizer from which vector values are read. Number parsing should be
enabled.java.io.IOException
public static void main(java.lang.String[] args)
public void scaleObj(double s)
s
.scaleObj
in interface VectorObject<Vector3d>
public void addObj(Vector3d v1)
v1
to this vector.addObj
in interface VectorObject<Vector3d>
public void scaledAddObj(double s, Vector3d v1)
v1
by s
and adds it to this vector.scaledAddObj
in interface VectorObject<Vector3d>