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?
Thanks!
Hello 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:
If .
QI:Also, if then:
QII:
QIII:
QIV:
IfClearly you find in the same way.
If
I hope that makes sense. (Drawing a diagram should help to clarify things.)
Grandad
Hello chili5Have a look at the attached diagram. I have indicated the four quadrants, and as an example the line in QIII with its angles and . You'll see that in this case
If you look at the acute angles the lines in the other three quadrants make with the -axis, and then the clockwise angles from the positive direction of the -axis, I think you'll see where the other equations I gave you come from.
Grandad