Class ActorVector

java.lang.Object
ActiverseUtils.ActorVector

public class ActorVector extends Object
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

    Constructors
    Constructor
    Description
    ActorVector(double x, double y)
    Constructs a vector from given x and y components.
    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 Type
    Method
    Description
    Adds another vector to this one.
    double
    Calculates the angle in degrees between this vector and another.
    double
    Computes the dot product between this vector and another.
    boolean
    Checks if two vectors are equal based on x and y components.
    double
     
    double
     
    int
    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.
    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.
    Returns a string representation of the vector in coordinate format.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ActorVector

      public ActorVector(double x, double y)
      Constructs a vector from given x and y components.
      Parameters:
      x - the x-component
      y - the y-component
    • ActorVector

      public ActorVector(Actor actor)
      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

      public ActorVector(Actor from, Actor to)
      Constructs a vector from one actor to another. Useful for computing direction, distance, and relative motion.
      Parameters:
      from - the origin Actor
      to - the destination Actor
  • 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

      public ActorVector normalize()
      Returns a new vector representing the direction (unit vector) of this vector.
      Returns:
      the normalized vector (same direction, length of 1)
    • scale

      public ActorVector scale(double scalar)
      Scales the vector by a scalar multiplier.
      Parameters:
      scalar - the scalar value to multiply with
      Returns:
      a new scaled ActorVector
    • add

      public ActorVector add(ActorVector other)
      Adds another vector to this one.
      Parameters:
      other - the vector to add
      Returns:
      the resulting vector
    • subtract

      public ActorVector subtract(ActorVector other)
      Subtracts another vector from this one.
      Parameters:
      other - the vector to subtract
      Returns:
      the resulting vector
    • dot

      public double dot(ActorVector other)
      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

      public double angleBetween(ActorVector other)
      Calculates the angle in degrees between this vector and another.
      Parameters:
      other - the other vector
      Returns:
      angle in degrees (0–180)
    • toAcceleration

      public ActorVector toAcceleration(double mass)
      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

      public String toString()
      Returns a string representation of the vector in coordinate format.
      Overrides:
      toString in class Object
      Returns:
      the string (x, y)
    • equals

      public boolean equals(Object obj)
      Checks if two vectors are equal based on x and y components.
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare
      Returns:
      true if the vectors are identical, false otherwise
    • hashCode

      public int hashCode()
      Returns the hash code for this vector.
      Overrides:
      hashCode in class Object
      Returns:
      hash code