cBook‎ > ‎

Geometry

whether a point is to the right or left side of a line

posted Nov 23, 2014, 6:21 PM by Javad Taghia   [ updated Nov 23, 2014, 6:21 PM ]


http://stackoverflow.com/questions/1560492/how-to-tell-whether-a-point-is-to-the-right-or-left-side-of-a-line

 use of a cross product:

public bool isLeft(Point a, Point b, Point c){
     return ((b.x - a.x)*(c.y - a.y) - (b.y - a.y)*(c.x - a.x)) > 0;
}

Where a = line point 1; b = line point 2; c = point to check against.

If the formula is equal to 0, the points are colinear.

If the line is horizontal, then this returns true if the point is above the line.

1-1 of 1