#ifndef __ROTATE_H__ #define __ROTATE_H__ __device__ const Matrix IDENTITY_MATRIX = {1,0,0,0,1,0,0,0,1}; __device__ const Matrix ZERO_MATRIX = {0,0,0,0,0,0,0,0,0}; __device__ __host__ Matrix make_rotation_matrix(float phi, const float3 &n) { /* rotate points counterclockwise, when looking towards +infinity, through an angle `phi` about the axis `n`. */ float cos_phi = cosf(phi); float sin_phi = sinf(phi); return IDENTITY_MATRIX*cos_phi + (1-cos_phi)*outer(n,n) + sin_phi*make_matrix(0,n.z,-n.y,-n.z,0,n.x,n.y,-n.x,0); } __device__ __host__ float3 rotate(const float3 &a, float phi, const float3 &n) { return make_rotation_matrix(phi,n)*a; } #endif