Class ActorVector
java.lang.Object
ActiverseUtils.ActorVector
The ActorVector class represents a 2D vector in the Activerse game engine.
It can represent position, velocity, acceleration, or directional displacement
between two Actor objects.
- Version:
- 1.4.0
- Author:
- Knivier
-
Constructor Summary
ConstructorsConstructorDescriptionActorVector
(double x, double y) Constructs a vector from given x and y components.ActorVector
(Actor actor) Constructs a vector representing the position of a single actor.ActorVector
(Actor from, Actor to) Constructs a vector from one actor to another. -
Method Summary
Modifier and TypeMethodDescriptionadd
(ActorVector other) Adds another vector to this one.double
angleBetween
(ActorVector other) Calculates the angle in degrees between this vector and another.double
dot
(ActorVector other) Computes the dot product between this vector and another.boolean
Checks if two vectors are equal based on x and y components.double
getX()
double
getY()
int
hashCode()
Returns the hash code for this vector.double
Returns the magnitude (length) of the vector using the Euclidean formula.Returns a new vector representing the direction (unit vector) of this vector.scale
(double scalar) Scales the vector by a scalar multiplier.subtract
(ActorVector other) Subtracts another vector from this one.toAcceleration
(double mass) Simulates a force applied on a mass and returns the resulting acceleration vector.double
toKineticEnergy
(double mass) Computes kinetic energy: KE = 0.5 * m * v², where v = this vector's magnitude.toString()
Returns a string representation of the vector in coordinate format.
-
Constructor Details
-
ActorVector
public ActorVector(double x, double y) Constructs a vector from given x and y components.- Parameters:
x
- the x-componenty
- the y-component
-
ActorVector
Constructs a vector representing the position of a single actor. Useful as a base vector or for physics calculations.- Parameters:
actor
- the Actor whose position to use
-
ActorVector
-
-
Method Details
-
getX
public double getX()- Returns:
- the x-component of the vector
-
getY
public double getY()- Returns:
- the y-component of the vector
-
magnitude
public double magnitude()Returns the magnitude (length) of the vector using the Euclidean formula.- Returns:
- the vector's magnitude
-
normalize
Returns a new vector representing the direction (unit vector) of this vector.- Returns:
- the normalized vector (same direction, length of 1)
-
scale
Scales the vector by a scalar multiplier.- Parameters:
scalar
- the scalar value to multiply with- Returns:
- a new scaled ActorVector
-
add
Adds another vector to this one.- Parameters:
other
- the vector to add- Returns:
- the resulting vector
-
subtract
Subtracts another vector from this one.- Parameters:
other
- the vector to subtract- Returns:
- the resulting vector
-
dot
Computes the dot product between this vector and another. Useful for projecting vectors or determining angles between them.- Parameters:
other
- the other ActorVector- Returns:
- the dot product (a scalar)
-
angleBetween
Calculates the angle in degrees between this vector and another.- Parameters:
other
- the other vector- Returns:
- angle in degrees (0–180)
-
toAcceleration
Simulates a force applied on a mass and returns the resulting acceleration vector. a = F / m- Parameters:
mass
- the mass of the object (in kg)- Returns:
- acceleration vector (m/s²)
-
toKineticEnergy
public double toKineticEnergy(double mass) Computes kinetic energy: KE = 0.5 * m * v², where v = this vector's magnitude.- Parameters:
mass
- the mass of the object (in kg)- Returns:
- the kinetic energy in joules
-
toString
-
equals
-
hashCode
-