org.pzgui.math
Class Vector2f

java.lang.Object
  extended by java.awt.geom.Point2D
      extended by org.pzgui.math.Vector2f
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class Vector2f
extends java.awt.geom.Point2D
implements java.io.Serializable, java.lang.Cloneable

A 2-element vector that is represented by float-precision floating point x,y coordinates.

Author:
David Underhill
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.geom.Point2D
java.awt.geom.Point2D.Double, java.awt.geom.Point2D.Float
 
Field Summary
static float EPS
           
 float x
           
 float y
           
 
Constructor Summary
Vector2f()
          Constructs and initializes a Vector3 to (0,0,0).
Vector2f(float[] v)
          Constructs and initializes a Vector2 from the array of length 3.
Vector2f(float x, float y)
          Constructs and initializes a Vector2 from the specified xy coordinates.
Vector2f(Vector2f v1)
          Constructs and initializes a Vector2 from the specified Vector3.
Vector2f(Vector2f from, Vector2f to)
          Constructs and initializes a Vector2 from one point to another
 
Method Summary
 Vector2f add(Vector2f v)
          adds v to this vector
static Vector2f add(Vector2f v1, Vector2f v2)
          adds v to this vector
 void clamp(float xMax, float yMax)
          clamps the values to the specified ranges (minimum value = 0)
 Vector2f clone()
           
 Vector2f divide(float s)
          divides this by s and returns this
static Vector2f divide(Vector2f v1, float s)
          returns the quotient of a vector and a scalar
 double getX()
           
 double getY()
           
 float length()
          Returns the length of this vector.
 float lengthSq()
          Returns the length squared of this vector.
static Vector2f makeUnit(Vector2f v)
          adds v to this vector
 Vector2f multiply(float s)
          multiplies this by s and returns this
static Vector2f multiply(Vector2f v1, float s)
          returns the product of a vector and a scalar
 void set(float x, float y)
          sets the components of this vector
 void setLocation(double x, double y)
           
 void setX(float x)
           
 void setY(float y)
           
 Vector2f subtract(Vector2f v)
          subtracts v from this vector
static Vector2f subtract(Vector2f v1, Vector2f v2)
          adds v to this vector
 java.lang.String toString()
           
 java.lang.String toStringPlain()
           
 
Methods inherited from class java.awt.geom.Point2D
distance, distance, distance, distanceSq, distanceSq, distanceSq, equals, hashCode, setLocation
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EPS

public static final float EPS
See Also:
Constant Field Values

x

public float x

y

public float y
Constructor Detail

Vector2f

public Vector2f(float x,
                float y)
Constructs and initializes a Vector2 from the specified xy coordinates.

Parameters:
x - the x coordinate
y - the y coordinate

Vector2f

public Vector2f(float[] v)
Constructs and initializes a Vector2 from the array of length 3.

Parameters:
v - the array of length 2 containing xyz in order

Vector2f

public Vector2f(Vector2f v1)
Constructs and initializes a Vector2 from the specified Vector3.

Parameters:
v1 - the Vector2 containing the initialization x y data

Vector2f

public Vector2f(Vector2f from,
                Vector2f to)
Constructs and initializes a Vector2 from one point to another


Vector2f

public Vector2f()
Constructs and initializes a Vector3 to (0,0,0).

Method Detail

getX

public double getX()
Specified by:
getX in class java.awt.geom.Point2D

getY

public double getY()
Specified by:
getY in class java.awt.geom.Point2D

setX

public void setX(float x)

setY

public void setY(float y)

set

public void set(float x,
                float y)
sets the components of this vector


setLocation

public void setLocation(double x,
                        double y)
Specified by:
setLocation in class java.awt.geom.Point2D

clamp

public void clamp(float xMax,
                  float yMax)
clamps the values to the specified ranges (minimum value = 0)


length

public final float length()
Returns the length of this vector.

Returns:
the length of this vector

lengthSq

public final float lengthSq()
Returns the length squared of this vector.

Returns:
the length squared of this vector

add

public Vector2f add(Vector2f v)
adds v to this vector


subtract

public Vector2f subtract(Vector2f v)
subtracts v from this vector


multiply

public Vector2f multiply(float s)
multiplies this by s and returns this


divide

public Vector2f divide(float s)
divides this by s and returns this


multiply

public static Vector2f multiply(Vector2f v1,
                                float s)
returns the product of a vector and a scalar


divide

public static Vector2f divide(Vector2f v1,
                              float s)
returns the quotient of a vector and a scalar


add

public static Vector2f add(Vector2f v1,
                           Vector2f v2)
adds v to this vector


subtract

public static Vector2f subtract(Vector2f v1,
                                Vector2f v2)
adds v to this vector


makeUnit

public static Vector2f makeUnit(Vector2f v)
adds v to this vector


clone

public Vector2f clone()
Overrides:
clone in class java.awt.geom.Point2D

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toStringPlain

public java.lang.String toStringPlain()