solve3 method

void solve3 (Matrix4 A, Vector3 x, Vector3 b)

Solve A * x = b.

Implementation

static void solve3(Matrix4 A, Vector3 x, Vector3 b) {
  final double A0x = A.entry(0, 0);
  final double A0y = A.entry(1, 0);
  final double A0z = A.entry(2, 0);
  final double A1x = A.entry(0, 1);
  final double A1y = A.entry(1, 1);
  final double A1z = A.entry(2, 1);
  final double A2x = A.entry(0, 2);
  final double A2y = A.entry(1, 2);
  final double A2z = A.entry(2, 2);
  final double bx = b.x - A._m4storage[12];
  final double by = b.y - A._m4storage[13];
  final double bz = b.z - A._m4storage[14];
  double rx, ry, rz;
  double det;

  // Column1 cross Column 2
  rx = A1y * A2z - A1z * A2y;
  ry = A1z * A2x - A1x * A2z;
  rz = A1x * A2y - A1y * A2x;

  // A.getColumn(0).dot(x)
  det = A0x * rx + A0y * ry + A0z * rz;
  if (det != 0.0) {
    det = 1.0 / det;
  }

  // b dot [Column1 cross Column 2]
  final double x_ = det * (bx * rx + by * ry + bz * rz);

  // Column2 cross b
  rx = -(A2y * bz - A2z * by);
  ry = -(A2z * bx - A2x * bz);
  rz = -(A2x * by - A2y * bx);
  // Column0 dot -[Column2 cross b (Column3)]
  final double y_ = det * (A0x * rx + A0y * ry + A0z * rz);

  // b cross Column 1
  rx = -(by * A1z - bz * A1y);
  ry = -(bz * A1x - bx * A1z);
  rz = -(bx * A1y - by * A1x);
  // Column0 dot -[b cross Column 1]
  final double z_ = det * (A0x * rx + A0y * ry + A0z * rz);

  x
    ..x = x_
    ..y = y_
    ..z = z_;
}