Beispiel #1
0
        private double _lineLeght(PointT a, PointT b) //подсчет длины отрезка ab
        {
            float x = a.X - b.X;
            float y = a.Y - b.Y;

            return(Math.Sqrt(x * x + y * y));
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Введите количество вершин многоугольника");
            var count = Convert.ToInt32(Console.ReadLine());


            var poligonT = new PointT[count];

            for (var i = 0; i < count; i++)
            {
                Console.WriteLine("X" + i + ":");
                var x = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Y" + i + ":");
                var y = Convert.ToInt32(Console.ReadLine());

                var point = new PointT(x, y);
                poligonT[i] = point;
            }



            var poligon = new Polygon(poligonT);

            Console.WriteLine("Площадь: ");
            Console.WriteLine(poligon.GetArea());
            Console.ReadLine();
        }
Beispiel #3
0
        private PointT?_getIntersectionPoint(PointT l1P1, PointT l1P2, PointT l2P1, PointT l2P2)
        {
            var a1 = l1P2.Y - l1P1.Y;
            var b1 = l1P1.X - l1P2.X;
            var c1 = a1 * l1P1.X + b1 * l1P1.Y;

            var a2 = l2P2.Y - l2P1.Y;
            var b2 = l2P1.X - l2P2.X;
            var c2 = a2 * l2P1.X + b2 * l2P1.Y;

            var det = a1 * b2 - a2 * b1;

            var x       = (b2 * c1 - b1 * c2) / det;
            var y       = (a1 * c2 - a2 * c1) / det;
            var online1 = (Math.Min(l1P1.X, l1P2.X) < x || Math.Min(l1P1.X, l1P2.X) == x) &&
                          (Math.Max(l1P1.X, l1P2.X) > x || Math.Max(l1P1.X, l1P2.X) == x) &&
                          (Math.Min(l1P1.Y, l1P2.Y) < y || Math.Min(l1P1.Y, l1P2.Y) == y) &&
                          (Math.Max(l1P1.Y, l1P2.Y) > y || Math.Max(l1P1.Y, l1P2.Y) == y);

            var online2 = ((Math.Min(l2P1.X, l2P2.X) < x || Math.Min(l2P1.X, l2P2.X) == x)) &&
                          (Math.Max(l2P1.X, l2P2.X) > x || Math.Max(l2P1.X, l2P2.X) == x) &&
                          (Math.Min(l2P1.Y, l2P2.Y) < y || Math.Min(l2P1.Y, l2P2.Y) == y) &&
                          (Math.Max(l2P1.Y, l2P2.Y) > y || Math.Max(l2P1.Y, l2P2.Y) == y);

            if (online1 && online2)
            {
                return(new PointT(x, y));
            }

            return(null);
        }
Beispiel #4
0
        private bool _isPointInside(PointT a, PointT b, PointT c, PointT p) //находится ли точка p внутри треугольника abc
        {
            float ab = (a.X - p.X) * (b.Y - a.Y) - (b.X - a.X) * (a.Y - p.Y);
            float bc = (b.X - p.X) * (c.Y - b.Y) - (c.X - b.X) * (b.Y - p.Y);
            float ca = (c.X - p.X) * (a.Y - c.Y) - (a.X - c.X) * (c.Y - p.Y);

            return((ab >= 0 && bc >= 0 && ca >= 0) || (ab <= 0 && bc <= 0 && ca <= 0));
        }
Beispiel #5
0
 private bool _pointInsertPoligon(IEnumerable <Triangle> triangles, PointT pt)
 {
     foreach (var triangle in triangles)
     {
         if (_isPointInside(triangle.getA(), triangle.getB(), triangle.getC(), pt))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #6
0
 public Triangle(PointT a, PointT b, PointT c)
 {
     this.a = a;
     this.b = b;
     this.c = c;
 }