code for computing rotation