Repository navigation
Commit 3dd62bb
committed
If math.Fraction is given a non-integer, numerator and denominator are scaled up to integers
Someone reported that matrixmath.inverse was returning something like
the identity matrix for any 3×3 rotation matrix.
`matrixmath.inverse` works by converting the matrix to a matrix of
Fractions, then performing Gauss-Jordan elimination on them. The
Fraction constructor rounds off its inputs, because it's expecting
integers on top and bottom.
This commit changes the Fraction constructor so both numerator and
denominator are multiplied by powers of 2 until they're both integers.
This necessarily results in some inaccuracy due to floating point error,
but at least it's not completely wrong.
I tried explicitly writing out the routine for inverting 3×3 matrices,
but it turned out to be less accurate than this method. The floating
point error must accumulate because there are more float operations.1 parent 4330e20 commit 3dd62bb
4 files changed
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2261 | 2261 | | |
2262 | 2262 | | |
2263 | 2263 | | |
| 2264 | + | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
2264 | 2268 | | |
2265 | 2269 | | |
2266 | 2270 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4498 | 4498 | | |
4499 | 4499 | | |
4500 | 4500 | | |
| 4501 | + | |
| 4502 | + | |
| 4503 | + | |
| 4504 | + | |
4501 | 4505 | | |
4502 | 4506 | | |
4503 | 4507 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1255 | 1255 | | |
1256 | 1256 | | |
1257 | 1257 | | |
| 1258 | + | |
| 1259 | + | |
1258 | 1260 | | |
1259 | 1261 | | |
1260 | 1262 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4499 | 4499 | | |
4500 | 4500 | | |
4501 | 4501 | | |
| 4502 | + | |
| 4503 | + | |
| 4504 | + | |
| 4505 | + | |
4502 | 4506 | | |
4503 | 4507 | | |
4504 | 4508 | | |
| |||
0 commit comments