Exemple #1
0
        public static ResultPoint Largest(List <InputPoint> points)
        {
            var result = new ResultPoint(0, 0);

            foreach (var point in points)
            {
                if (point.A > result.X)
                {
                    result.X = point.A;
                }

                if (point.B > result.Y)
                {
                    result.Y = point.B;
                }
            }

            return(result);
        }
Exemple #2
0
        public static ResultPoint Centroid(List <InputPoint> vertices)
        {
            var    centroid   = new ResultPoint(0, 0);
            var    signedArea = 0.0;
            double x0; // Current vertex X
            double y0; // Current vertex Y
            double x1; // Next vertex X
            double y1; // Next vertex Y
            double a;  // Partial signed area

            // For all vertices except last
            int i;

            for (i = 0; i < vertices.Count - 1; ++i)
            {
                x0          = vertices[i].A;
                y0          = vertices[i].B;
                x1          = vertices[i + 1].A;
                y1          = vertices[i + 1].B;
                a           = x0 * y1 - x1 * y0;
                signedArea += a;
                centroid.X += (x0 + x1) * a;
                centroid.Y += (y0 + y1) * a;
            }

            // Do last vertex
            x0          = vertices[i].A;
            y0          = vertices[i].B;
            x1          = vertices[0].A;
            y1          = vertices[0].B;
            a           = x0 * y1 - x1 * y0;
            signedArea += a;
            centroid.X += (x0 + x1) * a;
            centroid.Y += (y0 + y1) * a;

            signedArea *= 0.5;
            centroid.X /= (6 * signedArea);
            centroid.Y /= (6 * signedArea);

            return(centroid);
        }