|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.ou.utils.Vector2D
public final class Vector2D
Vector2D provides an immutable vector representation as well as a collection of useful vector operations.
Field Summary | |
---|---|
static float |
HALFPI
|
static float |
THREEHALFPI
|
static float |
TWOPI
|
static Vector2D |
X_NEG_UNIT_VECTOR
|
static Vector2D |
X_UNIT_VECTOR
|
static Vector2D |
Y_NEG_UNIT_VECTOR
|
static Vector2D |
Y_UNIT_VECTOR
|
static Vector2D |
ZERO_VECTOR
|
Constructor Summary | |
---|---|
Vector2D()
Create the zero vector |
|
Vector2D(float x,
float y)
Create a vector with the given x and y values. |
|
Vector2D(Vector2D b)
Create a new vector from an old one; |
Method Summary | |
---|---|
Vector2D |
add(Vector2D v)
Add these two vectors together. |
float |
angleBetween(Vector2D v)
The angle (in radians) between this vector and the given vector. |
int |
compareTo(Vector2D other)
Compare the vectors on the basis of magnitude. |
float |
cross(Vector2D v)
Get the cross product of the two vectors. |
Vector2D |
divide(float f)
Divide this vector by the given scalar. |
float |
dot(Vector2D v)
Get the dot product of the two vectors. |
boolean |
equals(java.lang.Object obj)
|
boolean |
equals(Vector2D v)
Determine if two vectors are equal (have the same components) |
Vector2D |
fastRotate(float cos,
float sin)
Rotate this vector using the given sine and cosine values. |
static Vector2D |
fromAngle(float angle,
float magnitude)
Create a vector from the given angle (in radians) and magnitude |
float |
getAngle()
The angle of the vector |
float |
getMagnitude()
The magnitude of the vector. |
static Vector2D |
getRandom(java.util.Random rand,
float maxMagnitude)
Create a random vector with a magnitude no greater than specified |
float |
getX()
The X component of the vector. |
float |
getY()
The Y component of the vector. |
int |
hashCode()
|
static void |
main(java.lang.String[] args)
|
Vector2D |
multiply(float f)
Multiply this vector by the given scalar. |
Vector2D |
negate()
Reverse this vector. |
Vector2D |
project(Vector2D v)
Project the given vector onto this vector. |
Vector2D |
rotate(float f)
Rotate this vector by the specified angle (in radians) |
Vector2D |
subtract(Vector2D v)
Subtract the other vector from this vector. |
Vector2D |
subtractAndRotate(Vector2D v,
float cos,
float sin)
Subtract the other vector from this vector and rotate the result using the given sine and cosine values. |
java.lang.String |
toString()
|
Vector2D |
unit()
The unit vector derived from this vector, or an arbitrary unit vector if this is the zero vector |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final Vector2D ZERO_VECTOR
public static final Vector2D X_UNIT_VECTOR
public static final Vector2D X_NEG_UNIT_VECTOR
public static final Vector2D Y_UNIT_VECTOR
public static final Vector2D Y_NEG_UNIT_VECTOR
public static final float HALFPI
public static final float THREEHALFPI
public static final float TWOPI
Constructor Detail |
---|
public Vector2D(float x, float y)
x
- y
- public Vector2D(Vector2D b)
public Vector2D()
Method Detail |
---|
public static Vector2D fromAngle(float angle, float magnitude)
angle
- In radiansmagnitude
-
public static Vector2D getRandom(java.util.Random rand, float maxMagnitude)
rand
- The source of randomness to use.maxMagnitude
-
public final float getX()
public final float getY()
public final float getMagnitude()
public final float getAngle()
public final float angleBetween(Vector2D v)
v
- A given vector.
public final Vector2D unit()
public final Vector2D negate()
public final Vector2D add(Vector2D v)
v
- Vector to add
public final Vector2D subtract(Vector2D v)
v
-
public final Vector2D multiply(float f)
f
-
public final Vector2D divide(float f)
f
-
public final float dot(Vector2D v)
v
-
public final float cross(Vector2D v)
v
-
public final Vector2D fastRotate(float cos, float sin)
cos
- sin
-
public final Vector2D subtractAndRotate(Vector2D v, float cos, float sin)
v
- cos
- sin
-
public final Vector2D rotate(float f)
f
-
public final Vector2D project(Vector2D v)
v
-
public final boolean equals(Vector2D v)
v
-
public int compareTo(Vector2D other)
compareTo
in interface java.lang.Comparable<Vector2D>
other
-
public java.lang.String toString()
toString
in class java.lang.Object
public static void main(java.lang.String[] args)
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |