lt.monarch.math.geom
Class Vector2D

java.lang.Object
  extended by lt.monarch.math.geom.Vector2D

public class Vector2D
extends java.lang.Object

Mathematical vector object


Field Summary
Modifier and Type Field and Description
 double x1
           
 double x2
           
 double y1
           
 double y2
           
 
Constructor Summary
Constructor and Description
Vector2D(double x, double y)
          Vector constructor with only end coordinates.
Vector2D(double x1, double y1, double x2, double y2)
          Vector constructor
 
Method Summary
Modifier and Type Method and Description
 double angleWithVector(Vector2D vector)
          Calculates the angle with the other vector
 boolean equals(java.lang.Object obj)
          Checks if the two vectors are equal
 Point2D getMidPoint()
          Gets vector middle point
static Point2D getPerpendicular(Point2D vector)
          Calculates a perpendicular vector to one provided.
 double getX1()
          Gets 1st x coordinate
 double getX2()
          Gets 2nd x coordinate
 double getY1()
          Gets first y coordinate
 double getY2()
          Gets 2nd y coordinate
 double length()
          Calculates the length of the vector
static double side(Point2D lp1, Point2D lp2, Point2D p)
          Determines whether the specified point is above or under some line denoted by two points.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

x1

public double x1

x2

public double x2

y1

public double y1

y2

public double y2
Constructor Detail

Vector2D

public Vector2D(double x1,
                double y1,
                double x2,
                double y2)
Vector constructor

Parameters:
x1 - vector start x coordinate
y1 - vector start y coordinate
x2 - vector end x coordinate
y2 - vector end y coordinate

Vector2D

public Vector2D(double x,
                double y)
Vector constructor with only end coordinates. The start is (0,0) coordinates

Parameters:
x - vector end x coordinate
y - vector end y coordinate
Method Detail

length

public double length()
Calculates the length of the vector

Returns:
Length of the vector

angleWithVector

public double angleWithVector(Vector2D vector)
Calculates the angle with the other vector

Parameters:
vector - Vector
Returns:
Return angle in degrees

getMidPoint

public Point2D getMidPoint()
Gets vector middle point

Returns:
vector middle point

getY1

public double getY1()
Gets first y coordinate

Returns:
Returns the y1.

getY2

public double getY2()
Gets 2nd y coordinate

Returns:
Returns the y2.

getX1

public double getX1()
Gets 1st x coordinate

Returns:
Returns the x1.

getX2

public double getX2()
Gets 2nd x coordinate

Returns:
Returns the x2.

equals

public boolean equals(java.lang.Object obj)
Checks if the two vectors are equal

Overrides:
equals in class java.lang.Object
Parameters:
obj - object that has to be compared
Returns:
value showing if two vectors are equal

getPerpendicular

public static Point2D getPerpendicular(Point2D vector)
Calculates a perpendicular vector to one provided.

Parameters:
vector - - a vector
Returns:
- a vector perpendicular to one specified

side

public static double side(Point2D lp1,
                          Point2D lp2,
                          Point2D p)
Determines whether the specified point is above or under some line denoted by two points.

Parameters:
lp1 - - the first reference point of line
lp2 - - the second reference point of line
p - - the point to test
Returns:
- positive if the point is above the line, otherwise negative and zero if one is on the line