tools

## Class Vector2d

- java.lang.Object
- - tools.Vector2d

-     public class Vector2d
      extends java.lang.Object

  This class represents a vector, or a position, in the map. PTSP-Competition Created by Diego Perez, University of Essex. Date: 19/12/11

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `double` | `x` X-coordinate of the vector.
    `double` | `y` Y-coordinate of the vector.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Vector2d()` Default constructor.
    `Vector2d(double x, double y)` Builds a vector from its coordinates.
    `Vector2d(Vector2d v)` Builds a vector from another vector.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Vector2d` | `add(double x, double y)` Adds to this vector two coordinates
    `Vector2d` | `add(Vector2d v)` Adds another vector to this.
    `Vector2d` | `add(Vector2d v, double w)` Adds to this vector another vector, scaled it by a factor..
    `Vector2d` | `copy()` Creates a copy of this vector
    `double` | `dist(double xx, double yy)` Returns the distance from this vector to a pair of coordinates.
    `double` | `dist(Vector2d v)` Returns the distance from this vector to the one in the arguments.
    `double` | `dot(Vector2d v)` Calculates the dot product between this vector and the one passed by parameter.
    `boolean` | `equals(java.lang.Object o)` Checks if a vector and this are the same.
    `double` | `mag()` Gets the magnitude of the vector.
    `Vector2d` | `mul(double fac)` Multiplies this vector by a factor.
    `void` | `normalise()` Normalises this vector.
    `void` | `rotate(double theta)` Rotates the vector an angle given, in radians.
    `double` | `scalarProduct(Vector2d v)` Calculates the scalar product of this vector and the one passed by parameter
    `void` | `set(double x, double y)` Sets this vector's coordinates to the coordinates given.
    `void` | `set(Vector2d v)` Sets this vector's coordinates to the coordinates of another vector.
    `double` | `sqDist(Vector2d v)` Returns the square distance from this vector to the one in the arguments.
    `static double` | `sqr(double x)` Gets the square value of the parameter passed.
    `Vector2d` | `subtract(double x, double y)` Subtracts two coordinates to this vector.
    `Vector2d` | `subtract(Vector2d v)` Subtracts another vector from this.
    `double` | `theta()` Returns the atan2 of this vector.
    `java.lang.String` | `toString()` Returns a representative String of this vector.
    `Vector2d` | `unitVector()`
    `Vector2d` | `wrap(double w, double h)` Performs a wrap operation over this vector.
    `void` | `zero()` Sets the vector's coordinates to (0,0)

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### x

          public double x

      X-coordinate of the vector.

    - #### y

          public double y

      Y-coordinate of the vector.

  - ### Constructor Detail

    - #### Vector2d

          public Vector2d()

      Default constructor.

    - #### Vector2d

          public Vector2d(double x,
                  double y)

      Builds a vector from its coordinates.
      Parameters:
        `x` - x coordinate
        `y` - y coordinate

    - #### Vector2d

          public Vector2d(Vector2d v)

      Builds a vector from another vector.
      Parameters:
        `v` - Vector to copy from.

  - ### Method Detail

    - #### equals

          public boolean equals(java.lang.Object o)

      Checks if a vector and this are the same.
      Overrides:
        `equals` in class `java.lang.Object`
      Parameters:
        `o` - the other vector to check
      Returns:
        true if their coordinates are the same.

    - #### copy

          public Vector2d copy()

      Creates a copy of this vector
      Returns:
        a copy of this vector

    - #### set

          public void set(Vector2d v)

      Sets this vector's coordinates to the coordinates of another vector.
      Parameters:
        `v` - that other vector.

    - #### set

          public void set(double x,
                 double y)

      Sets this vector's coordinates to the coordinates given.
      Parameters:
        `x` - x coordinate.
        `y` - y coordinate.

    - #### zero

          public void zero()

      Sets the vector's coordinates to (0,0)

    - #### toString

          public java.lang.String toString()

      Returns a representative String of this vector.
      Overrides:
        `toString` in class `java.lang.Object`
      Returns:
        a representative String of this vector.

    - #### add

          public Vector2d add(Vector2d v)

      Adds another vector to this.
      Parameters:
        `v` - vector to add.
      Returns:
        this, after the addition.

    - #### add

          public Vector2d add(double x,
                     double y)

      Adds to this vector two coordinates
      Parameters:
        `x` - x coordinate
        `y` - y coordinate
      Returns:
        returns this, after the addition.

    - #### add

          public Vector2d add(Vector2d v,
                     double w)

      Adds to this vector another vector, scaled it by a factor..
      Parameters:
        `v` - Vector to add, to be scaled by w
        `w` - Scale of v.
      Returns:
        this vector, after the addition.

    - #### wrap

          public Vector2d wrap(double w,
                      double h)

      Performs a wrap operation over this vector.
      Parameters:
        `w` - width
        `h` - height
      Returns:
        This vector, after the wrap.

    - #### subtract

          public Vector2d subtract(Vector2d v)

      Subtracts another vector from this.
      Parameters:
        `v` - vector to subtract.
      Returns:
        this, after the subtraction.

    - #### subtract

          public Vector2d subtract(double x,
                          double y)

      Subtracts two coordinates to this vector.
      Parameters:
        `x` - x coordinate
        `y` - y coordinate
      Returns:
        returns this, after the subtraction.

    - #### mul

          public Vector2d mul(double fac)

      Multiplies this vector by a factor.
      Parameters:
        `fac` - factor to multiply this vector by.
      Returns:
        This vector, after the operation.

    - #### rotate

          public void rotate(double theta)

      Rotates the vector an angle given, in radians.
      Parameters:
        `theta` - angle given, in radians

    - #### scalarProduct

          public double scalarProduct(Vector2d v)

      Calculates the scalar product of this vector and the one passed by parameter
      Parameters:
        `v` - vector to do the scalar product with.
      Returns:
        the value of the scalar product.

    - #### sqr

          public static double sqr(double x)

      Gets the square value of the parameter passed.
      Parameters:
        `x` - parameter
      Returns:
        x * x

    - #### sqDist

          public double sqDist(Vector2d v)

      Returns the square distance from this vector to the one in the arguments.
      Parameters:
        `v` - the other vector, to calculate the distance to.
      Returns:
        the square distance, in pixels, between this vector and v.

    - #### mag

          public double mag()

      Gets the magnitude of the vector.
      Returns:
        the magnitude of the vector (Math.sqrt(sqr(x) + sqr(y)))

    - #### dist

          public double dist(Vector2d v)

      Returns the distance from this vector to the one in the arguments.
      Parameters:
        `v` - the other vector, to calculate the distance to.
      Returns:
        the distance, in pixels, between this vector and v.

    - #### dist

          public double dist(double xx,
                    double yy)

      Returns the distance from this vector to a pair of coordinates.
      Parameters:
        `xx` - x coordinate
        `yy` - y coordinate
      Returns:
        the distance, in pixels, between this vector and the pair of coordinates.

    - #### theta

          public double theta()

      Returns the atan2 of this vector.
      Returns:
        the atan2 of this vector.

    - #### normalise

          public void normalise()

      Normalises this vector.

    - #### dot

          public double dot(Vector2d v)

      Calculates the dot product between this vector and the one passed by parameter.
      Parameters:
        `v` - the other vector.
      Returns:
        the dot product between these two vectors.

    - #### unitVector

          public Vector2d unitVector()