public class Vector3i extends VectoriBase
The size of these vectors is fixed.
Modifier and Type | Field and Description |
---|---|
int |
x
First element
|
int |
y
Second element
|
int |
z
Third element
|
static Vector3i |
ZERO
Global zero vector.
|
Constructor and Description |
---|
Vector3i()
Creates a 3-vector and initializes its elements to 0.
|
Vector3i(int[] values)
Creates a 3-vector with the supplied element values.
|
Vector3i(int x,
int y,
int z)
Creates a 3-vector with the supplied element values.
|
Vector3i(Vector3i v)
Creates a 3-vector by copying an existing one.
|
Vector3i(Vectori v)
Creates a 3-vector by copying an existing Vectori.
|
Modifier and Type | Method and Description |
---|---|
Vector3i |
absolute()
Sets the elements of this vector to their absolute values.
|
Vector3i |
absolute(Vector3i v1)
Sets the elements of this vector to the absolute value of v1.
|
Vector3i |
add(Vector3i v1)
Adds this vector to v1 and places the result in this vector.
|
Vector3i |
add(Vector3i v1,
Vector3i v2)
Adds vector v1 to v2 and places the result in this vector.
|
Vector3i |
clone() |
boolean |
equals(Vector3i 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.
|
Vector3i |
max(Vector3i 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.
|
Vector3i |
min(Vector3i 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.
|
Vector3i |
negate()
Negates this vector in place.
|
Vector3i |
negate(Vector3i 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.
|
Vector3i |
scale(double s)
Scales the elements of this vector by
s . |
Vector3i |
scale(double s,
Vector3i v1)
Scales the elements of vector v1 by
s and places the
results in this vector. |
Vector3i |
scaledAdd(double s,
Vector3i v1)
Computes
s v1 and adds the result to this vector. |
Vector3i |
scaledAdd(double s,
Vector3i v1,
Vector3i 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(Vector3d v1)
Sets the values of this vector to those of v1, converting to integer
using regular cast conversion.
|
void |
set(Vector3i 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 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(Vector3i 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.
|
Vector3i |
sub(Vector3i v1)
Subtracts v1 from this vector and places the result in this vector.
|
Vector3i |
sub(Vector3i v1,
Vector3i v2)
Subtracts vector v2 from v1 and places the result in this vector.
|
void |
updateBounds(Vector3i vmin,
Vector3i 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.
|
equals, getDefaultFormat, isFixedSize, set, setDefaultFormat, setSize, toString, toString, toString, write
public static final Vector3i ZERO
public int x
public int y
public int z
public Vector3i()
public Vector3i(Vector3i v)
v
- vector to be copiedpublic Vector3i(Vectori v)
v
- vector to be copiedpublic Vector3i(int x, int y, int z)
x
- first elementy
- second elementz
- third elementpublic Vector3i(int[] values)
values
- element valuespublic int size()
size
in interface Vectori
size
in class VectoriBase
public int get(int i)
get
in interface Vectori
get
in class VectoriBase
i
- element indexpublic void get(int[] values)
>=
the size of the vector.get
in interface Vectori
get
in class VectoriBase
values
- array into which values are copiedpublic void set(int i, int value)
set
in interface Vectori
set
in class VectoriBase
i
- element indexvalue
- element valuejava.lang.ArrayIndexOutOfBoundsException
- if i is not in the range 0 to 2.public void set(int[] values)
set
in interface Vectori
set
in class VectoriBase
values
- array from which values are copiedpublic void set(Vector3i v1)
v1
- vector whose values are copiedpublic void set(Vector3d v1)
v1
- vector whose values are copied and roundedpublic Vector3i add(Vector3i v1, Vector3i v2)
v1
- left-hand vectorv2
- right-hand vectorpublic Vector3i add(Vector3i v1)
v1
- right-hand vectorpublic Vector3i sub(Vector3i v1, Vector3i v2)
v1
- left-hand vectorv2
- right-hand vectorpublic Vector3i sub(Vector3i v1)
v1
- right-hand vectorpublic Vector3i negate(Vector3i v1)
v1
- vector to negatepublic Vector3i negate()
public Vector3i scale(double s)
s
.s
- scaling factorpublic Vector3i scale(double s, Vector3i v1)
s
and places the
results in this vector.s
- scaling factorv1
- vector to be scaledpublic Vector3i scaledAdd(double s, Vector3i v1, Vector3i v2)
s v1 + v2
and places the result in this vector.s
- scaling factorv1
- vector to be scaledv2
- vector to be addedpublic Vector3i scaledAdd(double s, Vector3i v1)
s v1
and adds the result to this vector.s
- scaling factorv1
- vector to be scaled and addedpublic double norm()
norm
in interface Vectori
norm
in class VectoriBase
public double normSquared()
normSquared
in interface Vectori
normSquared
in class VectoriBase
public int maxElement()
maxElement
in interface Vectori
maxElement
in class VectoriBase
public int minElement()
minElement
in interface Vectori
minElement
in class VectoriBase
public int infinityNorm()
infinityNorm
in interface Vectori
infinityNorm
in class VectoriBase
public int oneNorm()
oneNorm
in interface Vectori
oneNorm
in class VectoriBase
public boolean equals(Vector3i 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 Vector3i absolute()
public Vector3i absolute(Vector3i v1)
v1
- vector to take the absolute value ofpublic void sortAbsolute()
public int maxAbsIndex()
public int minAbsIndex()
public void sort(Vector3i 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 void updateBounds(Vector3i vmin, Vector3i vmax)
vmin
- minimum corner of the bounding boxvmax
- maximum corner of the bounding boxpublic Vector3i max(Vector3i v)
v
- vector to compare withpublic Vector3i min(Vector3i v)
v
- vector to compare withpublic Vector3i clone()
clone
in interface Clonable
clone
in class VectoriBase
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 (for integers) as decribed
by the parameter NumberFormat
.write
in interface Vectori
write
in class VectoriBase
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 4 5 3 ]defines a vector of size 4.
scan
in interface Vectori
scan
in class VectoriBase
rtok
- Tokenizer from which vector values are read. Number parsing should be
enabled.java.io.IOException