net.phys2d.math
Class Vector2f

java.lang.Object
  extended bynet.phys2d.math.Vector2f
All Implemented Interfaces:
ROVector2f

public class Vector2f
extends java.lang.Object
implements ROVector2f

A two dimensional vector


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(float x, float y)
          Create a new vector
Vector2f(ROVector2f other)
          Create a new vector based on another
 
Method Summary
 void add(ROVector2f v)
          Add a vector to this vector
 float distance(ROVector2f other)
          Get the distance from this point to another
 float distanceSquared(ROVector2f other)
          Get the distance squared from this point to another
 float dot(ROVector2f other)
          Get the dot product of this vector and another
 boolean equalsDelta(ROVector2f 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
 Vector2f negate()
          Negate this vector
 void normalise()
          Normalise the vector
 void projectOntoUnit(ROVector2f b, Vector2f 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(ROVector2f other)
          Set the value of this vector
 void sub(ROVector2f 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

Vector2f

public Vector2f()
Create an empty vector


Vector2f

public Vector2f(ROVector2f 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

getX

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

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

getY

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

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

set

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

Parameters:
other - The values to set into the vector

dot

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

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

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 Vector2f negate()
Negate this vector

Returns:
A copy of this vector negated

add

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

Parameters:
v - The vector to add

sub

public void sub(ROVector2f 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 ROVector2f
Returns:
The length of the vector squared

length

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

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

projectOntoUnit

public void projectOntoUnit(ROVector2f b,
                            Vector2f result)
Project this vector onto another

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

toString

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

distance

public float distance(ROVector2f other)
Get the distance from this point to another

Specified by:
distance in interface ROVector2f
Parameters:
other - The other point we're measuring to
Returns:
The distance to the other point

distanceSquared

public float distanceSquared(ROVector2f other)
Get the distance squared from this point to another

Specified by:
distanceSquared in interface ROVector2f
Parameters:
other - The other point we're measuring to
Returns:
The distance to the other point

equalsDelta

public boolean equalsDelta(ROVector2f 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