cs015.Swarm
Class Vector

java.lang.Object
  extended bycs015.Swarm.Vector

public class Vector
extends java.lang.Object


Constructor Summary
Vector()
          This constructor initializes the vector.
Vector(int angle, double vel)
          This constructor initializes the vector with given orientation and velocity.
 
Method Summary
 Vector add(Vector v)
          This method returns a new vector which is the sum of this vector and the parameter
 Vector copy()
          This method will return a copy of the current Vector, or in other words, another vector is made with the same orientation and speed and the new reference is returned.
 Vector createDirectionallyConstrainedVector(java.awt.Point source, java.awt.Point target)
          This method will return a new vector with current speed and direction towards a specific point on the screen, within a limit So a vector pointing away from the target point will not turn all the way towards the target but just a little bit towards the target.
 Vector createRandomlyConstrainedVector()
          This method will return a new vector with changed direction and speed by a random amount within a limit set by your TAs.
 int getRotation()
          This method will return the current rotation of the vector, or in other words, it will return the angle of the vector between it an the positive x axis.
 double getVelocity()
          This method will return the current velocity of the vector, or in other words, it will return the length of the vector.
 java.awt.Point movePositionAlong(java.awt.Point location)
          This method returns a new java.awt.Point based on the parameter location.
 void rotate(int angle)
           
 void setRotation(int angle)
          This method will set the current rotation of the vector, or in other words, it will set the angle of the vector between it an the positive x axis without modifing the vector's velocity.
 void setVelocity(double vel)
          This method will set the current velocity of the vector, or in other words, it will set the length of the vector without changing the rotation (or direction) of the vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Vector

public Vector()
This constructor initializes the vector. It takes no arguments. It set up the vector with the default angle of 0 degrees, and with the default velocity of 0.


Vector

public Vector(int angle,
              double vel)
This constructor initializes the vector with given orientation and velocity.

Parameters:
angle - the rotation angle
vel - the velocity
Method Detail

add

public Vector add(Vector v)
This method returns a new vector which is the sum of this vector and the parameter

Parameters:
v - vector to add to the current vector

movePositionAlong

public java.awt.Point movePositionAlong(java.awt.Point location)
This method returns a new java.awt.Point based on the parameter location. The new value is one determined by moving the point along the direction of the vector according to the speed of the vector.

Parameters:
location - The current source of the vector.

createRandomlyConstrainedVector

public Vector createRandomlyConstrainedVector()
This method will return a new vector with changed direction and speed by a random amount within a limit set by your TAs.


createDirectionallyConstrainedVector

public Vector createDirectionallyConstrainedVector(java.awt.Point source,
                                                   java.awt.Point target)
This method will return a new vector with current speed and direction towards a specific point on the screen, within a limit So a vector pointing away from the target point will not turn all the way towards the target but just a little bit towards the target.

Parameters:
source - The vector's point of origin
target - The position the vector turns towards.

getVelocity

public double getVelocity()
This method will return the current velocity of the vector, or in other words, it will return the length of the vector.


setVelocity

public void setVelocity(double vel)
This method will set the current velocity of the vector, or in other words, it will set the length of the vector without changing the rotation (or direction) of the vector.

Parameters:
vel - The vector's new velocity

getRotation

public int getRotation()
This method will return the current rotation of the vector, or in other words, it will return the angle of the vector between it an the positive x axis. Remember that the positive y axis points down, not up.


setRotation

public void setRotation(int angle)
This method will set the current rotation of the vector, or in other words, it will set the angle of the vector between it an the positive x axis without modifing the vector's velocity. Remember that the positive y axis points down, not up.

Parameters:
angle - The new orientation angle of the vector (in degrees)

rotate

public void rotate(int angle)

copy

public Vector copy()
This method will return a copy of the current Vector, or in other words, another vector is made with the same orientation and speed and the new reference is returned.