public static void Main()
Polygone poly = new Polygone(new Point(){X = 210, Y = 140}, new Point(){X = 240, Y = 135}, new Point(){X = 210 ,Y = 150}, new Point(){X = 180, Y = 135});
Console.WriteLine(poly.Contains(new Point(198,140)));
Console.WriteLine( (120-90)*-0.5);
public bool IsEmpty { get { return _isEmpty; } }
public Polygone(Point a, Point b, Point c, Point d)
public bool Contains(Point x)
bool rAB = IsUpperToAB(x);
bool rBC = IsLowerToCB(x);
bool rAD = IsUpperToDA(x);
bool rDC = IsLowerToDC(x);
if(A.Y < D.Y && A.Y < B.Y)
return rAB & rBC & rAD & rDC;
return (rAD | rAB) & rBC & rDC;
public bool IsUpperToAB(Point x)
float coef = (B.Y - A.Y) / (float)(B.X - A.X);
Console.WriteLine("IsUpperToAB");
Console.WriteLine(" coef: " + coef.ToString());
Console.WriteLine(" " + (A.Y + (x.X - A.X) * coef).ToString() + " <= " + x.Y.ToString());
Console.WriteLine(" " + (A.Y + (x.X - A.X) * coef <= x.Y).ToString());
return A.Y + (x.X - A.X) * coef <= x.Y;
public bool IsUpperToDA(Point x)
float coef = (D.Y - A.Y) / (float)(D.X - A.X);
Console.WriteLine("IsUpperToDA");
Console.WriteLine(" coef: " + coef.ToString());
Console.WriteLine(" " + (D.Y + (x.X - D.X) * coef).ToString() + " <= " + x.Y.ToString());
Console.WriteLine(" " + (D.Y + (x.X - D.X) * coef <= x.Y).ToString());
return D.Y + (x.X - D.X) * coef <= x.Y;
public bool IsLowerToCB(Point x)
float coef = (C.Y - B.Y) / (float)(C.X - B.X);
Console.WriteLine("IsLowerToCB");
Console.WriteLine(" coef: " + coef.ToString());
Console.WriteLine(" " + (C.Y + (x.X - C.X) * coef).ToString() + " >= " + x.Y.ToString());
Console.WriteLine(" " + (C.Y + (x.X - C.X) * coef >= x.Y).ToString());
return C.Y + (x.X - C.X) * coef >= x.Y;
public bool IsLowerToDC(Point x)
float coef = (C.Y - D.Y) / (float)(C.X - D.X);
Console.WriteLine("IsLowerToDC");
Console.WriteLine(" coef: " + coef.ToString());
Console.WriteLine(" " + (D.Y + (x.X - D.X) * coef).ToString() + " >= " + x.Y.ToString());
Console.WriteLine(" " + (D.Y + (x.X - D.X) * coef >= x.Y).ToString());
return D.Y + (x.X - D.X) * coef >= x.Y;
public Polygone Translation(int x, int y)
new Point(A.X + x, A.Y + y),
new Point(B.X + x, B.Y + y),
new Point(C.X + x, C.Y + y),
new Point(D.X + x, D.Y + y));
public static Polygone Empty
get { return new Polygone() { _isEmpty = true }; }