Skip to content

Instantly share code, notes, and snippets.

@daeyun
Created October 18, 2015 02:53
Show Gist options
  • Save daeyun/9b6877ac8ee8675f1c27 to your computer and use it in GitHub Desktop.
Save daeyun/9b6877ac8ee8675f1c27 to your computer and use it in GitHub Desktop.
void Inverse33(const double a[3][3], double inv[3][3]) {
int i, j;
double determinant = 0;
for (i = 0; i < 3; i++)
determinant =
determinant + (a[0][i] * (a[1][(i + 1) % 3] * a[2][(i + 2) % 3] -
a[1][(i + 2) % 3] * a[2][(i + 1) % 3]));
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++)
inv[j][i] =
((a[(i + 1) % 3][(j + 1) % 3] * a[(i + 2) % 3][(j + 2) % 3]) -
(a[(i + 1) % 3][(j + 2) % 3] * a[(i + 2) % 3][(j + 1) % 3])) /
determinant;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment