Dart Documentationbox2d_htmlMatrix33

Matrix33 class

A 3-by-3 matrix. Stored in column-major order.

class Matrix33 {
  final Vector3 col1;
  final Vector3 col2;
  final Vector3 col3;

  Matrix33() :
    col1 = new Vector3(),
    col2 = new Vector3(),
    col3 = new Vector3() { }

  Matrix33.setCols(Vector3 argCol1, Vector3 argCol2, Vector3 argCol3) :
    col1 = new Vector3.copy(argCol1),
    col2 = new Vector3.copy(argCol2),
    col3 = new Vector3.copy(argCol3) { }

  void setZero() {
    col1.setZero();
    col2.setZero();
    col3.setZero();
  }

  // Multiply a matrix times a vector.
  static Vector3 mul(Matrix33 A, Vector3 v){
    return new Vector3(v.x * A.col1.x + v.y * A.col2.x + v.z + A.col3.x,
        v.x * A.col1.y + v.y * A.col2.y + v.z * A.col3.y,
        v.x * A.col1.z + v.y * A.col2.z + v.z * A.col3.z);
  }

  static void mulToOut(Matrix33 A, Vector3 v, Vector3 out){
    final num tempy = v.x * A.col1.y + v.y * A.col2.y + v.z * A.col3.y;
    final num tempz = v.x * A.col1.z + v.y * A.col2.z + v.z * A.col3.z;
    out.x = v.x * A.col1.x + v.y * A.col2.x + v.z + A.col3.x;
    out.y = tempy;
    out.z = tempz;
  }

  /**
   * Solve A * x = b, where b is a column vector. This is more efficient
   * than computing the inverse in one-shot cases.
   */
  Vector solve22(Vector b) {
    Vector x = new Vector();
    solve22ToOut(b, x);
    return x;
  }

  /**
   * Solve A * x = b, where b is a column vector. This is more efficient
   * than computing the inverse in one-shot cases.
   */
  void solve22ToOut(Vector b, Vector out) {
    final num a11 = col1.x, a12 = col2.x, a21 = col1.y, a22 = col2.y;
    num det = a11 * a22 - a12 * a21;
    if (det != 0.0){
      det = 1.0 / det;
    }
    out.x = det * (a22 * b.x - a12 * b.y);
    out.y = det * (a11 * b.y - a21 * b.x);
  }

  /**
   * Solve A * x = b, where b is a column vector. This is more efficient
   * than computing the inverse in one-shot cases.
   */
  Vector3 solve33(Vector3 b) {
    Vector3 x = new Vector3();
    solve33ToOut(b, x);
    return x;
  }

  /**
   * Solve A * x = b, where b is a column vector. This is more efficient
   * than computing the inverse in one-shot cases.
   * out: the result
   */
  void solve33ToOut(Vector3 b, Vector3 out) {
    Vector3.crossToOut(col2, col3, out);
    num det = Vector3.dot(col1, out);
    if (det != 0.0){
      det = 1.0 / det;
    }

    Vector3.crossToOut(col2, col3, out);
    final num x = det * Vector3.dot(b, out);
    Vector3.crossToOut(b, col3, out);
    final num y = det * Vector3.dot(col1, out);
    Vector3.crossToOut(col2, b, out);
    num z = det * Vector3.dot(col1, out);
    out.x = x;
    out.y = y;
    out.z = z;
  }
}

Constructors

new Matrix33() #

Matrix33() :
  col1 = new Vector3(),
  col2 = new Vector3(),
  col3 = new Vector3() { }

new Matrix33.setCols(Vector3 argCol1, Vector3 argCol2, Vector3 argCol3) #

Matrix33.setCols(Vector3 argCol1, Vector3 argCol2, Vector3 argCol3) :
  col1 = new Vector3.copy(argCol1),
  col2 = new Vector3.copy(argCol2),
  col3 = new Vector3.copy(argCol3) { }

Static Methods

Vector3 mul(Matrix33 A, Vector3 v) #

static Vector3 mul(Matrix33 A, Vector3 v){
  return new Vector3(v.x * A.col1.x + v.y * A.col2.x + v.z + A.col3.x,
      v.x * A.col1.y + v.y * A.col2.y + v.z * A.col3.y,
      v.x * A.col1.z + v.y * A.col2.z + v.z * A.col3.z);
}

void mulToOut(Matrix33 A, Vector3 v, Vector3 out) #

static void mulToOut(Matrix33 A, Vector3 v, Vector3 out){
  final num tempy = v.x * A.col1.y + v.y * A.col2.y + v.z * A.col3.y;
  final num tempz = v.x * A.col1.z + v.y * A.col2.z + v.z * A.col3.z;
  out.x = v.x * A.col1.x + v.y * A.col2.x + v.z + A.col3.x;
  out.y = tempy;
  out.z = tempz;
}

Properties

final Vector3 col1 #

final Vector3 col1;

final Vector3 col2 #

final Vector3 col2;

final Vector3 col3 #

final Vector3 col3;

final Type runtimeType #

inherited from Object

A representation of the runtime type of the object.

external Type get runtimeType;

Operators

bool operator ==(other) #

inherited from Object

The equality operator.

The default behavior for all Objects is to return true if and only if this and other are the same object.

If a subclass overrides the equality operator it should override the hashCode method as well to maintain consistency.

bool operator ==(other) => identical(this, other);

Methods

int hashCode() #

inherited from Object

Get a hash code for this object.

All objects have hash codes. Hash codes are guaranteed to be the same for objects that are equal when compared using the equality operator ==. Other than that there are no guarantees about the hash codes. They will not be consistent between runs and there are no distribution guarantees.

If a subclass overrides hashCode it should override the equality operator as well to maintain consistency.

external int hashCode();

new Matrix33() #

Matrix33() :
  col1 = new Vector3(),
  col2 = new Vector3(),
  col3 = new Vector3() { }

new Matrix33.setCols(Vector3 argCol1, Vector3 argCol2, Vector3 argCol3) #

Matrix33.setCols(Vector3 argCol1, Vector3 argCol2, Vector3 argCol3) :
  col1 = new Vector3.copy(argCol1),
  col2 = new Vector3.copy(argCol2),
  col3 = new Vector3.copy(argCol3) { }

noSuchMethod(String name, List args) #

inherited from Object

noSuchMethod is invoked when users invoke a non-existant method on an object. The name of the method and the arguments of the invocation are passed to noSuchMethod. If noSuchMethod returns a value, that value becomes the result of the original invocation.

The default behavior of noSuchMethod is to throw a noSuchMethodError.

external Dynamic noSuchMethod(String name, List args);

const Object() #

inherited from Object

Creates a new Object instance.

Object instances have no meaningful state, and are only useful through their identity. An Object instance is equal to itself only.

const Object();

void setZero() #

void setZero() {
  col1.setZero();
  col2.setZero();
  col3.setZero();
}

Vector solve22(Vector b) #

Solve A * x = b, where b is a column vector. This is more efficient than computing the inverse in one-shot cases.

Vector solve22(Vector b) {
  Vector x = new Vector();
  solve22ToOut(b, x);
  return x;
}

void solve22ToOut(Vector b, Vector out) #

Solve A * x = b, where b is a column vector. This is more efficient than computing the inverse in one-shot cases.

void solve22ToOut(Vector b, Vector out) {
  final num a11 = col1.x, a12 = col2.x, a21 = col1.y, a22 = col2.y;
  num det = a11 * a22 - a12 * a21;
  if (det != 0.0){
    det = 1.0 / det;
  }
  out.x = det * (a22 * b.x - a12 * b.y);
  out.y = det * (a11 * b.y - a21 * b.x);
}

Vector3 solve33(Vector3 b) #

Solve A * x = b, where b is a column vector. This is more efficient than computing the inverse in one-shot cases.

Vector3 solve33(Vector3 b) {
  Vector3 x = new Vector3();
  solve33ToOut(b, x);
  return x;
}

void solve33ToOut(Vector3 b, Vector3 out) #

Solve A * x = b, where b is a column vector. This is more efficient than computing the inverse in one-shot cases. out: the result

void solve33ToOut(Vector3 b, Vector3 out) {
  Vector3.crossToOut(col2, col3, out);
  num det = Vector3.dot(col1, out);
  if (det != 0.0){
    det = 1.0 / det;
  }

  Vector3.crossToOut(col2, col3, out);
  final num x = det * Vector3.dot(b, out);
  Vector3.crossToOut(b, col3, out);
  final num y = det * Vector3.dot(col1, out);
  Vector3.crossToOut(col2, b, out);
  num z = det * Vector3.dot(col1, out);
  out.x = x;
  out.y = y;
  out.z = z;
}

String toString() #

inherited from Object

Returns a string representation of this object.

external String toString();