|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rit.vector.Vector2D
public class Vector2D
Class Vector2D provides a two-dimensional mathematical vector of type double. The vector's components are stored in the fields x and y.
Call one of the following static factory methods to create a buffer for sending and receiving Vector2D items in a message. To reduce the number of bytes in the message, thereby improving performance, each of these methods returns a buffer which treats a vector as a pair of doubles (rather than an object). This buffer does not support reduction. The buffer's getReductionBuf() method throws an UnsupportedOperationException.
| Field Summary | |
|---|---|
double |
x
X component. |
double |
y
Y component. |
| Constructor Summary | |
|---|---|
Vector2D()
Construct a new vector. |
|
Vector2D(double x,
double y)
Construct a new vector with the given X and Y components. |
|
Vector2D(Vector2D theVector)
Construct a new vector that is a copy of the given vector. |
|
| Method Summary | |
|---|---|
Vector2D |
add(Vector2D theVector)
Add the given vector to this vector. |
double |
arg()
Determine the argument of this vector. |
Vector2D |
assign(double x,
double y)
Assign the given X and Y components to this vector. |
Vector2D |
assign(Vector2D theVector)
Assign (copy) the given vector to this vector. |
Vector2D |
clear()
Clear this vector. |
double |
dist(Vector2D theVector)
Determine the distance (magnitude of the difference) between this vector and the given vector. |
Vector2D |
div(double a)
Divide this vector by the given scalar. |
double |
dot(Vector2D theVector)
Determine the dot product of this vector and the given vector. |
static DoubleBuf |
doubleBuffer(Vector2D[] theArray)
Create a buffer for the entire given vector array. |
static DoubleBuf |
doubleSliceBuffer(Vector2D[] theArray,
Range theRange)
Create a buffer for one slice of the given vector array. |
static DoubleBuf[] |
doubleSliceBuffers(Vector2D[] theArray,
Range[] theRanges)
Create an array of buffers for multiple slices of the given vector array. |
double |
mag()
Determine the magnitude of this vector. |
Vector2D |
mul(double a)
Multiply this vector by the given scalar. |
Vector2D |
neg()
Negate this vector. |
Vector2D |
norm()
Normalize this vector. |
void |
readExternal(ObjectInput in)
Read this vector from the given object input stream. |
Vector2D |
rotate180()
Rotate this vector 180 degrees. |
Vector2D |
rotate270()
Rotate this vector 270 degrees counterclockwise (90 degrees clockwise). |
Vector2D |
rotate90()
Rotate this vector 90 degrees counterclockwise. |
double |
sqrDist(Vector2D theVector)
Determine the squared distance (squared magnitude of the difference) between this vector and the given vector. |
double |
sqrMag()
Determine the squared magnitude of this vector. |
Vector2D |
sub(Vector2D theVector)
Subtract the given vector from this vector. |
String |
toString()
Returns a string version of this vector. |
void |
writeExternal(ObjectOutput out)
Write this vector to the given object output stream. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public double x
public double y
| Constructor Detail |
|---|
public Vector2D()
public Vector2D(double x,
double y)
x - Initial X component.y - Initial Y component.public Vector2D(Vector2D theVector)
theVector - Vector to copy.| Method Detail |
|---|
public Vector2D clear()
public Vector2D assign(double x,
double y)
x - X component.y - Y component.
public Vector2D assign(Vector2D theVector)
theVector - Vector to copy.
public Vector2D add(Vector2D theVector)
theVector - Vector to add.
public Vector2D sub(Vector2D theVector)
theVector - Vector to subtract.
public Vector2D mul(double a)
a - Scalar.
public Vector2D div(double a)
a - Scalar.
public Vector2D neg()
public Vector2D rotate90()
public Vector2D rotate180()
public Vector2D rotate270()
public Vector2D norm()
public double dot(Vector2D theVector)
theVector - Vector.
public double mag()
public double sqrMag()
public double arg()
public double dist(Vector2D theVector)
theVector - Vector.
public double sqrDist(Vector2D theVector)
theVector - Vector.
public void writeExternal(ObjectOutput out)
throws IOException
writeExternal in interface Externalizableout - Object output stream.
IOException - Thrown if an I/O error occurred.
public void readExternal(ObjectInput in)
throws IOException
readExternal in interface Externalizablein - Object input stream.
IOException - Thrown if an I/O error occurred.public String toString()
toString in class Objectpublic static DoubleBuf doubleBuffer(Vector2D[] theArray)
The returned buffer treats a vector as a pair of doubles (rather than an object). This buffer does not support reduction. The buffer's getReductionBuf() method throws an UnsupportedOperationException.
theArray - Array.
NullPointerException - (unchecked exception) Thrown if theArray is null.
public static DoubleBuf doubleSliceBuffer(Vector2D[] theArray,
Range theRange)
The returned buffer treats a vector as a pair of doubles (rather than an object). This buffer does not support reduction. The buffer's getReductionBuf() method throws an UnsupportedOperationException.
theArray - Array.theRange - Range of elements to include.
NullPointerException - (unchecked exception) Thrown if theArray is null or
theRange is null.
IndexOutOfBoundsException - (unchecked exception) Thrown if theArray does not include
all the indexes in theRange.
public static DoubleBuf[] doubleSliceBuffers(Vector2D[] theArray,
Range[] theRanges)
Each buffer in the returned buffer array treats a vector as a pair of doubles (rather than an object). This buffer does not support reduction. The buffer's getReductionBuf() method throws an UnsupportedOperationException.
theArray - Array.theRanges - Array of ranges of elements to include.
NullPointerException - (unchecked exception) Thrown if theArray is null or
theRanges or any element thereof is null.
IndexOutOfBoundsException - (unchecked exception) Thrown if theArray's allocation does
not include any element of theRanges.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||