rcssjava
Class VecPosition

java.lang.Object
  extended by rcssjava.VecPosition
All Implemented Interfaces:
java.io.Serializable

public class VecPosition
extends java.lang.Object
implements java.io.Serializable

Implementation of a 2d point/vector.

See Also:
Serialized Form

Constructor Summary
VecPosition()
          Default constructor sets point at origin
VecPosition(double vx, double vy)
          Cartesian constructor
VecPosition(double vx, double vy, boolean polar)
          Cartesian/Polar constructor
VecPosition(VecPosition p)
          Copy constructor
 
Method Summary
 VecPosition add(double d)
          Get new vector with a constant value added to each coordinate
 VecPosition add(VecPosition p)
          Sum of two vectors
 void copy(VecPosition p)
          Copy value of another VecPosition into this
 VecPosition divide(double d)
          Get new vector with each coordinate divided by a constant
 VecPosition divide(VecPosition p)
          Pairwise quotient of two vectors
 double dotProduct(VecPosition p)
          Dot (inner) product of two vectors
 double getAngleBetweenPoints(VecPosition p1, VecPosition p2)
          Get angle formed between the vectors connecting this point to the given points
 double getDirection()
          Get direction
 double getDistanceTo(VecPosition p)
          Get distanct to a given point
 double getMagnitude()
          Get magnitude
static VecPosition getVecPositionFromPolar(double mag, double angDeg)
          Convert from polar to cartesian coordinates
 double getX()
          Get x coordinate
 double getY()
          Get y coordinate
 VecPosition globalToRelative(VecPosition origin, double angDeg)
          Convert global coordinates to relative coordinates
 boolean isBehind(double d)
          Is this behind given x coordinate?
 boolean isBehind(VecPosition p)
          Is this behind given point?
 boolean isBetweenX(double d1, double d2)
          Is the x coordinate between the given x coordinates
 boolean isBetweenX(VecPosition p1, VecPosition p2)
          Is the x coordinate between the x coordinates of the given points?
 boolean isBetweenY(double d1, double d2)
          Is the y coordinate between the given y coordinates
 boolean isBetweenY(VecPosition p1, VecPosition p2)
          Is the y coordinate between the y coordinates of the given points?
 boolean isInFrontOf(double d)
          Is this in front of given x coordinate?
 boolean isInFrontOf(VecPosition p)
          Is this in front of given point?
 boolean isLeftOf(double d)
          Is this left of given y coordinate?
 boolean isLeftOf(VecPosition p)
          Is this left of given point?
 boolean isRightOf(double d)
          Is this right of given y coordinate?
 boolean isRightOf(VecPosition p)
          Is this right of given point?
 VecPosition multiply(double d)
          Get new vector with each coordinate muliplied by a constant
 VecPosition multiply(VecPosition p)
          Pairwise product of two vectors
 VecPosition negate()
          Get new vector which is the negation of this
 VecPosition normalize()
          Scale to magnitude 1.0
 VecPosition relativeToGlobal(VecPosition origin, double angDeg)
          Convert relative coordinates to global coordinates
 VecPosition rotate(double angDeg)
          Rotate by angle
 VecPosition subtract(double d)
          Get new vector with a constant value subtracted from each coordinate
 VecPosition subtract(VecPosition p)
          Difference of two vectors
 java.lang.String toString()
           
 VecPosition withMagnitude(double d)
          Scale to given magnitude
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VecPosition

public VecPosition()
Default constructor sets point at origin


VecPosition

public VecPosition(double vx,
                   double vy)
Cartesian constructor

Parameters:
vx - value of x coordinate
vy - value of y coordinate

VecPosition

public VecPosition(double vx,
                   double vy,
                   boolean polar)
Cartesian/Polar constructor

Parameters:
vx - x coordinate for cartesian, or magnitude for polar
vy - y coordinate for cartesian, or angle in degrees for polar
polar - set to true for polar interpretation of arguments
See Also:
getVecPositionFromPolar(double,double)

VecPosition

public VecPosition(VecPosition p)
Copy constructor

Parameters:
p - another VecPosition
Method Detail

copy

public void copy(VecPosition p)
Copy value of another VecPosition into this

Parameters:
p - another VecPosition

getX

public double getX()
Get x coordinate

Returns:
x coordinate

getY

public double getY()
Get y coordinate

Returns:
y coordinate

getMagnitude

public double getMagnitude()
Get magnitude

Returns:
euclidean length (L2 norm) of vector

getDirection

public double getDirection()
Get direction

Returns:
angle in degrees

getDistanceTo

public double getDistanceTo(VecPosition p)
Get distanct to a given point

Parameters:
p - another point
Returns:
euclidean distance to point

isInFrontOf

public boolean isInFrontOf(double d)
Is this in front of given x coordinate?

Parameters:
d - x coordinate
Returns:
true if this has a greater x coordinate

isInFrontOf

public boolean isInFrontOf(VecPosition p)
Is this in front of given point?

Parameters:
p - another point
Returns:
true if this has a greater x coordinate

isBehind

public boolean isBehind(double d)
Is this behind given x coordinate?

Parameters:
d - x coordinate
Returns:
true if this has a smaller x coordinate

isBehind

public boolean isBehind(VecPosition p)
Is this behind given point?

Parameters:
p - another point
Returns:
true if this has a smaller x coordinate

isLeftOf

public boolean isLeftOf(double d)
Is this left of given y coordinate?

Parameters:
d - y coordinate
Returns:
true if this has a smaller y coordinate

isLeftOf

public boolean isLeftOf(VecPosition p)
Is this left of given point?

Parameters:
p - another point
Returns:
true if this has a smaller y coordinate

isRightOf

public boolean isRightOf(double d)
Is this right of given y coordinate?

Parameters:
d - y coordinate
Returns:
true if this has a greater y coordinate

isRightOf

public boolean isRightOf(VecPosition p)
Is this right of given point?

Parameters:
p - another point
Returns:
true if this has a greater y coordinate

isBetweenX

public boolean isBetweenX(VecPosition p1,
                          VecPosition p2)
Is the x coordinate between the x coordinates of the given points?

Parameters:
p1 - back point
p2 - front point
Returns:
true if in front of back point and behind front point

isBetweenX

public boolean isBetweenX(double d1,
                          double d2)
Is the x coordinate between the given x coordinates

Parameters:
d1 - back x coordinate
d2 - front x coordinate
Returns:
true if in front of back coordinate and behind front coordinate

isBetweenY

public boolean isBetweenY(VecPosition p1,
                          VecPosition p2)
Is the y coordinate between the y coordinates of the given points?

Parameters:
p1 - left point
p2 - right point
Returns:
true if right of left point and left of right point

isBetweenY

public boolean isBetweenY(double d1,
                          double d2)
Is the y coordinate between the given y coordinates

Parameters:
d1 - left y coordinate
d2 - right y coordinate
Returns:
true if right of left coordinate and left of right coordinate

negate

public VecPosition negate()
Get new vector which is the negation of this

Returns:
new VecPosition with x and y negated

add

public VecPosition add(double d)
Get new vector with a constant value added to each coordinate

Parameters:
d - value to add to both x and y
Returns:
new VecPosition (x+d,y+d)

add

public VecPosition add(VecPosition p)
Sum of two vectors

Parameters:
p - another vector
Returns:
sum of this and given vector

subtract

public VecPosition subtract(double d)
Get new vector with a constant value subtracted from each coordinate

Parameters:
d - value to subtract from both x and y
Returns:
new VecPosition (x-d,y-d)

subtract

public VecPosition subtract(VecPosition p)
Difference of two vectors

Parameters:
p - another vector
Returns:
this minus given vector

multiply

public VecPosition multiply(double d)
Get new vector with each coordinate muliplied by a constant

Parameters:
d - value to multiply both x and y by
Returns:
new VecPosition (x*d,y*d)

multiply

public VecPosition multiply(VecPosition p)
Pairwise product of two vectors

Parameters:
p - another vector
Returns:
this times given vector, coordinate-by-coordinate
See Also:
dotProduct(VecPosition)

divide

public VecPosition divide(double d)
Get new vector with each coordinate divided by a constant

Parameters:
d - value to divide both x and y by
Returns:
new VecPosition (x/d,y/d)

divide

public VecPosition divide(VecPosition p)
Pairwise quotient of two vectors

Parameters:
p - another vector
Returns:
this divided by given vector, coordinate-by-coordinate

withMagnitude

public VecPosition withMagnitude(double d)
Scale to given magnitude

Parameters:
d - magnitude
Returns:
new VecPosition with given magnitude
See Also:
normalize()

normalize

public VecPosition normalize()
Scale to magnitude 1.0

Returns:
new VecPosition with magnitude 1.0
See Also:
withMagnitude(double)

rotate

public VecPosition rotate(double angDeg)
Rotate by angle

Parameters:
angDeg - angle in degrees
Returns:
new VecPosition rotated by given angle

globalToRelative

public VecPosition globalToRelative(VecPosition origin,
                                    double angDeg)
Convert global coordinates to relative coordinates

Parameters:
origin - position of relative coordinate system
angDeg - direction of relative coordinate system in degrees
Returns:
point in relative coordinates
See Also:
relativeToGlobal(VecPosition,double)

relativeToGlobal

public VecPosition relativeToGlobal(VecPosition origin,
                                    double angDeg)
Convert relative coordinates to global coordinates

Parameters:
origin - position of relative coordinate system
angDeg - direction of relative coordinate system in degrees
Returns:
point in global coordinates
See Also:
globalToRelative(VecPosition,double)

dotProduct

public double dotProduct(VecPosition p)
Dot (inner) product of two vectors

Parameters:
p - another vector
Returns:
dot product of this and given vector
See Also:
multiply(VecPosition)

getAngleBetweenPoints

public double getAngleBetweenPoints(VecPosition p1,
                                    VecPosition p2)
Get angle formed between the vectors connecting this point to the given points

Parameters:
p1 - first point
p2 - second point
Returns:
angle in degrees

toString

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

getVecPositionFromPolar

public static VecPosition getVecPositionFromPolar(double mag,
                                                  double angDeg)
Convert from polar to cartesian coordinates

Parameters:
mag - magnitude
angDeg - direction in degrees
Returns:
new VecPosition for the given values