Matrices

 

You can think of a matrix as an array of float arrays or as a two-dimensional array of floats. Unlike arrays, the size of a matrix cannot be altered after it has been created, and attempting to access matrix elements that do not exist will produce an error. The matrix size must be specified when it is created.

 

Examples

matrix $a1[][] = <<1; 4>>; // ERROR: Size not specified

matrix $a2[][]; // ERROR: Size not specified

matrix $a3[2][1]; // VALID: Creates <<0; 0>>;

$a3[0][1] = 7; // ERROR: Element doesn't exist

$a3[1][0] = 9; // VALID

 

Originally, MAXScript supported only one form of Matrix value, the one used throughout the core of the software to represent transformations - matrix3, containing 4 Point3 vectors, with row4 being the translation part. matrix3 values require all 4 Point3 values to be provided when defining the value.

 

Later, the so-called BigMatrix was introduced which lets you construct MxN custom matrices.

 

Other then MEL, MAXScript allows for Arrays of Arrays (at any depth, including Arrays in Arrays in Arrays in Arrays and so on), so Matrix values were never used to store tables of values.

 

If a matrix is declared but not assigned a value, all of the elements in the matrix are assigned 0.

 

This is true for BigMatrix values in MAXScript - all elements are assigned 0 when the BigMatrix is declared.

 

Example

matrix $a4[2][4] = <<-3.4, 6, 201, 0.7; 4, 2, 9.3, 1001>>;

 

MAXScript Example

a4 =matrix3 [1,0,0] [0,1,0] [0,0,1] [128.5, 10.1, - 199]

 

To replicate the above MEL example, a BigMatrix would be required:

b4 = bigMatrix 2 4

b4[1][1] = -3.4; b4[1][2] = 6; b4[1][3] = 201; b4[1][4] = 0.7

b4[2][1] = 4; b4[2][2] = 2; b4[2][3] = 9.3; b4[2][4] = 1001

 

So working with BigMatrix in MXS is rather tedious, but in the case of matrix3 values, you can read and write whole rows directly, for example

a4 =matrix3 [1,0,0] [0,1,0] [0,0,1] [128.5, 10.1, - 199]

a4.row1 = [-3.4, 6, 201]

 

If you are thinking of a matrix as a two-dimensional array, the first index represents the row and the second index represents the column.

 

matrix $a4[2][4]

column 0

column 1

column 2

column 3

row 0

-3.4

6

201 

0.7

row 1

4

2

9.3

1001

 

 

If you are thinking of a matrix as an array of float arrays, the first index represents the float array and the second index represents the index in that float array.

 

matrix $a4[2][4]

index 0

index 1

index 2

index 3

float array 0

-3.4

6

201 

0.7

float array 1

4 

2

9.3

1001

 

 

Both matrix3 and BigMatrix values in MAXScript work the same way as in MEL, so you can say in the above cases:

 

a4[1] returns [1,0,0] before the assignment and [-3.4, 6, 201] after.

a4.row1 is another way to access the first row

 

a4[1][1] returns 1 before and -3.4 after the assignment

a4.row1[1] is the alternative way to access the first column of the first row

a4.row1.x is yet another way to say the same, as a maxtrix3 consists of Point3 vectors

 

b4[1] returns #(-3.4,6,201,0.7)

b4[1][1] returns -3.4