public class Vec2 extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
float |
x
The x component, increasing to the right.
|
float |
y
The y component, increasing upwards.
|
Constructor and Description |
---|
Vec2()
A vector with x and y components both zero.
|
Vec2(float x,
float y)
A vector with the given components.
|
Modifier and Type | Method and Description |
---|---|
Vec2 |
add(Vec2 v)
Return the sum of this vector and another; does not alter either one.
|
static float |
cross(Vec2 a,
Vec2 b)
The z-component of the cross product of two vectors.
|
static float |
dot(Vec2 a,
Vec2 b)
The dot product of two vectors.
|
int |
hashCode()
Returns a hash code value for the object for use in hash tables.
|
float |
length()
Return the length of this vector.
|
float |
lengthSquared()
Return the squared length of this vector.
|
Vec2 |
mul(float a)
Return this vector multiplied by a number; does not alter this vector.
|
Vec2 |
negate()
Return the negation of this vector; does not alter this vector.
|
float |
normalize()
Normalize this vector and return the length before normalization.
|
Vec2 |
sub(Vec2 v)
Return the difference between this vector and another; does not
alter either one.
|
String |
toString()
Return a string representation of the vector.
|
public float x
public float y
public Vec2()
public Vec2(float x, float y)
x
- the x component, increasing to the righty
- the y component, increasing upwardspublic final Vec2 add(Vec2 v)
v
- a vector to be added to this onepublic final Vec2 sub(Vec2 v)
v
- a vector to be added to this onepublic final Vec2 mul(float a)
a
- number to multiply the vector bypublic final Vec2 negate()
public final float length()
public final float lengthSquared()
public final float normalize()
public final String toString()
public static final float cross(Vec2 a, Vec2 b)