calculate rotation in bounding box