Exemple #1
0
        private static void SwapPoints(ref PointZ a, ref PointZ b)
        {
            PointZ tmp = a;

            a = b;
            b = tmp;
        }
Exemple #2
0
        public Triangle(PointZ a, PointZ b, PointZ c)
        {
            vertexes = new PointZ[3];

            vertexes[0] = a;
            vertexes[1] = b;
            vertexes[2] = c;

            edges.Add(new Edge(a, b));
            edges.Add(new Edge(a, c));
            edges.Add(new Edge(b, c));
        }
Exemple #3
0
        public static List <PointZ> JarvisHull(PointZ[] points)
        {
            var Shell = new List <PointZ>();

            //Ищем отправную точку
            Int32 asStart = 0;

            for (int i = 1; i < points.Length; i++)
            {
                if (Math.Abs(points[i].Y - points[asStart].Y) < 0.000001)
                {
                    if (points[i].X < points[asStart].X)
                    {
                        asStart = i;
                    }
                    else
                    {
                        ;
                    }
                }
                else if (points[i].Y < points[asStart].Y)
                {
                    asStart = i;
                }
            }
            var startpoint = new PointZ(points[asStart].X, points[asStart].Y);

            Shell.Add(points[asStart]);

            PointZ current = points[asStart];

            SwapPoints(ref points[points.Length - 1], ref points[asStart]);
            Int32 k = 0;

            //Алгоритм выборки точек
            do
            {
                for (int i = k; i < points.Length; i++)
                {
                    if (PseudoscolarMult(current, points[i], points[k]) < 0)
                    {
                        SwapPoints(ref points[k], ref points[i]);
                    }
                }
                current = points[k];
                Shell.Add(points[k]);
                k++;
            }while (!IsEqualPoints(current, startpoint));

            //Shell.Add(startpoint);

            return(new HashSet <PointZ>(Shell).ToList());
        }
Exemple #4
0
 public PointZ getSecondPoint(PointZ point) => a == point ? b : a;
Exemple #5
0
 public bool Contains(PointZ point) => (a == point) || (b == point);
Exemple #6
0
 public Edge(PointZ p1, PointZ p2)
 {
     a = p1;
     b = p2;
 }
Exemple #7
0
 public bool Contains(PointZ point) => vertexes.Contains(point);
Exemple #8
0
 private static bool IsEqualPoints(PointZ current, PointZ startpoint)
 {
     return(current.X == startpoint.X && current.Y == startpoint.Y);
 }
Exemple #9
0
 private static double PseudoscolarMult(PointZ k, PointZ a, PointZ b)
 {
     return((a.X - k.X) * (b.Y - k.Y) - (b.X - k.X) * (a.Y - k.Y));
 }