public class Vector2i extends VectoriBase
The size of these vectors is fixed.
| Modifier and Type | Field and Description |
|---|---|
int |
x
First element
|
int |
y
Second element
|
static Vector2i |
ZERO
Global zero vector.
|
| Constructor and Description |
|---|
Vector2i()
Creates a 2-vector and initializes its elements to 0.
|
Vector2i(int[] values)
Creates a 2-vector with the supplied element values.
|
Vector2i(int x,
int y)
Creates a 2-vector with the supplied element values.
|
Vector2i(Vector2i v)
Creates a 2-vector by copying an existing one.
|
Vector2i(Vectori v)
Creates a 2-vector by copying an existing Vectori.
|
| Modifier and Type | Method and Description |
|---|---|
Vector2i |
absolute()
Sets the elements of this vector to their absolute values.
|
Vector2i |
absolute(Vector2i v1)
Sets the elements of this vector to the absolute value of v1.
|
Vector2i |
add(Vector2i v1)
Adds this vector to v1 and places the result in this vector.
|
Vector2i |
add(Vector2i v1,
Vector2i v2)
Adds vector v1 to v2 and places the result in this vector.
|
Vector2i |
clone() |
boolean |
equals(Vector2i v1)
Returns true if the elements of this vector exactly equal those of vector
v1. |
int |
get(int i)
Gets a single element of this vector.
|
void |
get(int[] values)
Copies the elements of this vector into an array of doubles.
|
int |
infinityNorm()
Returns the infinity norm of this vector.
|
Vector2i |
max(Vector2i 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.
|
int |
maxElement()
Returns the maximum element value.
|
Vector2i |
min(Vector2i 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.
|
int |
minElement()
Returns the minimum element value.
|
Vector2i |
negate()
Negates this vector in place.
|
Vector2i |
negate(Vector2i v1)
Sets this vector to the negative of v1.
|
double |
norm()
Returns the 2 norm of this vector.
|
double |
normSquared()
Returns the square of the 2 norm of this vector.
|
int |
oneNorm()
Returns the 1 norm of this vector.
|
Vector2i |
scale(double s)
Scales the elements of this vector by
s. |
Vector2i |
scale(double s,
Vector2i v1)
Scales the elements of vector v1 by
s and places the
results in this vector. |
Vector2i |
scaledAdd(double s,
Vector2i v1)
Computes
s v1 and adds the result to this vector. |
Vector2i |
scaledAdd(double s,
Vector2i v1,
Vector2i v2)
Computes
s v1 + v2 and places the result in this vector. |
void |
scan(ReaderTokenizer rtok)
Sets the contents of this vector to values read from a ReaderTokenizer.
|
void |
set(int[] values)
Sets the elements of this vector from an array of ints.
|
void |
set(int i,
int value)
Sets a single element of this vector.
|
void |
set(int x,
int y,
int z)
Sets the elements of this vector to the prescribed values.
|
void |
set(Vector2i v1)
Sets the values of this vector to those of v1.
|
void |
setRandom()
Sets the elements of this vector to uniformly distributed random values in
the range -1000 (inclusive) to 1000 (exclusive).
|
void |
setRandom(int lower,
int upper)
Sets the elements of this vector to uniformly distributed random values in
a specified range.
|
void |
setRandom(int lower,
int 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(Vector2i 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.
|
Vector2i |
sub(Vector2i v1)
Subtracts v1 from this vector and places the result in this vector.
|
Vector2i |
sub(Vector2i v1,
Vector2i v2)
Subtracts vector v2 from v1 and places the result in this vector.
|
void |
write(java.io.PrintWriter pw,
NumberFormat fmt,
boolean withBrackets)
Writes the contents of this vector to a PrintWriter.
|
equals, getDefaultFormat, isFixedSize, set, setDefaultFormat, setSize, toString, toString, toString, writepublic static final Vector2i ZERO
public int x
public int y
public Vector2i()
public Vector2i(Vector2i v)
v - vector to be copiedpublic Vector2i(Vectori v)
v - vector to be copiedpublic Vector2i(int x,
int y)
x - first elementy - second elementpublic Vector2i(int[] values)
values - element valuespublic int size()
size in interface Vectorisize in class VectoriBasepublic int get(int i)
get in interface Vectoriget in class VectoriBasei - element indexpublic void get(int[] values)
>= the size of the vector.get in interface Vectoriget in class VectoriBasevalues - array into which values are copiedpublic void set(int i,
int value)
set in interface Vectoriset in class VectoriBasei - element indexvalue - element valuejava.lang.ArrayIndexOutOfBoundsException - if i is not in the range 0 to 1.public void set(int[] values)
set in interface Vectoriset in class VectoriBasevalues - array from which values are copiedpublic void set(Vector2i v1)
v1 - vector whose values are copiedpublic Vector2i add(Vector2i v1, Vector2i v2)
v1 - left-hand vectorv2 - right-hand vectorpublic Vector2i add(Vector2i v1)
v1 - right-hand vectorpublic Vector2i sub(Vector2i v1, Vector2i v2)
v1 - left-hand vectorv2 - right-hand vectorpublic Vector2i sub(Vector2i v1)
v1 - right-hand vectorpublic Vector2i negate(Vector2i v1)
v1 - vector to negatepublic Vector2i negate()
public Vector2i scale(double s)
s.s - scaling factorpublic Vector2i scale(double s, Vector2i v1)
s and places the
results in this vector.s - scaling factorv1 - vector to be scaledpublic Vector2i scaledAdd(double s, Vector2i v1, Vector2i v2)
s v1 + v2 and places the result in this vector.s - scaling factorv1 - vector to be scaledv2 - vector to be addedpublic Vector2i scaledAdd(double s, Vector2i v1)
s v1 and adds the result to this vector.s - scaling factorv1 - vector to be scaled and addedpublic double norm()
norm in interface Vectorinorm in class VectoriBasepublic double normSquared()
normSquared in interface VectorinormSquared in class VectoriBasepublic int maxElement()
maxElement in interface VectorimaxElement in class VectoriBasepublic int minElement()
minElement in interface VectoriminElement in class VectoriBasepublic int infinityNorm()
infinityNorm in interface VectoriinfinityNorm in class VectoriBasepublic int oneNorm()
oneNorm in interface VectorioneNorm in class VectoriBasepublic boolean equals(Vector2i v1)
v1.v1 - vector to compare withpublic void setZero()
public void set(int x,
int y,
int z)
x - value for first elementy - value for second elementz - value for third elementpublic Vector2i absolute()
public Vector2i absolute(Vector2i v1)
v1 - vector to take the absolute value ofpublic void sortAbsolute()
public int maxAbsIndex()
public int minAbsIndex()
public void sort(Vector2i v1)
v1 - vector to sortpublic void sort()
public void setRandom()
public void setRandom(int lower,
int upper)
lower - lower random value (inclusive)upper - upper random value (exclusive)public void setRandom(int lower,
int upper,
java.util.Random generator)
lower - lower random value (inclusive)upper - upper random value (exclusive)generator - random number generatorpublic Vector2i max(Vector2i v)
v - vector to compare withpublic Vector2i min(Vector2i v)
v - vector to compare withpublic Vector2i clone()
clone in interface Clonableclone in class VectoriBasepublic 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 (for integers) as decribed
by the parameter NumberFormat.write in interface Vectoriwrite in class VectoriBasepw - PrintWriter to write this vector tofmt - numeric formatwithBrackets - if true, causes the output to be surrounded by square brackets.java.io.IOExceptionpublic 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 4 5 3 ]defines a vector of size 4.
scan in interface Vectoriscan in class VectoriBasertok - Tokenizer from which vector values are read. Number parsing should be
enabled.java.io.IOException