I am working on Project Euler Problem 102 and I thought I had a solution, but it seems I do not.
Now, don't give me the solution. I know I'm on the right track. What I want to know is why my method proved incorrect.
Here is my algorithm in sudo-code:
theta1 = angle of line (0, pt1) theta2 = angle of line (0, pt2) theta3 = angle of line (0, pt3) max angle = max(theta1, theta2, theta3) min angle = min(theta1, theta2, theta3) if (max angle - min angle > 180) Yes! contains origin else No! does not contain origin
Why is this not correct? If the origin lies inside the triangle then the rotation of a line from the origin to each of the points would yield an angle of more than 180. If the origin lies on one of the triangle sides then (max - min) would be 180 exactly, right? if the origin was not inside the triangle then (max - min) would be less than 180, etc.
I can see this in my head, but I'm obviously missing something. What am I missing?