How to calculate reference angle