Overview
Vector2 is a utility class for handling 2D coordinates. It includes methods for arithmetic, interpolation, normalization, and other vector operations commonly used in game development.
Constructors
Vector2()Creates a zero vector (0,0).
Vector2(float x, float y)Creates a vector with specified x and y values.
Vector2(Vector2 v2)Creates a copy of another vector.
Core Methods
float getX(), getY() – Get X or Y value.void setX(float), setY(float) – Set X or Y value.void set(float x, float y) – Set both X and Y values.Vector2 getFromString(String str) – Parse vector from "x,y" string format.float distance(Vector2 other) – Distance to another vector.Vector2 add(Vector2 other) – Add another vector to this one.Vector2 subtract(Vector2 other) – Subtract another vector from this one.Vector2 multiply(float) – Multiply both components by a scalar.Vector2 multiply(float sx, float sy) – Multiply by separate scalars.Vector2 divide(float) – Divide both components by a scalar.Vector2 divide(float sx, float sy) – Divide by separate scalars.float magnitude() – Return the length of the vector.Vector2 normalized() – Return the normalized (unit length) vector.float dot(Vector2 other) – Dot product with another vector.Vector2 scale(float scalar) – Return a scaled copy.Vector2 lerp(Vector2 other, float t) – Linear interpolation with another vector.void reorder() – Swap x and y if y is greater than x.String toString() – Convert to string format "(x, y)".Static Methods
static float doProduct(Vector2 v1, Vector2 v2) – Return dot product of two vectors.static double angleBetween(Vector2 v1, Vector2 v2) – Return the angle between two vectors in radians.