jglcore
Class JGL_Math

java.lang.Object
  extended by jglcore.JGL_Math

public final class JGL_Math
extends java.lang.Object

Static class gathering mathematics functions (trigonometry, linear algebra).

Author:
Nicolas Devere

Field Summary
static float DEGREES_TO_RADIANS
          Degrees to radians conversion factor
static float epsilon
          Small value used for float comparisons
static float RADIANS_TO_DEGREES
          Radians to degrees conversion factor
 
Constructor Summary
JGL_Math()
           
 
Method Summary
static float cos(float angle)
          Returns the cosine of the specified angle.
static boolean plane_lineIntersection(JGL_3DPlane plane, JGL_3DVector p1, JGL_3DVector p2, JGL_3DVector result)
          Computes the intersection point between the specified plane and the line defined by the specified 2 vectors.
static float plane_segmentIntersection(JGL_3DPlane plane, JGL_3DVector p1, JGL_3DVector p2, float a, float b, JGL_3DVector result)
          Computes the intersection point between the specified plane and the segment defined by the specified 2 vectors.
static int plane_trianglePosition(JGL_3DPlane plane, JGL_3DTriangle triangle)
          Returns the specified face's position against the specified plane.
static float sin(float angle)
          Returns the sine of the specified angle.
static int triangle_split(JGL_3DTriangle triangle, JGL_3DPlane plane, JGL_3DTriangle result1, JGL_3DTriangle result2, JGL_3DTriangle result3)
          Splits the specified triangle by the specified plane.
static void vector_add(JGL_3DVector v1, JGL_3DVector v2, JGL_3DVector result)
          Computes the ( [v1] + [v2] ) addition.
static void vector_applyMatrix(JGL_3DVector vector, JGL_3DMatrix matrix, JGL_3DVector result)
          Computes ( [matrix] * [vector] ).
static void vector_crossProduct(JGL_3DVector v1, JGL_3DVector v2, JGL_3DVector result)
          Computes the ( [v1] * [v2] ) cross product .
static float vector_dotProduct(JGL_3DVector v1, JGL_3DVector v2)
          Returns the ( [v1] .
static void vector_fastYXrotate(float angleX, float angleY, JGL_3DVector result)
          Applies a rotation to a (0, 0, -1) vector with the specified angles around the Y axis, then the X axis.
static void vector_fastYXrotate(JGL_3DVector vector, float angleX, float angleY, JGL_3DVector result)
          Applies a rotation to the specified vector with the specified angles around the Y axis, then the X axis.
static void vector_interpolationCubic(JGL_3DVector v1, JGL_3DVector v2, JGL_3DVector v3, JGL_3DVector v4, float p, JGL_3DVector result)
          Computes the cubic interpolation between the 4 vectors according to the specified parametric variable.
static void vector_interpolationLinear(JGL_3DVector v1, JGL_3DVector v2, float p, JGL_3DVector result)
          Computes the linear interpolation between the 2 vectors according to the specified parametric variable.
static void vector_multiply(JGL_3DVector v, float factor, JGL_3DVector result)
          Computes the ( [v1] * [factor] ) multiplication.
static float vector_squareDistance(JGL_3DVector v1, JGL_3DVector v2)
          Returns the square of the distance between the 2 vectors.
static void vector_substract(JGL_3DVector v1, JGL_3DVector v2, JGL_3DVector result)
          Computes the ( [v1] - [v2] ) subtraction.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

epsilon

public static float epsilon
Small value used for float comparisons


DEGREES_TO_RADIANS

public static float DEGREES_TO_RADIANS
Degrees to radians conversion factor


RADIANS_TO_DEGREES

public static float RADIANS_TO_DEGREES
Radians to degrees conversion factor

Constructor Detail

JGL_Math

public JGL_Math()
Method Detail

sin

public static float sin(float angle)
Returns the sine of the specified angle. This one is in degrees and must be included between -360 and +360.

Parameters:
angle - : the angle in degrees
Returns:
the sine

cos

public static float cos(float angle)
Returns the cosine of the specified angle. This one is in degrees and must be included between -360 and +360.

Parameters:
angle - : the angle in degrees
Returns:
the cosine

vector_add

public static void vector_add(JGL_3DVector v1,
                              JGL_3DVector v2,
                              JGL_3DVector result)
Computes the ( [v1] + [v2] ) addition.

Parameters:
v1 - : the first vector
v2 - : the second vector
result - : the addition result

vector_substract

public static void vector_substract(JGL_3DVector v1,
                                    JGL_3DVector v2,
                                    JGL_3DVector result)
Computes the ( [v1] - [v2] ) subtraction.

Parameters:
v1 - : the first vector
v2 - : the second vector
result - : the subtraction result

vector_multiply

public static void vector_multiply(JGL_3DVector v,
                                   float factor,
                                   JGL_3DVector result)
Computes the ( [v1] * [factor] ) multiplication.

Parameters:
v - : the vector
factor - : the factor
result - : the multiplication result

vector_dotProduct

public static float vector_dotProduct(JGL_3DVector v1,
                                      JGL_3DVector v2)
Returns the ( [v1] . [v2] ) dot product .

Parameters:
v1 - : the first vector
v2 - : the second vector
Returns:
the dot product

vector_crossProduct

public static void vector_crossProduct(JGL_3DVector v1,
                                       JGL_3DVector v2,
                                       JGL_3DVector result)
Computes the ( [v1] * [v2] ) cross product .

Parameters:
v1 - : the first vector
v2 - : the second vector
result - : the cross product result

vector_squareDistance

public static float vector_squareDistance(JGL_3DVector v1,
                                          JGL_3DVector v2)
Returns the square of the distance between the 2 vectors.

Parameters:
v1 - : the first vector
v2 - : the second vector
Returns:
the square of the distance

vector_fastYXrotate

public static void vector_fastYXrotate(float angleX,
                                       float angleY,
                                       JGL_3DVector result)
Applies a rotation to a (0, 0, -1) vector with the specified angles around the Y axis, then the X axis.

Parameters:
angleX - : the X axis rotation angle
angleY - : the Y axis rotation angle
result - : the rotation result

vector_fastYXrotate

public static void vector_fastYXrotate(JGL_3DVector vector,
                                       float angleX,
                                       float angleY,
                                       JGL_3DVector result)
Applies a rotation to the specified vector with the specified angles around the Y axis, then the X axis.

Parameters:
vector - : the vector to rotate
angleX - : the X axis rotation angle
angleY - : the Y axis rotation angle
result - : the rotation result

vector_applyMatrix

public static void vector_applyMatrix(JGL_3DVector vector,
                                      JGL_3DMatrix matrix,
                                      JGL_3DVector result)
Computes ( [matrix] * [vector] ).

Parameters:
vector - : the vector
matrix - : the matrix
result - : the multiplication result

vector_interpolationLinear

public static void vector_interpolationLinear(JGL_3DVector v1,
                                              JGL_3DVector v2,
                                              float p,
                                              JGL_3DVector result)
Computes the linear interpolation between the 2 vectors according to the specified parametric variable.

Parameters:
v1 - : the first vector
v2 - : the second vector
p - : the parametric variable
result - : the interpolation result

vector_interpolationCubic

public static void vector_interpolationCubic(JGL_3DVector v1,
                                             JGL_3DVector v2,
                                             JGL_3DVector v3,
                                             JGL_3DVector v4,
                                             float p,
                                             JGL_3DVector result)
Computes the cubic interpolation between the 4 vectors according to the specified parametric variable.

Parameters:
v1 - : the first vector
v2 - : the second vector
v3 - : the third vector
v4 - : the fourth vector
p - : the parametric variable
result - : the interpolation result

plane_lineIntersection

public static boolean plane_lineIntersection(JGL_3DPlane plane,
                                             JGL_3DVector p1,
                                             JGL_3DVector p2,
                                             JGL_3DVector result)
Computes the intersection point between the specified plane and the line defined by the specified 2 vectors.
If there is no intersection, the result object is unchanged.

Parameters:
plane - : the plane
p1 - : the line first point
p2 - : the line second point
result - : the intersection result (unchanged if no intersection)
Returns:
true if intersection, false otherwise

plane_segmentIntersection

public static float plane_segmentIntersection(JGL_3DPlane plane,
                                              JGL_3DVector p1,
                                              JGL_3DVector p2,
                                              float a,
                                              float b,
                                              JGL_3DVector result)
Computes the intersection point between the specified plane and the segment defined by the specified 2 vectors.
If there is no intersection, the result object is unchanged.

Parameters:
plane - : the plane
p1 - : the line first point
p2 - : the line second point
a - : parametric variable for the segment first point (usually 0)
b - : parametric variable for the segment second point (usually 1)
result - : the intersection result (unchanged if no intersection)
Returns:
the intersection's parametric variable, or 99 if no intersection

plane_trianglePosition

public static int plane_trianglePosition(JGL_3DPlane plane,
                                         JGL_3DTriangle triangle)
Returns the specified face's position against the specified plane.
-1 : behind the plane
0 : across the plane
1 : before the plane
9 : inside the plane

Parameters:
plane - : the plane
triangle - : the triangle to test
Returns:
the triangle's position

triangle_split

public static int triangle_split(JGL_3DTriangle triangle,
                                 JGL_3DPlane plane,
                                 JGL_3DTriangle result1,
                                 JGL_3DTriangle result2,
                                 JGL_3DTriangle result3)
Splits the specified triangle by the specified plane. A split can produce 2 or 3 triangles, the method returns the number of split triangles.

Parameters:
triangle - : the triangle to split
plane - : the split plane
result1 - : the first split triangle
result2 - : the second split triangle
result3 - : the third split triangle
Returns:
the number of split triangles