public class Vec2
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
double |
x
The vector's X component.
|
double |
y
The vector's Y component.
|
Constructor and Description |
---|
Vec2()
Constructs a two-component vector with X and Y both 0.
|
Vec2(double x,
double y)
Constructs a two-component vector with a specified X and Y.
|
Vec2(Vec2 vector)
Constructs a two-component vector with the X and Y of a specified vector.
|
Modifier and Type | Method and Description |
---|---|
Vec2 |
add(Vec2 vector)
Adds a specified vector to this vector.
|
double |
distanceTo(Vec2 vector)
Computes the distance from this vector to another vector.
|
double |
distanceToSquared(Vec2 vector)
Computes the squared distance from this vector to a specified vector.
|
Vec2 |
divide(double divisor)
Divides this vector by a scalar.
|
double |
dot(Vec2 vector)
Computes the scalar dot product of this vector and a specified vector.
|
boolean |
equals(java.lang.Object o) |
int |
hashCode() |
double |
magnitude()
Computes the magnitude of this vector.
|
double |
magnitudeSquared()
Computes the squared magnitude of this vector.
|
Vec2 |
mix(Vec2 vector,
double weight)
Mixes (interpolates) a specified vector with this vector, modifying this vector.
|
Vec2 |
multiply(double scalar)
Multiplies this vector by a scalar.
|
Vec2 |
multiplyByMatrix(Matrix3 matrix)
Multiplies this vector by a 3x3 matrix.
|
Vec2 |
negate()
Negates the components of this vector.
|
Vec2 |
normalize()
Normalizes this vector to a unit vector.
|
Vec2 |
set(double x,
double y)
Sets this vector to the specified X and Y.
|
Vec2 |
set(Vec2 vector)
Sets this vector to the X and Y of a specified vector.
|
Vec2 |
subtract(Vec2 vector)
Subtracts a specified vector from this vector.
|
Vec2 |
swap(Vec2 vector)
Swaps this vector with the specified vector.
|
float[] |
toArray(float[] result,
int offset)
Copies this vector's components to the specified single precision array.
|
java.lang.String |
toString() |
public double x
public double y
public Vec2()
public Vec2(double x, double y)
x
- the vector's X componenty
- the vector's Y componentpublic Vec2(Vec2 vector)
vector
- the vector specifying the componentsjava.lang.IllegalArgumentException
- If the vector is nullpublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public float[] toArray(float[] result, int offset)
result
- a pre-allocated array of length 2 in which to return the componentspublic double magnitude()
public double magnitudeSquared()
magnitude
but is potentially much more efficient.public double distanceTo(Vec2 vector)
vector
- the vector to compute the distance tojava.lang.IllegalArgumentException
- If the vector is nullpublic double distanceToSquared(Vec2 vector)
distanceTo
but is potentially much more efficient.vector
- the vector to compute the distance tojava.lang.IllegalArgumentException
- If the vector is nullpublic Vec2 set(double x, double y)
x
- the new X componenty
- the new Y componentpublic Vec2 set(Vec2 vector)
vector
- the vector specifying the new componentsjava.lang.IllegalArgumentException
- If the vector is nullpublic Vec2 swap(Vec2 vector)
vector
- the vector to swap with this vectorjava.lang.IllegalArgumentException
- If the vector is nullpublic Vec2 add(Vec2 vector)
vector
- the vector to addjava.lang.IllegalArgumentException
- If the vector is nullpublic Vec2 subtract(Vec2 vector)
vector
- the vector to subtractjava.lang.IllegalArgumentException
- If the vector is nullpublic Vec2 multiply(double scalar)
scalar
- the scalar to multiply this vector bypublic Vec2 multiplyByMatrix(Matrix3 matrix)
matrix
- the matrix to multiply this vector byjava.lang.IllegalArgumentException
- If the matrix is nullpublic Vec2 divide(double divisor)
divisor
- the scalar to divide this vector bypublic Vec2 negate()
public Vec2 normalize()
public double dot(Vec2 vector)
vector
- the vector to multiplyjava.lang.IllegalArgumentException
- If the vector is nullpublic Vec2 mix(Vec2 vector, double weight)
vector
- The vector to mix with this oneweight
- The relative weight of this vector, typically in the range [0,1]java.lang.IllegalArgumentException
- If the vector is null