Reference angle demo

Reference angle demonstration

What happens at 90 degrees? Why? How can this 'bug' be corrected?