maspack.matrix

## Class Vector3i

• All Implemented Interfaces:
java.lang.Cloneable, Vectori, Clonable

public class Vector3i
extends VectoriBase
Implements a 3 element integer vector, along its most commonly used operations.

The size of these vectors is fixed.

• ### Field Summary

Fields
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 Summary

Constructors
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.
• ### Method Summary

All Methods
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.
Adds this vector to v1 and places the result in this vector.
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.
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.
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.
• ### Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
• ### Field Detail

• #### ZERO

public static final Vector3i ZERO
Global zero vector. Should not be modified.
• #### x

public int x
First element
• #### y

public int y
Second element
• #### z

public int z
Third element
• ### Constructor Detail

• #### Vector3i

public Vector3i()
Creates a 3-vector and initializes its elements to 0.
• #### Vector3i

public Vector3i(Vector3i v)
Creates a 3-vector by copying an existing one.
Parameters:
v - vector to be copied
• #### Vector3i

public Vector3i(Vectori v)
Creates a 3-vector by copying an existing Vectori. The size of the copied vector must be at least 3.
Parameters:
v - vector to be copied
• #### Vector3i

public Vector3i(int x,
int y,
int z)
Creates a 3-vector with the supplied element values.
Parameters:
x - first element
y - second element
z - third element
• #### Vector3i

public Vector3i(int[] values)
Creates a 3-vector with the supplied element values.
Parameters:
values - element values
• ### Method Detail

• #### size

public int size()
Returns the size of this vector (which is always 3)
Specified by:
size in interface Vectori
Specified by:
size in class VectoriBase
Returns:
3
• #### get

public int get(int i)
Gets a single element of this vector. Elements 0, 1, and 2 correspond to x, y, and z.
Specified by:
get in interface Vectori
Specified by:
get in class VectoriBase
Parameters:
i - element index
Returns:
element value throws ArrayIndexOutOfBoundsException if i is not in the range 0 to 2.
• #### get

public void get(int[] values)
Copies the elements of this vector into an array of doubles. The array length must be >= the size of the vector.
Specified by:
get in interface Vectori
Overrides:
get in class VectoriBase
Parameters:
values - array into which values are copied
• #### set

public void set(int i,
int value)
Sets a single element of this vector. Elements 0, 1, and 2 correspond to x, y, and z.
Specified by:
set in interface Vectori
Specified by:
set in class VectoriBase
Parameters:
i - element index
value - element value
Throws:
java.lang.ArrayIndexOutOfBoundsException - if i is not in the range 0 to 2.
• #### set

public void set(int[] values)
Sets the elements of this vector from an array of ints. The array must have a length of at least 3.
Specified by:
set in interface Vectori
Overrides:
set in class VectoriBase
Parameters:
values - array from which values are copied
• #### set

public void set(Vector3i v1)
Sets the values of this vector to those of v1.
Parameters:
v1 - vector whose values are copied
• #### set

public void set(Vector3d v1)
Sets the values of this vector to those of v1, converting to integer using regular cast conversion. May result in a loss of precision.
Parameters:
v1 - vector whose values are copied and rounded

Vector3i v2)
Adds vector v1 to v2 and places the result in this vector.
Parameters:
v1 - left-hand vector
v2 - right-hand vector
Returns:
this vector

Adds this vector to v1 and places the result in this vector.
Parameters:
v1 - right-hand vector
Returns:
this vector
• #### sub

public Vector3i sub(Vector3i v1,
Vector3i v2)
Subtracts vector v2 from v1 and places the result in this vector.
Parameters:
v1 - left-hand vector
v2 - right-hand vector
Returns:
this vector
• #### sub

public Vector3i sub(Vector3i v1)
Subtracts v1 from this vector and places the result in this vector.
Parameters:
v1 - right-hand vector
Returns:
this vector
• #### negate

public Vector3i negate(Vector3i v1)
Sets this vector to the negative of v1.
Parameters:
v1 - vector to negate
Returns:
this vector
• #### negate

public Vector3i negate()
Negates this vector in place.
Returns:
this vector
• #### scale

public Vector3i scale(double s)
Scales the elements of this vector by s.
Parameters:
s - scaling factor
Returns:
this vector
• #### scale

public Vector3i scale(double s,
Vector3i 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
Returns:
this vector

Vector3i v1,
Vector3i 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
Returns:
this vector

Vector3i v1)
Computes s v1 and adds the result to this vector.
Parameters:
s - scaling factor
v1 - vector to be scaled and added
Returns:
this vector
• #### norm

public double norm()
Returns the 2 norm of this vector. This is the square root of the sum of the squares of the elements.
Specified by:
norm in interface Vectori
Overrides:
norm in class VectoriBase
Returns:
vector 2 norm
• #### normSquared

public double normSquared()
Returns the square of the 2 norm of this vector. This is the sum of the squares of the elements.
Specified by:
normSquared in interface Vectori
Overrides:
normSquared in class VectoriBase
Returns:
square of the 2 norm
• #### maxElement

public int maxElement()
Returns the maximum element value.
Specified by:
maxElement in interface Vectori
Overrides:
maxElement in class VectoriBase
Returns:
maximal element
• #### minElement

public int minElement()
Returns the minimum element value.
Specified by:
minElement in interface Vectori
Overrides:
minElement in class VectoriBase
Returns:
minimal element
• #### infinityNorm

public int infinityNorm()
Returns the infinity norm of this vector. This is the maximum absolute value over all elements.
Specified by:
infinityNorm in interface Vectori
Overrides:
infinityNorm in class VectoriBase
Returns:
vector infinity norm
• #### oneNorm

public int oneNorm()
Returns the 1 norm of this vector. This is the sum of the absolute values of the elements.
Specified by:
oneNorm in interface Vectori
Overrides:
oneNorm in class VectoriBase
Returns:
vector 1 norm
• #### equals

public boolean equals(Vector3i 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(int x,
int y,
int z)
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
• #### absolute

public Vector3i absolute()
Sets the elements of this vector to their absolute values.
Returns:
this vector
• #### absolute

public Vector3i absolute(Vector3i v1)
Sets the elements of this vector to the absolute value of v1.
Parameters:
v1 - vector to take the absolute value of
Returns:
this vector
• #### sortAbsolute

public 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.
• #### maxAbsIndex

public int maxAbsIndex()
Returns the index (0, 1, or 2) of the element of this vector with the largest absolute value.
Returns:
index of largest absolute value
• #### minAbsIndex

public int minAbsIndex()
Returns the index (0, 1, or 2) of the element of this vector with the smallest absolute value.
Returns:
index of smallest absolute value
• #### sort

public 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.
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 z being set to the smallest value.
• #### setRandom

public void setRandom()
Sets the elements of this vector to uniformly distributed random values in the range -1000 (inclusive) to 1000 (exclusive).
• #### setRandom

public void setRandom(int lower,
int 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(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.
Parameters:
lower - lower random value (inclusive)
upper - upper random value (exclusive)
generator - random number generator
• #### updateBounds

public void updateBounds(Vector3i vmin,
Vector3i vmax)
Updates a bounding box to include this vector. The box is described by minimum and maximum corner points, which are changed if necessary. This method will only grow bounds, not shrink them.
Parameters:
vmin - minimum corner of the bounding box
vmax - maximum corner of the bounding box
• #### max

public Vector3i max(Vector3i 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
Returns:
this vector
• #### min

public Vector3i min(Vector3i 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
Returns:
this
• #### write

public void write(java.io.PrintWriter pw,
NumberFormat fmt,
boolean withBrackets)
throws java.io.IOException
Writes the contents of this vector to a PrintWriter. Element values are separated by spaces, and optionally surrounded by square brackets [ ] if withBrackets is set true. Each element is formatted using a C printf style (for integers) as decribed by the parameter NumberFormat.
Specified by:
write in interface Vectori
Overrides:
write in class VectoriBase
Parameters:
pw - PrintWriter to write this vector to
fmt - numeric format
withBrackets - if true, causes the output to be surrounded by square brackets.
Throws:
java.io.IOException
• #### scan

throws java.io.IOException
Sets the contents of this vector to values read from a ReaderTokenizer. The input should consist of a sequence of numbers, separated by white space and optionally surrounded by square brackets [ ].

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.
Specified by:
scan in interface Vectori
Overrides:
scan in class VectoriBase
Parameters:
rtok - Tokenizer from which vector values are read. Number parsing should be enabled.
Throws:
java.io.IOException