Quaternion based compass