I have a question very similar to this:
How to know if a line intersects a plane in C#?
I am searching for a method (in C#) tha
Slightly off topic, but if the line is infinite I think there's a much simpler solution:
The line does not go through the polygon if all the point lie on the same side of the line.
With help from these two:
I got this little gem:
public class PointsAndLines
{
public static bool IsOutside(Point lineP1, Point lineP2, IEnumerable region)
{
if (region == null || !region.Any()) return true;
var side = GetSide(lineP1, lineP2, region.First());
return
side == 0
? false
: region.All(x => GetSide(lineP1, lineP2, x) == side);
}
public static int GetSide(Point lineP1, Point lineP2, Point queryP)
{
return Math.Sign((lineP2.X - lineP1.X) * (queryP.Y - lineP1.Y) - (lineP2.Y - lineP1.Y) * (queryP.X - lineP1.X));
}
}