game.physics
Class GeneralPhysics

java.lang.Object
  extended bygame.physics.GeneralPhysics

public final class GeneralPhysics
extends java.lang.Object

A class that defines vector operations and other mathematical/physical computations.


Constructor Summary
GeneralPhysics()
           
 
Method Summary
static double determinant(double a, double b, double c, double d)
          Returns the determinant of a 2x2 matrix of [ (a,b) (c,d) ].
static double distancePointLine(Vector2D point, Vector2D i, Vector2D j)
          Returns the minimum distance between a specified point and a line defined by i and j using the formula at http://astronomy.swin.edu.au/pbourke/geometry/pointline/ .
static void getFuturePosition(Vector2D position, double direction, Vector2D futurePosition)
          Sets a point to 1 unit in a direction from another point.
static void getPointLineLineIntersection(Vector2D a, Vector2D b, Vector2D c, Vector2D d, Vector2D result)
          Sets a point to the intersection of two lines defined by two vectors each.
static boolean isGreaterDistanceToIntersection(Vector2D positionA, double directionA, Vector2D positionB, double directionB)
          Returns whether a vector moving in a direction is closer to its point of intersection with another vector moving in another direction than that vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GeneralPhysics

public GeneralPhysics()
Method Detail

distancePointLine

public static double distancePointLine(Vector2D point,
                                       Vector2D i,
                                       Vector2D j)
Returns the minimum distance between a specified point and a line defined by i and j using the formula at http://astronomy.swin.edu.au/pbourke/geometry/pointline/ .

Parameters:
point - the specified point off the line
i - a point on the line
j - a point on the line
Returns:
the distance between the point and the line

getPointLineLineIntersection

public static void getPointLineLineIntersection(Vector2D a,
                                                Vector2D b,
                                                Vector2D c,
                                                Vector2D d,
                                                Vector2D result)
Sets a point to the intersection of two lines defined by two vectors each.

Parameters:
a - a point on line 1
b - a point on line 1
c - a point on line 2
d - a point on line 2
result - the point of intersection

determinant

public static double determinant(double a,
                                 double b,
                                 double c,
                                 double d)
Returns the determinant of a 2x2 matrix of [ (a,b) (c,d) ].

Parameters:
a - the element at row 1, column 1
b - the element at row 1, column 2
c - the element at row 2, column 1
d - the element at row 2, column 2
Returns:
the determinant of that matrix

isGreaterDistanceToIntersection

public static boolean isGreaterDistanceToIntersection(Vector2D positionA,
                                                      double directionA,
                                                      Vector2D positionB,
                                                      double directionB)
Returns whether a vector moving in a direction is closer to its point of intersection with another vector moving in another direction than that vector.

Parameters:
positionA - position 1
directionA - direction 1
positionB - position 2
directionB - direction 2
Returns:
true if position 1 is closer to the point of intersection than position 2
false otherwise

getFuturePosition

public static void getFuturePosition(Vector2D position,
                                     double direction,
                                     Vector2D futurePosition)
Sets a point to 1 unit in a direction from another point.

Parameters:
position - the original position
direction - the direction of offset
futurePosition - the new position
See Also:
MovingBody#dir