RoboJDETM v2.0

com.ridgesoft.robotics
Class Vector2D

java.lang.Object
  extended by com.ridgesoft.robotics.Vector2D

public class Vector2D
extends Object

Implements a two dimensional (magnitude and direction) vector for physics calculations and provides a method for summing vectors.


Constructor Summary
Vector2D(float magnitude, float directionDegrees)
          Constructs a Vector2D object.
Vector2D(Vector2D[] vectors)
          Constructs a Vector2D object that is the sum of a set of vectors.
 
Method Summary
 Vector2D add(Vector2D vector)
          Adds a vector to this vector and returns a new Vector2D object containing the result.
 float getDirection()
          Gets the direction of the vector.
 float getMagnitude()
          Gets the magnitude of the vector.
 void setDirection(float directionDegrees)
          Sets the direction component of the vector.
 void setMagnitude(float magnitude)
          Sets the magnitude of the vector.
 String toString()
          Returns a String object containing the magnitude and direction (in degrees) of the vector in the format: magnitude, direction
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait
 

Constructor Detail

Vector2D

public Vector2D(float magnitude,
                float directionDegrees)
Constructs a Vector2D object.

Parameters:
magnitude - magnitude of the vector
directionDegrees - direction of the vector in degrees

Vector2D

public Vector2D(Vector2D[] vectors)
Constructs a Vector2D object that is the sum of a set of vectors.

Parameters:
vectors - the vectors to sum when constructing the new vector
Method Detail

add

public Vector2D add(Vector2D vector)
Adds a vector to this vector and returns a new Vector2D object containing the result.

Parameters:
vector - vector to add to this vector
Returns:
Vector2D object containing the result of the addition

getDirection

public float getDirection()
Gets the direction of the vector.

Returns:
direction in degrees

getMagnitude

public float getMagnitude()
Gets the magnitude of the vector.

Returns:
magnitude of the vector in user defined units

setDirection

public void setDirection(float directionDegrees)
Sets the direction component of the vector.

Parameters:
directionDegrees - direction in degrees

setMagnitude

public void setMagnitude(float magnitude)
Sets the magnitude of the vector.

Parameters:
magnitude - vector magnitude in user defined units

toString

public String toString()
Returns a String object containing the magnitude and direction (in degrees) of the vector in the format: magnitude, direction

Overrides:
toString in class Object
Returns:
String representation of the vector

RoboJDETM v2.0

Copyright (c) 2003-2009 RidgeSoft, LLC. All rights reserved.
www.ridgesoft.com