Skip to content

Instantly share code, notes, and snippets.

@fospathi
Created November 27, 2017 13:59
Show Gist options
  • Save fospathi/24fba0114046da52490d623e1d850385 to your computer and use it in GitHub Desktop.
Save fospathi/24fba0114046da52490d623e1d850385 to your computer and use it in GitHub Desktop.
/// Print the calculation which multiplies two 3x4 affine transformation
/// matrices.
///
/// The matrices store their elements in a flat array in column order.
void main() {
StringBuffer buffer = new StringBuffer();
String l = "a1";
String r = "a2";
for (int col in new Iterable.generate(4)) {
for (int row in new Iterable.generate(3)) {
buffer.writeAll([
"$l[${0 + row}]*$r[${col * 3 + 0}]",
"$l[${3 + row}]*$r[${col * 3 + 1}]",
"$l[${6 + row}]*$r[${col * 3 + 2}]",
], " + ");
if (3 == col) {
buffer.write(" + $l[${9 + row}]");
}
buffer.write(",\n");
}
}
print(buffer.toString());
}
/*
a1[0]*a2[0] + a1[3]*a2[1] + a1[6]*a2[2],
a1[1]*a2[0] + a1[4]*a2[1] + a1[7]*a2[2],
a1[2]*a2[0] + a1[5]*a2[1] + a1[8]*a2[2],
a1[0]*a2[3] + a1[3]*a2[4] + a1[6]*a2[5],
a1[1]*a2[3] + a1[4]*a2[4] + a1[7]*a2[5],
a1[2]*a2[3] + a1[5]*a2[4] + a1[8]*a2[5],
a1[0]*a2[6] + a1[3]*a2[7] + a1[6]*a2[8],
a1[1]*a2[6] + a1[4]*a2[7] + a1[7]*a2[8],
a1[2]*a2[6] + a1[5]*a2[7] + a1[8]*a2[8],
a1[0]*a2[9] + a1[3]*a2[10] + a1[6]*a2[11] + a1[9],
a1[1]*a2[9] + a1[4]*a2[10] + a1[7]*a2[11] + a1[10],
a1[2]*a2[9] + a1[5]*a2[10] + a1[8]*a2[11] + a1[11],
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment