## net.rim.device.api.math Class VecMath

java.lang.Object
net.rim.device.api.math.VecMath

public final class VecMath
extends Object

Implementations of a stack for use in matrix multiplication. Does matrix multiplication on 3x3 matrices.

NOTE: All matrix elements must be Fixed32 integers, that is, 32-bit ints that use the 16.16 convention to fix the decimal point. Use Fixed32.toFP(int) and Fixed32.toInt(int) to convert between normal integers and Fixed32 integers.

Since:
BlackBerry API 4.0.0

Field Summary
static int[] IDENTITY_3X3
3 x 3 identity matrix.

Method Summary
static boolean intersects(int ax0, int ay0, int ax1, int ay1, int bx0, int by0, int bx1, int by1)
Does line segment A intersection line segment B?
static boolean isIdentity(int[] source, int index)
Determines if this matrix is the indentity matrix.
static boolean isTranslation(int[] source, int index)
Determine if the matrix represented by the integer array is a translation.
static void multiply3x3(int[] a, int aStartIndex, int[] b, int bStartIndex)
Deprecated. use multiply3x3(int[],int,int[],int,int[],int) and pass B as the destination matrix.
static void multiply3x3(int[] a, int aStartIndex, int[] b, int bStartIndex, int[] dest, int destStartIndex)
Multiplies 2 3x3 matrices (A x B).
static void multiply3x3Affine(int[] a, int aStartIndex, int[] b, int bStartIndex, int[] dest, int destStartIndex)
Multiplies 2 affine 3x3 matrices (A x B).
static long multiplyPoint(int[] matrix, int pos, int x, int y)
Multiplies a given (x, y) point by a given matrix, and returns the result as a long number: the first 32 bits represent the resulting x-coordinate, and the second 32 bits represent the resulting y-coordinate So, resultX = (int) result resultY = (int) (result >>> 32) This method does the same as VecMath.pointMultiply3x3(int[], int, int, int, int[], int), but it does not require an array to store the return values.
static void pointMultiply3x3(int[] a, int aStartIndex, int x, int y, int[] dest, int destStartIndex)
Multiplies a given x,y point by a given 3x3 matrix.
static void transformPoints(int[] matrix, int matrixOffset, int[] coordsX, int[] coordsY, int[] destX, int[] destY)
Transforms an array of x,y coordinates represented by normal integers.
static void transformPoints32(int[] matrix, int matrixOffset, int[] coordsX, int[] coordsY, int[] destX, int[] destY)
Transforms an array of x,y coordinates represented by Fixed32 integers.
static void transformPoints32(int[] matrix, int matrixOffset, int[] coordsX, int[] coordsY, int[] destX, int[] destY, int length)
Transforms an array of x,y coordinates represented by Fixed32 integers.

Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail

### IDENTITY_3X3

public static final int[] IDENTITY_3X3
3 x 3 identity matrix.

Since:
BlackBerry API 4.0.0

Method Detail

### multiplyPoint

public static long multiplyPoint(int[] matrix,
int pos,
int x,
int y)
Multiplies a given (x, y) point by a given matrix, and returns the result as a long number: the first 32 bits represent the resulting x-coordinate, and the second 32 bits represent the resulting y-coordinate So, resultX = (int) result resultY = (int) (result >>> 32)

This method does the same as VecMath.pointMultiply3x3(int[], int, int, int, int[], int), but it does not require an array to store the return values.

Parameters:
matrix - the array containing the matrix to multiply.
pos - the index in a where the matrix begins.
x - the x coordinate (in Fixed 32 notation).
y - the y coordinate (in Fixed 32 notation).
Returns:
the long number representing the resulting (x, y) point.
Since:
BlackBerry API 4.0.0

### transformPoints

public static void transformPoints(int[] matrix,
int matrixOffset,
int[] coordsX,
int[] coordsY,
int[] destX,
int[] destY)
Transforms an array of x,y coordinates represented by normal integers.

Parameters:
matrix - The transformation matrix used to transform the input coordinates. The matrix elements are in fixed-32 (15.16) format.
matrixoffset - The offset to the first point to be transformed in the matrix array.
coordsX - An array containing normal integers that represent the x coordinates to be transformed.
coordsY - An array containing normal integers that represent the Y coordinates to be transformed.
destX - The array into which the transformed x coordinates are returned as normal integers.
destY - The array into which the transformed y coordinates are returned as normal integers.
Since:
BlackBerry API 4.0.0

### transformPoints32

public static void transformPoints32(int[] matrix,
int matrixOffset,
int[] coordsX,
int[] coordsY,
int[] destX,
int[] destY)
Transforms an array of x,y coordinates represented by Fixed32 integers.

Parameters:
matrix - The transformation matrix used to transform the input coordinates. The matrix elements are in fixed-32 (15.16) format.
matrixoffset - The offset to the first point to be transformed in the matrix array.
coordsX - An array containing normal integers that represent the x coordinates to be transformed.
coordsY - An array containing normal integers that represent the Y coordinates to be transformed.
destX - The array into which the transformed x coordinates are returned as normal integers.
destY - The array into which the transformed y coordinates are returned as normal integers.
Since:
BlackBerry API 4.0.2

### transformPoints32

public static void transformPoints32(int[] matrix,
int matrixOffset,
int[] coordsX,
int[] coordsY,
int[] destX,
int[] destY,
int length)
Transforms an array of x,y coordinates represented by Fixed32 integers.

Parameters:
matrix - The transformation matrix used to transform the input coordinates. The matrix elements are in fixed-32 (15.16) format.
matrixoffset - The offset to the first point to be transformed in the matrix array.
coordsX - An array containing normal integers that represent the x coordinates to be transformed.
coordsY - An array containing normal integers that represent the Y coordinates to be transformed.
destX - The array into which the transformed x coordinates are returned as normal integers.
destY - The array into which the transformed y coordinates are returned as normal integers.
length - If length is -1, then all the values in the input arrays are processed; otherwise, the first length values in the input arrays are processed.
Since:
BlackBerry API 4.0.2

### isIdentity

public static final boolean isIdentity(int[] source,
int index)
Determines if this matrix is the indentity matrix.

Parameters:
source - Integer array containing the matrix.
index - Offset inside the matrix
Returns:
True if it is the identity.
Since:
BlackBerry API 4.0.0

### isTranslation

public static final boolean isTranslation(int[] source,
int index)
Determine if the matrix represented by the integer array is a translation.

Parameters:
source - Integer array containing the matrix.
index - Offset inside the matrix
Returns:
True if the matrix is a translation, otherwise false.
Since:
BlackBerry API 4.1.0

### intersects

public static boolean intersects(int ax0,
int ay0,
int ax1,
int ay1,
int bx0,
int by0,
int bx1,
int by1)
Does line segment A intersection line segment B? It receives the x and y coordinates of every line segment This method assumes integer parameters ONLY (non-fixed32). Passing fixed32 values to this method could cause overflow.

Returns:
True is the line intersect.
Since:
BlackBerry API 4.0.0

### multiply3x3

public static void multiply3x3(int[] a,
int aStartIndex,
int[] b,
int bStartIndex)
Deprecated. use multiply3x3(int[],int,int[],int,int[],int) and pass B as the destination matrix.

Multiplies 2 3x3 matrices (A x B). The result overwrites the second matrix (B). Please note, no bounds checks are made by this method. It assumes that the arrays are non-null and contain enough values for a 3x3 matrix.

Parameters:
a - the array containing matrix A
aStartIndex - the index of the start of matrix A
b - the array containing matrix B
bStartIndex - the index of the start of matrix B
Since:
BlackBerry API 4.0.0

### multiply3x3

public static void multiply3x3(int[] a,
int aStartIndex,
int[] b,
int bStartIndex,
int[] dest,
int destStartIndex)
Multiplies 2 3x3 matrices (A x B). The result is stored in the specified destination array. Please note, no bounds checks are made by this method. It assumes that the arrays are non-null and contain enough values/space for a 3x3 matrix. If A or B would be overwritten by the operation, A or B is first copied to a temporary array before the calculation.

Parameters:
a - the array containing matrix A
aStartIndex - the index of the start of matrix A
b - the array containing matrix B
bStartIndex - the index of the start of matrix B
dest - the array to store the result of the multiplication
destStartIndex - the index at which to store the first value in the matrix.
Since:
BlackBerry API 4.0.0

### multiply3x3Affine

public static void multiply3x3Affine(int[] a,
int aStartIndex,
int[] b,
int bStartIndex,
int[] dest,
int destStartIndex)
Multiplies 2 affine 3x3 matrices (A x B). An affine matrix has the following form:
A C E
B D F
0 0 1

The result is stored in the specified destination array. Please note, no bounds checks are made by this method. It assumes that the arrays are non-null and contain enough values/space for a 3x3 matrix. Also this method is optimized for affine matrices. Using it with non-affine matrices give incorrect and undefined behavior.

Parameters:
a - the array containing matrix A
aStartIndex - the index of the start of matrix A
b - the array containing matrix B
bStartIndex - the index of the start of matrix B
dest - the array to store the result of the multiplication
destStartIndex - the index at which to store the first value in the matrix.
Since:
BlackBerry API 4.0.0

### pointMultiply3x3

public static void pointMultiply3x3(int[] a,
int aStartIndex,
int x,
int y,
int[] dest,
int destStartIndex)
Multiplies a given x,y point by a given 3x3 matrix. (A x P) The resulting x point is stored at dest[destStartIndex] and the resulting y point is stored at dest[destStartIndex + 1]. It is assumed that the arrays are of sufficient length.

Parameters:
a - the array containing the matrix to multiply.
aStartIndex - the index in a where the matrix begins.
x - the x coordinate (in Fixed 32 notation).
y - the y coordinate (in Fixed 32 notation).
dest - the array in which to store the results.
destStartOffset - the index in dest where the results should be stored.
Since:
BlackBerry API 4.0.0