Class Vector

java.lang.Object
com.takenoko.vector.Vector
Direct Known Subclasses:
PositionVector

public class Vector extends Object
The Vector class represents a vector in a 2D hexagonal grid.
  • Field Details

    • q

      private final double q
    • r

      private final double r
    • s

      private final double s
  • Constructor Details

    • Vector

      public Vector(double q, double r, double s)
      Constructor for the Vector class. The vector is represented by its coordinates in a 2D hexagonal grid. The vector must respect q+r+s=0.
      Parameters:
      q - The q coordinate of the vector.
      r - The r coordinate of the vector.
      s - The s coordinate of the vector.
  • Method Details

    • add

      public Vector add(Vector other)
      Add two vectors.
      Parameters:
      other - The vector to add to this vector.
      Returns:
      The sum of this vector and the other vector.
    • sub

      public Vector sub(Vector other)
      Subtract two vectors.
      Parameters:
      other - The vector to subtract to this vector.
      Returns:
      The difference of this vector and the other vector.
    • rotate60

      public Vector rotate60()
      Rotate the vector by 60 degrees.
      Returns:
      The rotated vector.
    • length

      public double length()
      Determine the length of the vector.
      Returns:
      The length of the vector.
    • distance

      public double distance(Vector other)
      Determine the distance between two vectors.
      Parameters:
      other - The other vector.
      Returns:
      The distance between the two vectors.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getNeighbors

      public List<Vector> getNeighbors()
      Determine the neighbors of the vector.
      Returns:
      The neighbors around the vector.
    • multiply

      public Vector multiply(double i)
      Multiply the vector by a scalar.
      Parameters:
      i - The number of times to multiply the vector.
      Returns:
      The multiplied vector.
    • normalize

      public Vector normalize()
      Normalize the vector.
      Returns:
      The normalized vector.
    • q

      public double q()
    • r

      public double r()
    • s

      public double s()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toPositionVector

      public PositionVector toPositionVector()