New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed small mathematical errors. #26

merged 1 commit into from Jan 28, 2014


None yet
2 participants

dwetterau commented Jan 28, 2014

The first issue in src/collide_fine.cpp was something I noticed from the book, where the contactPoint's value gets overwritten when it should just be displaced by the vertexPos vector.

The issue in Matrix4::getDeterminant() I noticed when I was trying to use the matrix inverse method for the first time. For a rotation matrix I had, the determinant was returning an incorrect value which I confirmed with my calculator and various online tools. I have derived the Matrix4 determinant method again below:

Original Matrix:
[[a, b, c, d]
[e, f, g, h]
[i, j , k, l]
[0, 0, 0, 1]]

+a * det([[f, g, h], [j, k, l], [0, 0, 1]])
-b * det([[e, g, h], [i, k, l], [0, 0, 1]])
+c * det([[e, f, h], [i, j, l], [0, 0, 1]])
-d * det([[e, f, g], [i, j, k], [0, 0, 0]])

Since the matrix d is multiplied by has all zeros for the last row, it has a determinant of 0. Since each of the remaining three matrices have two zeros in the bottom row, they each reduce to the 2x2 matrix made of the top left corner of each matrix. Therefore we have:

+a_(f_k - g_j) - b_(e_k - g_i) + c_(e_j - f*i)
= afk - agj - bek + bgi + cej - cfi

Substituting in a = data[0], b = data[1], and so on we get:
+data[0] * data[5] * data[10]
-data[0] * data[6] * data[9]
-data[1] * data[4] * data[10]
+data[1] * data[6] * data[8]
+data[2] * data[4] * data[9]
-data[2] * data[5] * data[8]

Which is equivalent to the old code (just in a different order):
return data[8] * data[5] * data[2]+
data[4] * data[9] * data[2]+
data[8] * data[1] * data[6]-
data[0] * data[9] * data[6]-
data[4] * data[1] * data[10]+
data[0] * data[5] * data[10];

With the exception of the first line needing to be negative.

If I messed up, I apologize for wasting your time. I've absolutely loved reading and implementing things from your book.

idmillington added a commit that referenced this pull request Jan 28, 2014

Merge pull request #26 from dwetterau/master
Fixed small mathematical errors.

@idmillington idmillington merged commit e68e1ba into idmillington:master Jan 28, 2014


This comment has been minimized.


idmillington commented Jan 28, 2014

Really appreciate the fixes, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment