Added calcrotation function