org.kabeja.math
Class MathUtils

java.lang.Object
  extended by org.kabeja.math.MathUtils

public class MathUtils
extends java.lang.Object

Author:
Field Summary
static double DISTANCE_DELTA
           
 
Constructor Summary
MathUtils()
           
 
Method Summary
static double absoluteValue(Vector v)
          Returns the absalute value (or length) of the vector
static Vector addVectorToVector(Vector a, Vector b)
           
static Vector crossProduct(Vector a, Vector b)
          Calculate the cross product of 2 vectors.
static double distance(Point start, Point end)
           
static double getAngle(Vector a, Vector b)
          Calculate the angle between vector a vector b
static double getDirectionAngle(Vector v)
          Returns the angle of the vector again the x-axis
static Point getIntersection(Point a, Vector u, Point b, Vector v)
           
static Point getPointOfStraightLine(Point a, Vector direction, double parameter)
          Calculate a point of a straigt line.
static int getQuadrant(double angle)
          Returns the qaudrant for the given angle:
0,1,2 or 3
static int getQuadrant(Point p, Point center)
          Returns the qaudrant:
0,1,2 or 3
static Vector getVector(Point a, Point b)
          Calculate the vector from point a to point b
static Vector invertDirection(Vector v)
          Invert the direction of the given vector
static double[][] multiplyMatrixByMatrix(double[][] a, double[][] b)
           
static double[] multiplyMatrixByVector(double[][] a, double[] v)
           
static Vector normalize(Vector v)
           
static Point rotatePointXY(Point p, Point center, double angle)
          Rotate the given point around centerpoint with the given angle in X-Y plane.
static double scalarProduct(Vector a, Vector b)
          Calculate the scalar product of vector a and vector b
static Vector scaleVector(Vector a, double scale)
          Scale a vector with the given value
static Vector subtractVectorByVector(Vector a, Vector b)
          Substracts a vector from other vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DISTANCE_DELTA

public static final double DISTANCE_DELTA
See Also:
Constant Field Values
Constructor Detail

MathUtils

public MathUtils()
Method Detail

scalarProduct

public static double scalarProduct(Vector a,
                                   Vector b)
Calculate the scalar product of vector a and vector b

Parameters:
a -
b -
Returns:
the result of the scalar product

absoluteValue

public static double absoluteValue(Vector v)
Returns the absalute value (or length) of the vector

Parameters:
v -
Returns:

crossProduct

public static Vector crossProduct(Vector a,
                                  Vector b)
Calculate the cross product of 2 vectors.

Parameters:
a -
b -
Returns:
a new vector as result of the cross product of a and b

scaleVector

public static Vector scaleVector(Vector a,
                                 double scale)
Scale a vector with the given value

Parameters:
a - the vector
scale - the value to scale
Returns:
a new vector scaled with the given

getPointOfStraightLine

public static Point getPointOfStraightLine(Point a,
                                           Vector direction,
                                           double parameter)
Calculate a point of a straigt line.

Parameters:
a - the startpoint of the straight line
direction - the direction vector of the straight line
parameter - the parameter
Returns:
a new point

getVector

public static Vector getVector(Point a,
                               Point b)
Calculate the vector from point a to point b

Parameters:
a -
b -
Returns:
the vector from a to b

getIntersection

public static Point getIntersection(Point a,
                                    Vector u,
                                    Point b,
                                    Vector v)

distance

public static double distance(Point start,
                              Point end)

getAngle

public static double getAngle(Vector a,
                              Vector b)
Calculate the angle between vector a vector b

Parameters:
a -
b -
Returns:
the angle in radian

rotatePointXY

public static Point rotatePointXY(Point p,
                                  Point center,
                                  double angle)
Rotate the given point around centerpoint with the given angle in X-Y plane.

Parameters:
p - the point to rotate
center - the centerpoint
angle - in radian
Returns:
the rotated point

normalize

public static Vector normalize(Vector v)

getQuadrant

public static int getQuadrant(Point p,
                              Point center)
Returns the qaudrant:
0,1,2 or 3

Parameters:
p -
center -
Returns:

getQuadrant

public static int getQuadrant(double angle)
Returns the qaudrant for the given angle:
0,1,2 or 3

Parameters:
angle - in degree
Returns:
the quadrant

getDirectionAngle

public static double getDirectionAngle(Vector v)
Returns the angle of the vector again the x-axis

Parameters:
v - the vector
Returns:
the angle in degree

invertDirection

public static Vector invertDirection(Vector v)
Invert the direction of the given vector

Parameters:
the - vector to invert
Returns:
new inverted vector

multiplyMatrixByMatrix

public static double[][] multiplyMatrixByMatrix(double[][] a,
                                                double[][] b)
                                         throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

multiplyMatrixByVector

public static double[] multiplyMatrixByVector(double[][] a,
                                              double[] v)
                                       throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

subtractVectorByVector

public static Vector subtractVectorByVector(Vector a,
                                            Vector b)
Substracts a vector from other vector.

Parameters:
a - the minuend
b - the subtrahend
Returns:
the difference as vector

addVectorToVector

public static Vector addVectorToVector(Vector a,
                                       Vector b)