using System;
using System.Collections.Generic;
class Program
{
struct Point
{
public double x, y;
}
static bool PointInPolygon(Point point, List<Point> polygon)
{
int numVertices = polygon.Count;
double x = point.x, y = point.y;
bool inside = false;
Point p1 = polygon[0], p2;
for (int i = 1; i <= numVertices; i++)
{
p2 = polygon[i % numVertices];
if (y > Math.Min(p1.y, p2.y))
{
if (y <= Math.Max(p1.y, p2.y))
{
if (x <= Math.Max(p1.x, p2.x))
{
double xIntersection = (y - p1.y) * (p2.x - p1.x) / (p2.y - p1.y) + p1.x;
if (p1.x == p2.x || x <= xIntersection)
{
inside = !inside;
}
}
}
}
p1 = p2;
}
return inside;
}
static void Main(string[] args)
{
Point point = new Point { x = 150, y = 85 };
List<Point> polygon = new List<Point>
{
new Point { x = 186, y = 14 },
new Point { x = 186, y = 44 },
new Point { x = 175, y = 115 },
new Point { x = 175, y = 85 }
};
if (PointInPolygon(point, polygon))
{
Console.WriteLine("Point is inside the polygon");
}
else
{
Console.WriteLine("Point is outside the polygon");
}
}
}