de.steeringbehaviors.simulation.renderer
Class Vector2d

java.lang.Object
  extended by de.steeringbehaviors.simulation.renderer.Vector2d

public class Vector2d
extends java.lang.Object

Implements a simple 2d vector class


Field Summary
protected  double m_x
          X member of vector
protected  double m_y
          Y member of vector
 
Constructor Summary
Vector2d()
          Construct zero length vector
Vector2d(double x, double y)
          Construct vector from x and y info
Vector2d(Point2d p)
          Construct vector from point
Vector2d(Vector2d v)
          Copyconstructor
 
Method Summary
 Vector2d add(Vector2d v)
          Add another vector to this vector
 double dot(Vector2d v)
          Calculates the dot product of this vector with the other vector
 double getX()
          Returns the x member
 double getY()
          Returns the y member
 double length()
          Returns the length of the vector
 double lengthSquared()
          Calculates the langth of the vector in squared space
 void normalize()
          Normalizes the vector
 void scale(double a)
          Scales the vector
 void setX(double x)
          Sets the x member
 void setY(double y)
          Sets the y member
 Vector2d sub(Vector2d v)
          Subtract a vector from this vector
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_x

protected double m_x
X member of vector


m_y

protected double m_y
Y member of vector

Constructor Detail

Vector2d

public Vector2d()
Construct zero length vector


Vector2d

public Vector2d(double x,
                double y)
Construct vector from x and y info

Parameters:
x - X member
y - Y member

Vector2d

public Vector2d(Vector2d v)
Copyconstructor

Parameters:
v - Vector to copy

Vector2d

public Vector2d(Point2d p)
Construct vector from point

Parameters:
p - The point
Method Detail

setX

public void setX(double x)
Sets the x member

Parameters:
x - The new x member value

setY

public void setY(double y)
Sets the y member

Parameters:
y - The new y member value

getX

public double getX()
Returns the x member

Returns:
X member

getY

public double getY()
Returns the y member

Returns:
Y member

add

public Vector2d add(Vector2d v)
Add another vector to this vector

Parameters:
v - The other vector
Returns:
New vector

sub

public Vector2d sub(Vector2d v)
Subtract a vector from this vector

Parameters:
v - The other vector
Returns:
The new vector

length

public double length()
Returns the length of the vector

Returns:
The length

lengthSquared

public double lengthSquared()
Calculates the langth of the vector in squared space

Returns:
Squared length of vector

scale

public void scale(double a)
Scales the vector

Parameters:
a - New scale

normalize

public void normalize()
Normalizes the vector


dot

public double dot(Vector2d v)
Calculates the dot product of this vector with the other vector

Parameters:
v - The other vector
Returns:
Dot product