net.java.dev.joode.util
Class Math2D

java.lang.Object
  extended by net.java.dev.joode.util.Math2D

public final class Math2D
extends java.lang.Object

Simple utility wrapping up a bunch of math operations so that the rest of the code doesn't have to look so cluttered.

Author:
Kevin Glass

Method Summary
static Matrix2 abs(Matrix2 A)
          Create the absolute version of a matrix
static Vector2 abs(Vector2 a)
          Make a vector absolute
static void add(float[] A, float[] B, float[] res)
           
static Matrix2 add(Matrix2 A, Matrix2 B)
          Add two matricies
static float clamp(float a, float low, float high)
          Clamp a value
static float cross(float[] A, float[] B)
           
static Vector2 cross(float s, Vector2 a)
          Find the cross product of a vector and a float
static Vector2 cross(Vector2 a, float s)
          Find the cross product of a vector and a float
static float cross(Vector2 a, Vector2 b)
          Find the cross product of two vectors
static float dot(float[] A, float[] B)
           
static Vector2 getNormal(ROVector2 x, ROVector2 y)
          Get the normal of a line x y (or edge).
static void mul(float[] A, float scalar)
           
static Matrix2 mul(Matrix2 A, Matrix2 B)
          Multiple two matricies
static Vector2 mul(Matrix2 A, ROVector2 v)
          Multiply a matrix by a vector
static float norm(float[] A)
           
static void normalize(float[] A)
           
static Vector2 scale(ROVector2 a, float scale)
          Scale a vector by a given value
static float sign(float x)
          Check the sign of a value
static void sub(float[] A, float[] B, float[] res)
           
static void sub(ROVector2 a, ROVector2 b, Vector2 passback)
          Subtract one vector from another
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

scale

public static Vector2 scale(ROVector2 a,
                            float scale)
Scale a vector by a given value

Parameters:
a - The vector to be scaled
scale - The amount to scale the vector by
Returns:
A newly created vector - a scaled version of the new vector

sub

public static void sub(ROVector2 a,
                       ROVector2 b,
                       Vector2 passback)
Subtract one vector from another

Parameters:
a - The vector to be subtracted from
b - The vector to subtract

sign

public static float sign(float x)
Check the sign of a value

Parameters:
x - The value to check
Returns:
-1.0f if negative, 1.0 if positive

mul

public static Vector2 mul(Matrix2 A,
                          ROVector2 v)
Multiply a matrix by a vector

Parameters:
A - The matrix to be multiplied
v - The vector to multiple by
Returns:
A newly created vector containing the resultant vector

mul

public static Matrix2 mul(Matrix2 A,
                          Matrix2 B)
Multiple two matricies

Parameters:
A - The first matrix
B - The second matrix
Returns:
A newly created matrix containing the result

abs

public static Matrix2 abs(Matrix2 A)
Create the absolute version of a matrix

Parameters:
A - The matrix to make absolute
Returns:
A newly created absolute matrix

abs

public static Vector2 abs(Vector2 a)
Make a vector absolute

Parameters:
a - The vector to make absolute
Returns:
A newly created result vector

add

public static Matrix2 add(Matrix2 A,
                          Matrix2 B)
Add two matricies

Parameters:
A - The first matrix
B - The second matrix
Returns:
A newly created matrix containing the result

cross

public static float cross(Vector2 a,
                          Vector2 b)
Find the cross product of two vectors

Parameters:
a - The first vector
b - The second vector
Returns:
The cross product of the two vectors

cross

public static Vector2 cross(float s,
                            Vector2 a)
Find the cross product of a vector and a float

Parameters:
s - The scalar float
a - The vector to fidn the cross of
Returns:
A newly created resultant vector

cross

public static Vector2 cross(Vector2 a,
                            float s)
Find the cross product of a vector and a float

Parameters:
s - The scalar float
a - The vector to fidn the cross of
Returns:
A newly created resultant vector

clamp

public static float clamp(float a,
                          float low,
                          float high)
Clamp a value

Parameters:
a - The original value
low - The lower bound
high - The upper bound
Returns:
The clamped value

getNormal

public static Vector2 getNormal(ROVector2 x,
                                ROVector2 y)
Get the normal of a line x y (or edge). When standing on x facing y, the normal will point to the left. TODO: move this function somewhere else?

Parameters:
x - startingpoint of the line
y - endpoint of the line
Returns:
a (normalised) normal

dot

public static float dot(float[] A,
                        float[] B)

cross

public static float cross(float[] A,
                          float[] B)

add

public static void add(float[] A,
                       float[] B,
                       float[] res)

sub

public static void sub(float[] A,
                       float[] B,
                       float[] res)

mul

public static void mul(float[] A,
                       float scalar)

norm

public static float norm(float[] A)

normalize

public static void normalize(float[] A)