I had this problem on my last programming contest and my team had no idea as to how to approach it. I'm not asking for an exact answer to this but can anyone give me an general idea about how to do this, or what I should research to figure out how to do this?
Do you want the mathematical method to work it out, or how to turn this method into a piece of code?
Originally Posted by chili5
The mathematics required is very simple, but you'll have to look at the logic of the various possible positions of the pairs of points to solve the problem. I suggest you proceed as follows:
Suppose that the line joining the origin to the point makes an angle with the positive direction of the -axis, measured clockwise, with ; and similarly for and . Then the output angle is the difference between these two angles: ; or, if this is negative, .
So how do we find the angle ? The first thing to do is to calculate the acute angle that the line joining the origin to makes with the horizontal. If this angle is denoted by , then . Note that:
You will need to check for to avoid a division by zero error.Then the value of will depend upon which quadrant is in; as follows:Also, if then:
If Clearly you find in the same way.
I hope that makes sense. (Drawing a diagram should help to clarify things.)
Thanks. I'll play around with it some and see if that makes any sense =)
Originally Posted by Grandad
Well today in math we actually went over the arctan thing required to calculate the acute angle but what I'm not sure of is the four quadrant thing that you posted above. Sorry, I'm just so lost. :(