net.java.dev.joode.util
Class Vector2

java.lang.Object
  extended by net.java.dev.joode.util.Vector2
All Implemented Interfaces:
ROVector2

public class Vector2
extends java.lang.Object
implements ROVector2

A two dimensional vector

Author:
Kevin Glass

Field Summary
 float x
          The x component of this vector
 float y
          The y component of this vector
 
Constructor Summary
Vector2()
          Create an empty vector
Vector2(float x, float y)
          Create a new vector
Vector2(ROVector2 other)
          Create a new vector based on another
 
Method Summary
 void add(ROVector2 v)
          Add a vector to this vector
 float distance(ROVector2 other)
          Get the distance from this point to another
 float dot(ROVector2 other)
          Get the dot product of this vector and another
 boolean equalsDelta(ROVector2 other, float delta)
          Compare two vectors allowing for a (small) error as indicated by the delta.
 float getX()
          Get the X component of this vector
 float getY()
          Get the Y component of this vector
 float length()
          Get the length of this vector
 float lengthSquared()
          The length of the vector squared
 Vector2 negate()
          Negate this vector
 void normalise()
          Normalise the vector
 void perp(Vector2 passback)
          returns (in the passback) a perpendicular vector.
 void projectOntoUnit(ROVector2 b, Vector2 result)
          Project this vector onto another
 void scale(float a)
          Scale this vector by a value
 void set(float x, float y)
          Set the values in this vector
 void set(ROVector2 other)
          Set the value of this vector
 void sub(ROVector2 v)
          Subtract a vector from this vector
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, 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

Vector2

public Vector2()
Create an empty vector


Vector2

public Vector2(ROVector2 other)
Create a new vector based on another

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

Vector2

public Vector2(float x,
               float y)
Create a new vector

Parameters:
x - The x component to assign
y - The y component to assign
Method Detail

getX

public float getX()
Description copied from interface: ROVector2
Get the X component of this vector

Specified by:
getX in interface ROVector2
Returns:
The X component of this vector
See Also:
ROVector2.getX()

getY

public float getY()
Description copied from interface: ROVector2
Get the Y component of this vector

Specified by:
getY in interface ROVector2
Returns:
The Y component of this vector
See Also:
ROVector2.getY()

set

public void set(ROVector2 other)
Set the value of this vector

Parameters:
other - The values to set into the vector

dot

public float dot(ROVector2 other)
Description copied from interface: ROVector2
Get the dot product of this vector and another

Specified by:
dot in interface ROVector2
Parameters:
other - The other vector to dot against
Returns:
The dot product of the two vectors
See Also:
ROVector2.dot(ROVector2)

set

public void set(float x,
                float y)
Set the values in this vector

Parameters:
x - The x component to set
y - The y component to set

negate

public Vector2 negate()
Negate this vector

Returns:
A copy of this vector negated

add

public void add(ROVector2 v)
Add a vector to this vector

Parameters:
v - The vector to add

sub

public void sub(ROVector2 v)
Subtract a vector from this vector

Parameters:
v - The vector subtract

scale

public void scale(float a)
Scale this vector by a value

Parameters:
a - The value to scale this vector by

normalise

public void normalise()
Normalise the vector


lengthSquared

public float lengthSquared()
The length of the vector squared

Specified by:
lengthSquared in interface ROVector2
Returns:
The length of the vector squared

length

public float length()
Description copied from interface: ROVector2
Get the length of this vector

Specified by:
length in interface ROVector2
Returns:
The length of this vector
See Also:
ROVector2.length()

projectOntoUnit

public void projectOntoUnit(ROVector2 b,
                            Vector2 result)
Project this vector onto another

Specified by:
projectOntoUnit in interface ROVector2
Parameters:
b - The vector to project onto
result - The projected vector

toString

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

distance

public float distance(ROVector2 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

equalsDelta

public boolean equalsDelta(ROVector2 other,
                           float delta)
Compare two vectors allowing for a (small) error as indicated by the delta. Note that the delta is used for the vector's components separately, i.e. any other vector that is contained in the square box with sides 2*delta and this vector at the center is considered equal.

Parameters:
other - The other vector to compare this one to
delta - The allowed error
Returns:
True iff this vector is equal to other, with a tolerance defined by delta

perp

public void perp(Vector2 passback)
returns (in the passback) a perpendicular vector. Turns this vector clockwise so y becomes the x and the x becomes -y

Parameters:
passback -