Package org.collebol.math
Class Vector2D
java.lang.Object
org.collebol.math.Vector2D
This 2D game Vector represents a quantity with both direction and magnitude (length),
typically used for movement, velocity, and position. It is described by two components:
x (horizontal) and y (vertical).
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Vector2D
public Vector2D(float x, float y)
-
-
Method Details
-
getX
public float getX() -
setX
public void setX(float x) -
getY
public float getY() -
setY
public void setY(float y) -
add
Add up two vectors.- Parameters:
other- the other vector you want to add up.- Returns:
- new vector with the combined vector values.
-
subtract
Subtract two vectors.- Parameters:
other- vector you want to subtract.- Returns:
- new vector. ( x - other ).
-
scale
Multiply vector values with scalar.- Parameters:
scalar- the value you want to multiply with- Returns:
- new vector with multiplied values.
-
length
public float length()Calculate the length (magnitude) of the vector.- Returns:
- magnitude
-