Implement n-dimensional rotation matrix algorithm.