In Quaternion Monte Carlo we keep track of the reference frame with the use of two unit vectors that define a plane. The rotation of the vectors is achieved with Quaternion algebra
The polarization reference frame can be tracked via a triplet of unit vectors that are rotated by an azimuth and scattering angle at each scattering step. In our implementation only two vectors are rotated for every scattering event; the third unit vector is implicitly defined by the cross product of the two used vectors and is calculated only when a photon reaches a boundary.