public class Vector2d
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
double |
x
X-coordinate of the vector.
|
double |
y
Y-coordinate of the vector.
|
Constructor and Description |
---|
Vector2d()
Default constructor.
|
Vector2d(double x,
double y)
Builds a vector from its coordinates.
|
Vector2d(Vector2d v)
Builds a vector from another vector.
|
Modifier and Type | Method and Description |
---|---|
Vector2d |
add(double x,
double y)
Adds to this vector two coordinates
|
Vector2d |
add(Vector2d v)
Adds another vector to this.
|
Vector2d |
add(Vector2d v,
double w)
Adds to this vector another vector, scaled it by a factor..
|
Vector2d |
copy()
Creates a copy of this vector
|
double |
dist(double xx,
double yy)
Returns the distance from this vector to a pair of coordinates.
|
double |
dist(Vector2d v)
Returns the distance from this vector to the one in the arguments.
|
double |
dot(Vector2d v)
Calculates the dot product between this vector and the one passed by parameter.
|
boolean |
equals(java.lang.Object o)
Checks if a vector and this are the same.
|
double |
mag()
Gets the magnitude of the vector.
|
Vector2d |
mul(double fac)
Multiplies this vector by a factor.
|
void |
normalise()
Normalises this vector.
|
void |
rotate(double theta)
Rotates the vector an angle given, in radians.
|
double |
scalarProduct(Vector2d v)
Calculates the scalar product of this vector and the one passed by parameter
|
void |
set(double x,
double y)
Sets this vector's coordinates to the coordinates given.
|
void |
set(Vector2d v)
Sets this vector's coordinates to the coordinates of another vector.
|
double |
sqDist(Vector2d v)
Returns the square distance from this vector to the one in the arguments.
|
static double |
sqr(double x)
Gets the square value of the parameter passed.
|
Vector2d |
subtract(double x,
double y)
Subtracts two coordinates to this vector.
|
Vector2d |
subtract(Vector2d v)
Subtracts another vector from this.
|
double |
theta()
Returns the atan2 of this vector.
|
java.lang.String |
toString()
Returns a representative String of this vector.
|
Vector2d |
unitVector() |
Vector2d |
wrap(double w,
double h)
Performs a wrap operation over this vector.
|
void |
zero()
Sets the vector's coordinates to (0,0)
|
public double x
public double y
public Vector2d()
public Vector2d(double x, double y)
x
- x coordinatey
- y coordinatepublic Vector2d(Vector2d v)
v
- Vector to copy from.public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- the other vector to checkpublic Vector2d copy()
public void set(Vector2d v)
v
- that other vector.public void set(double x, double y)
x
- x coordinate.y
- y coordinate.public void zero()
public java.lang.String toString()
toString
in class java.lang.Object
public Vector2d add(Vector2d v)
v
- vector to add.public Vector2d add(double x, double y)
x
- x coordinatey
- y coordinatepublic Vector2d add(Vector2d v, double w)
v
- Vector to add, to be scaled by ww
- Scale of v.public Vector2d wrap(double w, double h)
w
- widthh
- heightpublic Vector2d subtract(Vector2d v)
v
- vector to subtract.public Vector2d subtract(double x, double y)
x
- x coordinatey
- y coordinatepublic Vector2d mul(double fac)
fac
- factor to multiply this vector by.public void rotate(double theta)
theta
- angle given, in radianspublic double scalarProduct(Vector2d v)
v
- vector to do the scalar product with.public static double sqr(double x)
x
- parameterpublic double sqDist(Vector2d v)
v
- the other vector, to calculate the distance to.public double mag()
public double dist(Vector2d v)
v
- the other vector, to calculate the distance to.public double dist(double xx, double yy)
xx
- x coordinateyy
- y coordinatepublic double theta()
public void normalise()
public double dot(Vector2d v)
v
- the other vector.public Vector2d unitVector()