solve static method

void solve(
  1. Matrix3 A,
  2. Vector3 x,
  3. Vector3 b
)

Solve A * x = b.

Implementation

static void solve(Matrix3 A, Vector3 x, Vector3 b) {
  final A0x = A.entry(0, 0);
  final A0y = A.entry(1, 0);
  final A0z = A.entry(2, 0);
  final A1x = A.entry(0, 1);
  final A1y = A.entry(1, 1);
  final A1z = A.entry(2, 1);
  final A2x = A.entry(0, 2);
  final A2y = A.entry(1, 2);
  final A2z = A.entry(2, 2);
  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 x_ = det * (b.x * rx + b.y * ry + b.z * rz);

  // Column2 cross b
  rx = -(A2y * b.z - A2z * b.y);
  ry = -(A2z * b.x - A2x * b.z);
  rz = -(A2x * b.y - A2y * b.x);
  // Column0 dot -[Column2 cross b (Column3)]
  final y_ = det * (A0x * rx + A0y * ry + A0z * rz);

  // b cross Column 1
  rx = -(b.y * A1z - b.z * A1y);
  ry = -(b.z * A1x - b.x * A1z);
  rz = -(b.x * A1y - b.y * A1x);
  // Column0 dot -[b cross Column 1]
  final z_ = det * (A0x * rx + A0y * ry + A0z * rz);

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