Advanced math using 9Dof data on an UNO

I have a 9Dof stick and UNO up and running this orientation processing test:

It tracks the exact location of the device, as seen in this photo.


The sketch on the UNO outputs the YAW,PITCH, ROLL data like this:

What I'm wanting to do it to use that data, and detect when the board has moved x degrees in any direction. (x likely being about 5 degrees) I'm envisioning code something like this:

set currentPosition to the current direction it's pointing

now this loop:
check if it's changed direction
if the change is move than 5 degrees set hasChanged to true
set currentPosition to the new position

With this, I could just keep a watch on currentPosition, and if it has changed, I'll know there's been a 5 degree movement in any direction.

I really have no idea how to go about the math of turning the YAW,PITCH,ROLL data into a spherical direction, and then calculate a difference of angle in 2 readings. Maybe this is more complex than what the Atmega chip can do? I'm hoping not. If this can work, I have an awesome project for it!
Thanks for the help!

For small rotations, it is fairly simple to use spherical trigonometry or vector algebra to calculate a change in orientation, and a function to do that may already be built in to the AHRS software you are using. The documentation for that software would be a good place to start.

For larger changes in orientation, angles don't work well or at all due to a problem called "gimbal lock" -- it sometimes becomes impossible to calculate a unique set of angles that describe the orientation.

To read up on this stuff, I strongly recommend the background material at http://www.chrobotics.com/library