|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmaspack.matrix.VectorBase
maspack.matrix.Vector2d
public class Vector2d
Implements a 2 element vector, along with its most commonly used operations.
The size of these vectors is fixed.
Field Summary | |
---|---|
double |
x
First element |
static Vector2d |
X_UNIT
Global unit vector along the x axis. |
double |
y
Second element |
static Vector2d |
Y_UNIT
Global unit vector along the y axis. |
static Vector2d |
ZERO
Global zero vector. |
Constructor Summary | |
---|---|
Vector2d()
Creates a 2-vector and initializes its elements to 0. |
|
Vector2d(double[] values)
Creates a 2-vector with the supplied element values. |
|
Vector2d(double x,
double y)
Creates a 2-vector with the supplied element values. |
|
Vector2d(Vector2d v)
Creates a 2-vector by copying an existing one. |
Method Summary | |
---|---|
void |
absolute()
Sets the elements of this vector to their absolute values. |
void |
absolute(Vector2d v1)
Sets the elements of this vector to the absolute value of v1. |
void |
add(double dx,
double dy)
Adds specified increments to the components of this vector. |
void |
add(Vector2d v1)
Adds this vector to v1 and places the result in this vector. |
void |
add(Vector2d v1,
Vector2d v2)
Adds vector v1 to v2 and places the result in this vector. |
double |
angle(Vector2d v1)
Returns the angle between this vector and v1. |
Vector2d |
clone()
|
void |
combine(double s1,
Vector2d v1,
double s2,
Vector2d v2)
Computes s1 v1 + s2 v2 and places the result in this
vector. |
double |
cross(Vector2d v2)
Computes the cross product of this vector and v1. |
double |
cross(Vector2d v1,
Vector2d v2)
Computes the cross product of v1 and v2. |
double |
distance(Vector2d v)
Returns the Euclidean distance between this vector and vector v. |
double |
distanceSquared(Vector2d v)
Returns the squared of the Euclidean distance between this vector and vector v. |
double |
dot(Vector2d v1)
Returns the dot product of this vector and v1. |
boolean |
epsilonEquals(Vector2d v1,
double eps)
Returns true if the elements of this vector equal those of vector v1 within a prescribed tolerance epsilon . |
boolean |
equals(Vector2d 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(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,
Vector2d v1)
Computes the interpolation (1-s) this + s v1 and places the
result in this vector. |
void |
interpolate(Vector2d v1,
double s,
Vector2d v2)
Computes the interpolation (1-s) v1 + s v2 and places the
result in this vector. |
void |
inverseTransform(AffineTransform2dBase X)
Applies an inverse affine transformation to this vector, in place. |
void |
inverseTransform(AffineTransform2dBase X,
Vector2d v1)
Applies an inverse affine transformation to the vector v1, and places the result in this vector. |
void |
inverseTransform(RotationMatrix2d R)
Applies an inverse rotational transformation to this vector, in place. |
void |
inverseTransform(RotationMatrix2d R,
Vector2d v1)
Applies an inverse rotational transformation to the vector v1, and stores the result in this vector. |
double |
length()
Returns the 2 norm of this vector. |
double |
lengthSquared()
Returns the square of the 2 norm of this vector. |
void |
max(Vector2d 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 or 1) of the element of v with the largest absolute value. |
double |
maxElement()
Returns the maximum element value of this vector. |
void |
min(Vector2d 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 or 1) of the element of v with the smallest absolute value. |
double |
minElement()
Returns the minimum element value of this vector. |
void |
negate()
Negates this vector in place. |
void |
negate(Vector2d v1)
Sets this vector to the negative of v1. |
void |
normalize()
Normalizes this vector in place. |
void |
normalize(Vector2d 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 |
perpendicular(Vector2d v1)
Sets this vector to one which is perpendicular to v1. |
void |
rotate(double cosine,
double sine,
Vector2d a)
|
void |
scale(double s)
Scales the elements of this vector by s . |
void |
scale(double s,
Vector2d v1)
Scales the elements of vector v1 by s and places the
results in this vector. |
void |
scaledAdd(double s,
Vector2d v1)
Computes s v1 and adds the result to this vector. |
void |
scaledAdd(double s,
Vector2d v1,
Vector2d 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)
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(Vector2d 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 |
setZero()
Sets the elements of this vector to zero. |
int |
size()
Returns the size of this vector (which is always 2) |
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(Vector2d v1)
Sorts the contents of vector v1 by element value, with x being set to the largest value and y 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 y being set to the smallest value. |
void |
sub(Vector2d v1)
Subtracts v1 from this vector and places the result in this vector. |
void |
sub(Vector2d v1,
Vector2d v2)
Subtracts vector v1 from v2 and places the result in this vector. |
void |
transform(AffineTransform2dBase X)
Applies a affine transformation to this vector, in place. |
void |
transform(AffineTransform2dBase X,
Vector2d v1)
Applies a affine transformation to the vector v1, and places the result in this vector. |
void |
transform(RotationMatrix2d R)
Applies a rotational transformation to this vector, in place. |
void |
transform(RotationMatrix2d R,
Vector2d v1)
Applies a rotational transformation to the vector v1 and stores the result in this vector. |
void |
updateBounds(Vector2d vmin,
Vector2d 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 |
---|
public static final Vector2d ZERO
public static final Vector2d X_UNIT
public static final Vector2d Y_UNIT
public double x
public double y
Constructor Detail |
---|
public Vector2d()
public Vector2d(Vector2d v)
v
- vector to be copiedpublic Vector2d(double x, double y)
x
- first elementy
- second elementpublic Vector2d(double[] values)
values
- element valuesMethod Detail |
---|
public 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 index
public void get(double[] values)
get
in interface Vector
get
in class VectorBase
values
- array into which values are copiedpublic void get(VectorNd v1, int idx)
v1
- vector into which values are to be copiedidx
- starting index for copying values
ArrayIndexOfOutBoundsException
- if idx specifies a region within v1 that exceeds its boundspublic void set(int i, double value)
set
in interface Vector
set
in class VectorBase
i
- element indexvalue
- element value
java.lang.ArrayIndexOutOfBoundsException
- if i is not in the range 0 to 1.public void set(double[] values)
set
in interface Vector
set
in class VectorBase
values
- array from which values are copiedpublic void set(Vector2d 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 values
ArrayIndexOfOutBoundsException
- if idx specifies a region within v1 that exceeds its boundspublic void add(Vector2d v1, Vector2d v2)
v1
- left-hand vectorv2
- right-hand vectorpublic void add(Vector2d v1)
v1
- right-hand vectorpublic void add(double dx, double dy)
dx
- x incrementdy
- y incrementpublic void sub(Vector2d v1, Vector2d v2)
v1
- left-hand vectorv2
- right-hand vectorpublic void sub(Vector2d v1)
v1
- right-hand vectorpublic void negate(Vector2d v1)
v1
- vector to negatepublic void negate()
public void scale(double s)
s
.
s
- scaling factorpublic void scale(double s, Vector2d v1)
s
and places the
results in this vector.
s
- scaling factorv1
- vector to be scaledpublic void rotate(double cosine, double sine, Vector2d a)
public void interpolate(Vector2d v1, double s, Vector2d 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, Vector2d v1)
(1-s) this + s v1
and places the
result in this vector.
s
- interpolation factorv1
- right-hand vectorpublic void scaledAdd(double s, Vector2d v1)
s v1
and adds the result to this vector.
s
- scaling factorv1
- vector to be scaled and addedpublic void scaledAdd(double s, Vector2d v1, Vector2d v2)
s v1 + v2
and places the result in this vector.
s
- scaling factorv1
- vector to be scaledv2
- vector to be addedpublic void combine(double s1, Vector2d v1, double s2, Vector2d 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 length()
public double lengthSquared()
public double distance(Vector2d v)
public double distanceSquared(Vector2d 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(Vector2d v1)
v1
- right-hand vector
public double angle(Vector2d v1)
acos(c)
, where c
is the dot product of unit
vectors parallel to this vector and v1.
v1
- right-hand vector
public void normalize()
public void normalize(Vector2d v1)
v1
- vector to normalizepublic void perpendicular(Vector2d v1)
v1
- perpendicular reference vectorpublic boolean epsilonEquals(Vector2d v1, double eps)
v1
within a prescribed tolerance epsilon
.
v1
- vector to compare witheps
- comparison tolerance
public boolean equals(Vector2d v1)
v1
.
v1
- vector to compare with
public void setZero()
public void set(double x, double y)
x
- value for first elementy
- value for second elementpublic void absolute()
public void absolute(Vector2d v1)
v1
- vector to take the absolute value ofpublic void sortAbsolute()
public int maxAbsIndex()
public int minAbsIndex()
public void sort(Vector2d v1)
v1
- vector to sortpublic void sort()
public double cross(Vector2d v1, Vector2d v2)
v1
- first vectorv2
- second vector
public double cross(Vector2d v2)
v2
- second vector
public void transform(RotationMatrix2d R)
R
- rotational transformation matrixpublic void transform(RotationMatrix2d R, Vector2d v1)
R
- rotational transformation matrixv1
- vector to transformpublic void inverseTransform(RotationMatrix2d R)
R
- rotational transformation matrixpublic void inverseTransform(RotationMatrix2d R, Vector2d v1)
R
- rotational transformation matrixv1
- vector to transformpublic void transform(AffineTransform2dBase X)
X
- affine transformationpublic void transform(AffineTransform2dBase X, Vector2d v1)
X
- affine transformationv1
- vector to be transformedpublic void inverseTransform(AffineTransform2dBase X)
X
- affine transformationpublic void inverseTransform(AffineTransform2dBase X, Vector2d v1)
X
- affine transformationv1
- vector to be transformedpublic 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(Vector2d vmin, Vector2d vmax)
vmin
- minimum corner of the bounding boxvmax
- maximum corner of the bounding boxpublic void max(Vector2d v)
v
- vector to compare withpublic void min(Vector2d v)
v
- vector to compare withpublic Vector2d clone()
clone
in interface Clonable
clone
in class VectorBase
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |