I want to determine position of Point for a giving line in c#. I read this link and this link. I test them but it seems that my code is wrong. For some points close (not very close) to line it return wrong values. Here is my code:
public static PointToLineSituation WhereIsPoint(Line l, Point p)
{
var x = p.X;
var y = p.Y;
var x1 = l.X1;
var x2 = l.X2;
var y1 = l.Y1;
var y2 = l.Y2;
var d = (x - x1) * (y1 - y2) - (y - y1) * (x2 - x1);
if (d > 0)
return PointToLineSituation.Up;
if (d < 0)
return PointToLineSituation.Down;
return PointToLineSituation.OnLine;
}
I want to use in graphical coordination. Is it my problem? Any help will be appreciated.
Here is an example of coordination system, an up point, and a down point as depicted below: