multiply function

List<num> multiply(
  1. List<num> a,
  2. List<num> b
)

Takes two Matrix3s, a and b, and computes the product in the order that pre-composes b with a. In other words, the matrix returned will a A matrix. b A matrix.

Implementation

List<num> multiply(List<num> a, List<num> b) {
  final a00 = a[0 * 3 + 0];
  final a01 = a[0 * 3 + 1];
  final a02 = a[0 * 3 + 2];
  final a10 = a[1 * 3 + 0];
  final a11 = a[1 * 3 + 1];
  final a12 = a[1 * 3 + 2];
  final a20 = a[2 * 3 + 0];
  final a21 = a[2 * 3 + 1];
  final a22 = a[2 * 3 + 2];
  final b00 = b[0 * 3 + 0];
  final b01 = b[0 * 3 + 1];
  final b02 = b[0 * 3 + 2];
  final b10 = b[1 * 3 + 0];
  final b11 = b[1 * 3 + 1];
  final b12 = b[1 * 3 + 2];
  final b20 = b[2 * 3 + 0];
  final b21 = b[2 * 3 + 1];
  final b22 = b[2 * 3 + 2];

  return [
    b00 * a00 + b01 * a10 + b02 * a20,
    b00 * a01 + b01 * a11 + b02 * a21,
    b00 * a02 + b01 * a12 + b02 * a22,
    b10 * a00 + b11 * a10 + b12 * a20,
    b10 * a01 + b11 * a11 + b12 * a21,
    b10 * a02 + b11 * a12 + b12 * a22,
    b20 * a00 + b21 * a10 + b22 * a20,
    b20 * a01 + b21 * a11 + b22 * a21,
    b20 * a02 + b21 * a12 + b22 * a22,
  ];
}