# Vector2f (Slick - The 2D Library)
Date: 2013-06-03

## org.newdawn.slick.geom
Class Vector2f

    java.lang.Object
      org.newdawn.slick.geom.Vector2f

All Implemented Interfaces:
  java.io.Serializable

    public class Vector2f

extends java.lang.Object
implements java.io.Serializable

A two dimensional vector

Author:
  Kevin Glass
See Also:
  Serialized Form

Field Summary
`float` `x` The x component of this vector
`float` `y` The y component of this vector

Constructor Summary
`Vector2f()` Create an empty vector
`Vector2f(double theta)` Create a new vector based on an angle
`Vector2f(float[] coords)` Create a vector based on the contents of a coordinate array
`Vector2f(float x, float y)` Create a new vector
`Vector2f(Vector2f other)` Create a new vector based on another

Method Summary
`Vector2f` `add(double theta)` Adjust this vector by a given angle
`Vector2f` `add(Vector2f v)` Add a vector to this vector
`Vector2f` `copy()` Return a copy of this vector
`float` `distance(Vector2f other)` Get the distance from this point to another
`float` `distanceSquared(Vector2f other)` Get the distance from this point to another, squared.
`float` `dot(Vector2f other)` Dot this vector against another
`boolean` `equals(java.lang.Object other)`
`Vector2f` `getNormal()` The normal of the vector
`Vector2f` `getPerpendicular()` A vector perpendicular to this vector.
`double` `getTheta()` Get the angle this vector is at
`float` `getX()` Get the x component
`float` `getY()` Get the y component
`int` `hashCode()`
`float` `length()` Get the length of this vector
`float` `lengthSquared()` The length of the vector squared
`Vector2f` `negate()` Negate this vector
`Vector2f` `negateLocal()` Negate this vector without creating a new copy
`Vector2f` `normalise()` Normalise the vector
`void` `projectOntoUnit(Vector2f b, Vector2f result)` Project this vector onto another
`Vector2f` `scale(float a)` Scale this vector by a value
`Vector2f` `set(float[] pt)` Set the values in this vector
`Vector2f` `set(float x, float y)` Set the values in this vector
`void` `set(Vector2f other)` Set the value of this vector
`void` `setTheta(double theta)` Calculate the components of the vectors based on a angle
`Vector2f` `sub(double theta)` Adjust this vector by a given angle
`Vector2f` `sub(Vector2f v)` Subtract a vector from this vector
`java.lang.String` `toString()`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Field Detail

### x

    public float x

  The x component of this vector

### y

    public float y

  The y component of this vector

Constructor Detail

### Vector2f

    public Vector2f()

  Create an empty vector

### Vector2f

    public Vector2f(float[] coords)

  Create a vector based on the contents of a coordinate array

  Parameters:
    `coords` - The coordinates array, index 0 = x, index 1 = y

### Vector2f

    public Vector2f(double theta)

  Create a new vector based on an angle

  Parameters:
    `theta` - The angle of the vector in degrees

### Vector2f

    public Vector2f(Vector2f other)

  Create a new vector based on another

  Parameters:
    `other` - The other vector to copy into this one

### Vector2f

    public Vector2f(float x,
                    float y)

  Create a new vector

  Parameters:
    `x` - The x component to assign
    `y` - The y component to assign

Method Detail

### setTheta

    public void setTheta(double theta)

  Calculate the components of the vectors based on a angle

  Parameters:
    `theta` - The angle to calculate the components from (in degrees)

### add

    public Vector2f add(double theta)

  Adjust this vector by a given angle

  Parameters:
    `theta` - The angle to adjust the angle by (in degrees)
  Returns:
    This vector - useful for chaining operations

### sub

    public Vector2f sub(double theta)

  Adjust this vector by a given angle

  Parameters:
    `theta` - The angle to adjust the angle by (in degrees)
  Returns:
    This vector - useful for chaining operations

### getTheta

    public double getTheta()

  Get the angle this vector is at

  Returns:
    The angle this vector is at (in degrees)

### getX

    public float getX()

  Get the x component

  Returns:
    The x component

### getY

    public float getY()

  Get the y component

  Returns:
    The y component

### set

    public void set(Vector2f other)

  Set the value of this vector

  Parameters:
    `other` - The values to set into the vector

### dot

    public float dot(Vector2f other)

  Dot this vector against another

  Parameters:
    `other` - The other vector dot agianst
  Returns:
    The dot product of the two vectors

### set

    public Vector2f set(float x,
                        float y)

  Set the values in this vector

  Parameters:
    `x` - The x component to set
    `y` - The y component to set
  Returns:
    This vector - useful for chaining operations

### getPerpendicular

    public Vector2f getPerpendicular()

  A vector perpendicular to this vector.

  Returns:
    a vector perpendicular to this vector

### set

    public Vector2f set(float[] pt)

  Set the values in this vector

  Parameters:
    `pt` - The pair of values to set into the vector
  Returns:
    This vector - useful for chaining operations

### negate

    public Vector2f negate()

  Negate this vector

  Returns:
    A copy of this vector negated

### negateLocal

    public Vector2f negateLocal()

  Negate this vector without creating a new copy

  Returns:
    This vector - useful for chaning operations

### add

    public Vector2f add(Vector2f v)

  Add a vector to this vector

  Parameters:
    `v` - The vector to add
  Returns:
    This vector - useful for chaning operations

### sub

    public Vector2f sub(Vector2f v)

  Subtract a vector from this vector

  Parameters:
    `v` - The vector subtract
  Returns:
    This vector - useful for chaining operations

### scale

    public Vector2f scale(float a)

  Scale this vector by a value

  Parameters:
    `a` - The value to scale this vector by
  Returns:
    This vector - useful for chaining operations

### normalise

    public Vector2f normalise()

  Normalise the vector

  Returns:
    This vector - useful for chaning operations

### getNormal

    public Vector2f getNormal()

  The normal of the vector

  Returns:
    A unit vector with the same direction as the vector

### lengthSquared

    public float lengthSquared()

  The length of the vector squared

  Returns:
    The length of the vector squared

### length

    public float length()

  Get the length of this vector

  Returns:
    The length of this vector

### projectOntoUnit

    public void projectOntoUnit(Vector2f b,
                                Vector2f result)

  Project this vector onto another

  Parameters:
    `b` - The vector to project onto
    `result` - The projected vector

### copy

    public Vector2f copy()

  Return a copy of this vector

  Returns:
    The new instance that copies this vector

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `java.lang.Object`
  See Also:
    `Object.toString()`

### distance

    public float distance(Vector2f other)

  Get the distance from this point to another

  Parameters:
    `other` - The other point we're measuring to
  Returns:
    The distance to the other point

### distanceSquared

    public float distanceSquared(Vector2f other)

  Get the distance from this point to another, squared. This can sometimes be used in place of distance and avoids the additional sqrt.

  Parameters:
    `other` - The other point we're measuring to
  Returns:
    The distance to the other point squared

### hashCode

    public int hashCode()

  Overrides:
    `hashCode` in class `java.lang.Object`
  See Also:
    `Object.hashCode()`

### equals

    public boolean equals(java.lang.Object other)

  Overrides:
    `equals` in class `java.lang.Object`
  See Also:
    `Object.equals(java.lang.Object)`

Copyright © 2006 New Dawn Software. All Rights Reserved.