net.clackrouter.jgraph.utils
Class MathExtensions

java.lang.Object
  extended by net.clackrouter.jgraph.utils.MathExtensions

public abstract class MathExtensions
extends java.lang.Object


Constructor Summary
MathExtensions()
           
 
Method Summary
static double abs(double x, double y)
          Computes the absolute value of a Vector, running from the Point (0;0) to the Point (x;y).
static double abs(java.awt.geom.Point2D.Double v)
          Computes the absolute value of v.
static double angleBetween(java.awt.geom.Point2D.Double v1, java.awt.geom.Point2D.Double v2)
          Calculates the angle between v1 and v2.
static double getEuclideanDistance(java.awt.geom.Point2D.Double p1, java.awt.geom.Point2D.Double p2)
          Returns the euclidean Distance between two Points in a 2D cartesian coordinate system.
static java.awt.geom.Point2D.Double getNormalizedVector(java.awt.geom.Point2D.Double v)
           
static double getTransposed(java.awt.geom.Point2D.Double v1, java.awt.geom.Point2D.Double v2)
          Calculates the Transposed of v1 and v2.
static double sgn(double x)
          Extracts the leading sign of x.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MathExtensions

public MathExtensions()
Method Detail

sgn

public static double sgn(double x)
Extracts the leading sign of x.

Parameters:
x - Any double value.
Returns:
If x has a positive value -1.0, for x = 0.0 here comes 0.0 and if x has a negative the method returns -1.0.

abs

public static double abs(java.awt.geom.Point2D.Double v)
Computes the absolute value of v. Assuming v is a mathematical Vector, pointing from Point Zero to the Point, represented by x and y in v, then this method returns the length of v.

return sqrt( v.x? + v.y? )

Parameters:
v - Point the Vector is pointing at, coming from the point (0;0).
Returns:
Length of the mathematical Vector v, computed by Pytagoras's theorem.

abs

public static double abs(double x,
                         double y)
Computes the absolute value of a Vector, running from the Point (0;0) to the Point (x;y). This is the length of that Vector.

return sqrt( v.x? + v.y? )

Parameters:
x - Length of one Karthese. Between x and y is an Angle of 90?
y - Length of the other Karthese. Between x and y is an Angle of 90?
Returns:
Length of the Hypothenuse.

angleBetween

public static double angleBetween(java.awt.geom.Point2D.Double v1,
                                  java.awt.geom.Point2D.Double v2)
Calculates the angle between v1 and v2. Assuming that v1 and v2 are mathematical Vectors, leading from the Point (0;0) to their coordinates, the angle in (0;0) is calculated.

return arccos( ( v1.x*v2.x + v1.y*v2.y ) / ( sqrt( v1.x? + v1.y? ) * sqrt( v2.x? + v2.y? ) ) )

Parameters:
v1 - One of two Vectors leading from (0;0) to (v1.x;v1.y)
v2 - One of two Vectors leading from (0;0) to (v2.x;v2.y)
Returns:
The Angle between the two vectors

getTransposed

public static double getTransposed(java.awt.geom.Point2D.Double v1,
                                   java.awt.geom.Point2D.Double v2)
Calculates the Transposed of v1 and v2. It is assumed, that v1 and v2 are mathematical Vectors, leading from the Point (0;0) to their coordinates.

return v1.x * v2.x + v1.y * v2.y

Parameters:
v1 - Vector, leading from (0;0) to the coordinates of the point.
v2 - Vector, leading from (0;0) to the coordinates of the point.
Returns:
Transposed from v1 and v2.

getEuclideanDistance

public static double getEuclideanDistance(java.awt.geom.Point2D.Double p1,
                                          java.awt.geom.Point2D.Double p2)
Returns the euclidean Distance between two Points in a 2D cartesian coordinate system. The euclidean Distance is calculated in the following way:

sqrt( (p1.x - p2.x)? + (p1.y - p2.y)? )

Parameters:
p1 - First of two Points, the Distance should be calculated between.
p2 - Second of two Points, the Distance should be calculated between.
Returns:
Distance between p1 and p2, calculated in the euclidean way.

getNormalizedVector

public static java.awt.geom.Point2D.Double getNormalizedVector(java.awt.geom.Point2D.Double v)