I asked a question on stackoverflow about how to know if a line is coinciding with another polygon. [http://stackoverflow.com/q/13304575/1362544]
The answer I got suggested checking intersection of the line with each edge of the polygon. Precisely, this is what the answer said:
Checking crossing of the line with edge is a geometry problem. If bounding-points of line we are checking are P1=(x1,y1) and P2=(x2,y2), and bounding points of edge are P3=(x3,y3) and P4=(x4,y4) then you should solve the linear system:
(x2 - x1) y + (y1 - y2) x = x1 y2 - x2 y1 ,
(x4 - x3) y + (y3 - y4) x = x3 y4 - x4 y3 .
After getting a value for (x, y) you should check that it is on parts between bounding-points on both lines (line we're checking and the edge). If that is true your lines cross each other
I don't understand how he got the 2 equations- an explanation would be greatly appreciated.
Actually that's not quite right: the terms on the right have the wrong signs. $$(x_2 - x_1) y + (y_1 - y_2) x = - x_1 y_2 + x_2 y_1$$ is satisfied by both $(x,y) = (x_1, y_1)$ and $(x,y) = (x_2, y_2)$, and therefore (since it's the equation of some straight line) is the equation for the straight line joining those two points. Similarly $$(x_4 - x_3) y + (y_3 - y_4) x = - x_3 y_4 + x_4 y_3$$ is the equation for the straight line joining $(x_3,y_3)$ and $(x_4,y_4)$.