Class Vector


  • public class Vector
    extends Object
    This class defines a vector. It consists of an (x,y) direction.
    • Constructor Detail

      • Vector

        public Vector​(double dx,
                      double dy)
        Constructs a new vector.
        Parameters:
        dx - the direction along the X axis
        dy - the direction along the Y axis
    • Method Detail

      • fromAngle

        public static Vector fromAngle​(double angle,
                                       double length)
        Creates a new vector with the specified angle and length. The vector with direction (1, 0) has angle 0.
        Parameters:
        angle - the angle in degrees
        length - the length
        Returns:
        the vector
      • getDx

        public double getDx()
        Returns the direction along the X axis.
        Returns:
        the direction along the X axis
      • setDx

        public void setDx​(double dx)
        Sets the direction along the X axis.
        Parameters:
        dx - the duration along the X axis
      • getDy

        public double getDy()
        Returns the direction along the Y axis.
        Returns:
        the direction along the Y axis
      • setDy

        public void setDy​(double dy)
        Sets the direction along the Y axis.
        Parameters:
        dy - the direction along the Y axis
      • rotate

        public void rotate​(double angle)
        Rotates this vector by the specified number of degrees.
        Parameters:
        angle - the number of degrees
      • getAngle

        public double getAngle()
        Returns the angle in degrees for this vector. The vector with direction (1, 0) has angle 0. This method returns a value between 0 (inclusive) and 360 (exclusive).
        Returns:
        the angle in degrees
      • getLength

        public double getLength()
        Returns the length of this vector.
        Returns:
        the length of this vector
      • isParallel

        public boolean isParallel​(Vector other)
        Returns whether another vector is parallel to this vector. This is also true if the other vector moves in the opposite direction.
        Parameters:
        other - the other vector
        Returns:
        true if the vector is parallel, false otherwise
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object