Hi am looking for some help
I have a Diagonal line drawn on a picture box on my forum and i need to know if the user has clicked the line
I have the Start point and End Point of the Line and the mouse x,y location
So i basically need to find out if the x,y of the mouse is on the line.
can anyone help?
Thanks
Example: Line Start point (A) is (0, 0), END point (B) is (10, 5).
Slope of line is therefore:
To check if your point(x,y) (C) is on the line it must have the same slope from A->C and C->B. so do the same calculation again. Say point is (4, 2)
Therefore this point would be on line AB.
If point was (20, 10)
However:
Similarly if point was (2, 2)
So for a point to be on a line
m(AB) == m(AC) == m(CB)You may have a bit of work arounds to perform as you may not be able to get decimal values, and your line may be more than one pixel in width, but these basic principles should see you through.