
robcat2075
The Ray Tracer Challenge: Inversion of Rotation trouble
Title: Ray Trace Challenge: Inversion pg 49
I have gotten all my code (including my matrix multiplication and inversion routines) to pass the prescribed tests up through page 48, where we begin rotating on the X axis.
My code creates the desired result for the “half quarter” and “full quarter” rotations on the X axis.
However, on page 49 there is this last test proposed for the X rotations…
Next, add another test showing that the inverse of this rotation matrix simply
rotates in the opposite direction.
By an inversion, I do not get a rotation in the opposite direction. Instead, the point gets moved to 0,0,0
The matrix after the original PI/4 rotation operation looks like this…
Rotation PI/4.0 matrix values
Matrix values
| 1.0000 | 0.0000 | 0.0000 | 0.0000 |
| 0.0000 | 0.7071 | -0.7071 | 0.0000 |
| 0.0000 | 0.7071 | 0.7071 | 0.0000 |
| 0.0000 | 0.0000 | 0.0000 | 1.0000 |
That matrix produces the desired result when multiplied by the tuple that represents the 0,1,0 starting point.
If I apply Inversion to that matrix, as the book directs, I get this matrix…
Rotation PI/4.0 matrix INVERTED values
Matrix values
| 1.0000 | 0.0000 | 0.0000 | 0.0000 |
| 0.0000 | 0.0000 | 0.0000 | 0.0000 |
| 0.0000 | 0.0000 | 0.0000 | 0.0000 |
| 0.0000 | 0.0000 | 0.0000 | 1.0000 |
When multiplied by the 0,1,0 Tuple, this does not produce an opposite rotation, the Tuple is placed at 0,0,0.
Elsewhere on the internet I have read the correct way to reverse a rotation matrix is to transpose it.
Indeed, if I use my Transpose routine on the original rotation Matrix I get a matrix that produces a correct opposite rotation…
Rotation PI/4.0 matrix TRANSPOSED values
Matrix values
| 1.0000 | 0.0000 | 0.0000 | 0.0000 |
| 0.0000 | 0.7071 | 0.7071 | 0.0000 |
| 0.0000 | -0.7071 | 0.7071 | 0.0000 |
| 0.0000 | 0.0000 | 0.0000 | 1.0000 |
Rotation PI/4.0 TRANSPOSED point values
values: x= 0.000 y= 0.707 z= -0.707 w= 1
However, after searching this forum I have not seen any mention that the direction to invert rather than tranpose in this instance is a typo or other error.
What am I doing wrong?
First Post!

robcat2075
Hold it… false alarm… I think.
Just by chance I caught a line of code where I was loading a double value into an int variable.
Fixing that has made the inverted rotation result come out correctly.
I wish I knew enough about matrix math to know why the wrong version was good enough for all the tests except that inverted rotation.
Popular Prag Prog topics










Other popular topics










Latest in PragProg
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /ash
- /centos
- /php
- /deepseek
- /html
- /zig
- /scala
- /debian
- /nixos
- /lisp
- /agda
- /react-native
- /sublime-text
- /textmate
- /kubuntu
- /arch-linux
- /ubuntu
- /revery
- /manjaro
- /spring
- /django
- /diversity
- /nodejs
- /lua
- /c
- /julia
- /slackware
- /neovim