|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectvooga.physicsEngine.geometry.mathUtils.Vector2f
public class Vector2f
A utility class representing a 2-dimensional vector. Some of this code is copied from an online open-source implementation by Kevin Glass.
Field Summary | |
---|---|
double |
delta
|
protected double |
x
|
protected double |
y
|
Constructor Summary | |
---|---|
Vector2f()
Create a (0,0) vector. |
|
Vector2f(double x,
double y)
Create a new vector |
|
Vector2f(Vector2f other)
Create a new vector based on another |
Method Summary | |
---|---|
Vector2f |
add(Vector2f difference)
|
Vector2f |
clone()
|
double |
cross(Vector2f vec)
Computes the magnitude of the cross product with given vector. |
static double |
cross(Vector2f a,
Vector2f b)
Return the magnitude of the cross product bewteen a and b (a.x*b.y-a.y*b.x) |
static Vector2f |
difference(Vector2f first,
Vector2f second)
Compute the vector difference first-second |
double |
distance(Vector2f other)
Get the distance from this point to another |
double |
distanceSquared(Vector2f other)
Get the distance squared from this point to another |
double |
dot(Vector2f vec)
Compute the dot product between a and b |
static double |
dot(Vector2f a,
Vector2f b)
Returns the dot product of a and b. |
boolean |
equals(java.lang.Object other)
|
boolean |
equalsDelta(Vector2f other,
double delta)
Compare two vectors allowing for a (small) error as indicated by the delta. |
static Vector2f |
fromPosition(Position position)
|
static Vector2f |
getRealCordinates(Vector2f relativeCoordinate,
Vector2f centroid,
double angularPosition)
Obtain the real coordinate of some point given that the old coordinate has centroid is (0,0) and is unrotated.` |
double |
getX()
Get the x position of the vector |
double |
getY()
Get the y position of the vector |
double |
length()
Computes the Euclidean length of this vector. |
double |
lengthSquared()
The length of the vector squared |
static Vector2f |
mean(java.util.List<Vector2f> points)
Return the mean of the given vectors; returning (0,0) if the mean is empty |
static Vector2f |
mult(Vector2f vector,
double scalar)
Return the scalar product of the vector and scalar |
Vector2f |
normalise()
Normalise the vector |
static Vector2f |
normalize(Vector2f vec)
Normalize the given vector without changing it. |
Vector2f |
reverse()
Reverse this vector (no copying) |
static Vector2f |
rotateBy90CCW(Vector2f vec)
Return a new vector that is the given rotated by 90 degrees counterclockwise |
static Vector2f |
rotateBy90CW(Vector2f vec)
Return a new vector that is the given rotated by 90 degrees clockwise |
Vector2f |
scale(double a)
Scale this vector by a value |
void |
set(double x,
double y)
Change values of a vector |
void |
set(float x,
float y)
Set the values in this vector |
void |
set(Vector2f other)
Set the value of this vector |
Vector2f |
sub(Vector2f v)
Subtract a vector from this vector |
static Vector2f |
sum(java.util.List<Vector2f> summands)
Sum a list of vectors and return the result |
static Vector2f |
sum(Vector2f a,
Vector2f b)
Find the sum of vectors a and b |
static Position |
toPosition(Vector2f vector)
Translates given Vector2f into a game engine Position object. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected double x
protected double y
public final double delta
Constructor Detail |
---|
public Vector2f(double x, double y)
x
- The x componenty
- The y componentpublic Vector2f(Vector2f other)
other
- The other vector to copy into this onepublic Vector2f()
Method Detail |
---|
public Vector2f clone()
clone
in class java.lang.Object
public double getX()
public double getY()
public void set(double x, double y)
x
- The new x value of the vectory
- The new y value of the vectorpublic Vector2f add(Vector2f difference)
difference
- public static Vector2f fromPosition(Position position)
public void set(Vector2f other)
other
- The values to set into the vectorpublic double dot(Vector2f vec)
vec
-
public void set(float x, float y)
x
- The x component to sety
- The y component to setpublic Vector2f reverse()
public Vector2f sub(Vector2f v)
v
- The vector subtractpublic Vector2f scale(double a)
a
- The value to scale this vector bypublic Vector2f normalise()
public double lengthSquared()
public double length()
public java.lang.String toString()
toString
in class java.lang.Object
public double distance(Vector2f other)
other
- The other point we're measuring to
public double distanceSquared(Vector2f other)
other
- The other point we're measuring to
public boolean equalsDelta(Vector2f other, double delta)
other
- The other vector to compare this one todelta
- The allowed error
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public static Vector2f sum(java.util.List<Vector2f> summands)
summands
-
public static Vector2f sum(Vector2f a, Vector2f b)
a
- b
-
public static Vector2f mean(java.util.List<Vector2f> points)
points
-
public static double cross(Vector2f a, Vector2f b)
vec
-
public double cross(Vector2f vec)
vec
-
public static Vector2f getRealCordinates(Vector2f relativeCoordinate, Vector2f centroid, double angularPosition)
relativeCoordinate
- centroid
- angularPosition
-
public static Vector2f difference(Vector2f first, Vector2f second)
first
- second
-
public static Vector2f rotateBy90CCW(Vector2f vec)
vec
-
public static Vector2f rotateBy90CW(Vector2f vec)
vec
-
public static double dot(Vector2f a, Vector2f b)
a
- b
-
public static Vector2f mult(Vector2f vector, double scalar)
vector
- scalar
-
public static Vector2f normalize(Vector2f vec)
vec
-
public static Position toPosition(Vector2f vector)
vector
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |