# Fixed small mathematical errors. #26

Merged
merged 1 commit into from Jan 28, 2014

## Conversation

Projects
None yet
2 participants
Contributor

### 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]] Determinant: +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: Determinant: +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.
``` fixed math bugs ```
``` 8ee8e45 ```

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

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

Owner

### idmillington commented Jan 28, 2014

 Really appreciate the fixes, thanks!