edu.umd.cfar.lamp.viper.gui.canvas
Class MathVector

java.lang.Object
  extended byedu.umd.cfar.lamp.viper.gui.canvas.MathVector

public class MathVector
extends java.lang.Object

Author:
clin "width" is defined parallel to the angle "height is defined perpendicular to the angle

Constructor Summary
MathVector(double x, double y)
          Create a vector with magnitude sqrt(x^2 + y^2) in the direction of (0,0) to (x,y)
MathVector(java.awt.geom.Point2D first, java.awt.geom.Point2D second)
          Creates a vector in the direction of first to second, with magnitude equal to the distance between first and second
 
Method Summary
static MathVector addVector(MathVector v1, MathVector v2)
           
static java.awt.geom.Point2D addVectorToPoint(MathVector v, java.awt.geom.Point2D pt)
          Adds a vector to a point, to get a resulting point shifted by the vector
static double computeAngle(MathVector v)
           
static double computeAngle(java.awt.geom.Point2D firstPoint, java.awt.geom.Point2D secondPoint)
          (firstPoint, secondPoint) define a line This computes the angle of the line relative to the x-axis
static double computeHeight(MathVector vect, double angle)
          Computes the magnitude of vect perpendicular to direction of angle
static MathVector computeHeightVector(MathVector vect, double angle)
          Computes component of vect perpendicular to direction of angle
static MathVector computeUnitHeightVector(double angle)
          Computes a unit vector perpendicular to direction of angle
static MathVector computeUnitWidthVector(double angle)
          Computes a unit vector in the direction of angle
static double computeWidth(MathVector vect, double angle)
          Computes the magnitude of vect in the direction of angle
static MathVector computeWidthVector(MathVector vect, double angle)
          Computes component of vect in direction of angle
static double dotProduct(MathVector v1, MathVector v2)
          Computes the magnitude of the dot product
 double getLength()
          Computes magnitude of vector
 double getX()
           
 double getY()
           
static void main(java.lang.String[] args)
           
static java.awt.geom.Point2D offsetPointByHeight(java.awt.geom.Point2D refPt, MathVector v, double angle)
          Offsets refPt in the direction of angle, with the magnitude of v projected on the angle
static java.awt.geom.Point2D offsetPointByWidth(java.awt.geom.Point2D refPt, MathVector v, double angle)
          We have a point which we want to move along the line with angle, "angle" v is a vector, which is projected onto angle, and tells us how much to move at an angle.
static double projectUnit(MathVector vectSource, MathVector vectProject)
          Projects vectSource onto the normalized vectProject (i.e., a unit vector in the direction of vectProject)
 void setX(double xIn)
           
 void setY(double yIn)
           
static java.awt.geom.Line2D testLineByWidth(java.awt.geom.Point2D refPt, MathVector v, double angle)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MathVector

public MathVector(double x,
                  double y)
Create a vector with magnitude sqrt(x^2 + y^2) in the direction of (0,0) to (x,y)


MathVector

public MathVector(java.awt.geom.Point2D first,
                  java.awt.geom.Point2D second)
Creates a vector in the direction of first to second, with magnitude equal to the distance between first and second

Parameters:
first - tail of the vector
second - head of the vector
Method Detail

getX

public double getX()

setX

public void setX(double xIn)

getY

public double getY()

setY

public void setY(double yIn)

getLength

public double getLength()
Computes magnitude of vector


dotProduct

public static double dotProduct(MathVector v1,
                                MathVector v2)
Computes the magnitude of the dot product

Parameters:
v1 - The vector to be projected
v2 - The vector being projected on
Returns:
The magnitude of the dot product of v1 and v2

projectUnit

public static double projectUnit(MathVector vectSource,
                                 MathVector vectProject)
Projects vectSource onto the normalized vectProject (i.e., a unit vector in the direction of vectProject)

Parameters:
vectSource - The vector to be projected
vectProject - The vector being projected on
Returns:
The magnitude of the component of vectSource in the direction of vectProject

computeWidth

public static double computeWidth(MathVector vect,
                                  double angle)
Computes the magnitude of vect in the direction of angle

Parameters:
vect - The vector to project
angle - The angle of the unit vector to be projected on
Returns:
The component of vect in the direction of angle

computeHeight

public static double computeHeight(MathVector vect,
                                   double angle)
Computes the magnitude of vect perpendicular to direction of angle

Parameters:
vect - The vector to project
angle - The angle of the unit vector to be projected on, in radians
Returns:
The component of vect perpendicular direction of angle

computeUnitWidthVector

public static MathVector computeUnitWidthVector(double angle)
Computes a unit vector in the direction of angle

Parameters:
angle - In radians
Returns:
A unit vector in the direction of angle

computeUnitHeightVector

public static MathVector computeUnitHeightVector(double angle)
Computes a unit vector perpendicular to direction of angle

Parameters:
angle - In radians
Returns:
A unit vector perpendicular to direction of angle

computeWidthVector

public static MathVector computeWidthVector(MathVector vect,
                                            double angle)
Computes component of vect in direction of angle

Parameters:
vect - The vector to be projected
angle - The direction to be projected on, in radians
Returns:
A vector that represents the component of vect in the direction of angle.

computeHeightVector

public static MathVector computeHeightVector(MathVector vect,
                                             double angle)
Computes component of vect perpendicular to direction of angle

Parameters:
vect - The vector to be projected
angle - The direction to be projected on, in radians
Returns:
A vector that represents the component of vect perpendicular to direction of angle.

addVector

public static MathVector addVector(MathVector v1,
                                   MathVector v2)
Parameters:
v1 - First vector to be added
v2 - Second vector to be added
Returns:
Performs vector addition, resulting in a head to tail addition of v1 and v2

addVectorToPoint

public static java.awt.geom.Point2D addVectorToPoint(MathVector v,
                                                     java.awt.geom.Point2D pt)
Adds a vector to a point, to get a resulting point shifted by the vector

Parameters:
v - To "add" to the point
pt - The point to be added
Returns:
New point which is old point displaced by vector

offsetPointByWidth

public static java.awt.geom.Point2D offsetPointByWidth(java.awt.geom.Point2D refPt,
                                                       MathVector v,
                                                       double angle)
We have a point which we want to move along the line with angle, "angle" v is a vector, which is projected onto angle, and tells us how much to move at an angle. As an analogy, pretend a wind is blowing to the northeast, and there's a "train" on a track that's east-west. This is the component of the wind that pushes the train in the east direction

Parameters:
refPt - The point to be offset
v - The vector of movement
angle - The angle to project the vector on
Returns:
The offsetted point

testLineByWidth

public static java.awt.geom.Line2D testLineByWidth(java.awt.geom.Point2D refPt,
                                                   MathVector v,
                                                   double angle)

offsetPointByHeight

public static java.awt.geom.Point2D offsetPointByHeight(java.awt.geom.Point2D refPt,
                                                        MathVector v,
                                                        double angle)
Offsets refPt in the direction of angle, with the magnitude of v projected on the angle

Parameters:
refPt -
v -
angle -
Returns:

computeAngle

public static double computeAngle(java.awt.geom.Point2D firstPoint,
                                  java.awt.geom.Point2D secondPoint)
(firstPoint, secondPoint) define a line This computes the angle of the line relative to the x-axis

Parameters:
firstPoint -
secondPoint -
Returns:
angle in radians relative to x-axis: result from 0 up to 2 PI

computeAngle

public static double computeAngle(MathVector v)

toString

public java.lang.String toString()

main

public static void main(java.lang.String[] args)