Beispiel #1
0
        /// <summary>
        /// Returns the centroid.
        /// </summary>
        public C2DPoint GetCentroid()
        {
            // Find the centroid and area of the straight line polygon.
            C2DPoint Centroid = new C2DPoint(0, 0);
            //   C2DPoint pti = new C2DPoint();
            //   C2DPoint ptii;
            double dArea = 0;

            for (int i = 0; i < Lines.Count; i++)
            {
                C2DPoint pti  = Lines[i].GetPointFrom();
                C2DPoint ptii = Lines[i].GetPointTo();

                Centroid.x += (pti.x + ptii.x) * (pti.x * ptii.y - ptii.x * pti.y);
                Centroid.y += (pti.y + ptii.y) * (pti.x * ptii.y - ptii.x * pti.y);

                dArea += pti.x * ptii.y - ptii.x * pti.y;
            }
            dArea = dArea / 2.0;

            Centroid.x = Centroid.x / (6.0 * dArea);
            Centroid.y = Centroid.y / (6.0 * dArea);

            List <double>   dSegAreas    = new List <double>();
            double          dTotalArea   = dArea;
            List <C2DPoint> SegCentroids = new List <C2DPoint>();

            for (int i = 0; i < Lines.Count; i++)
            {
                if (Lines[i] is C2DArc)
                {
                    C2DSegment Seg      = new C2DSegment(Lines[i] as C2DArc);
                    double     dSegArea = Seg.GetAreaSigned();
                    dTotalArea += dSegArea;
                    dSegAreas.Add(dSegArea);
                    SegCentroids.Add(Seg.GetCentroid());
                }
            }

            Centroid.Multiply(dArea);

            for (int i = 0; i < dSegAreas.Count; i++)
            {
                Centroid.x += SegCentroids[i].x * dSegAreas[i];
                Centroid.y += SegCentroids[i].y * dSegAreas[i];
            }

            Centroid.Multiply(1 / dTotalArea);
            return(Centroid);
        }
        /// <summary>
        /// Returns the centroid.
        /// </summary>
        public C2DPoint GetCentroid()
        {
            // Find the centroid and area of the straight line polygon.
            C2DPoint Centroid = new C2DPoint(0, 0);
             //   C2DPoint pti = new C2DPoint();
             //   C2DPoint ptii;
            double dArea = 0;

            for (int i = 0; i < Lines.Count; i++)
            {
                C2DPoint pti = Lines[i].GetPointFrom();
                C2DPoint ptii = Lines[i].GetPointTo();

                Centroid.x += (pti.x + ptii.x) * (pti.x * ptii.y - ptii.x * pti.y);
                Centroid.y += (pti.y + ptii.y) * (pti.x * ptii.y - ptii.x * pti.y);

                dArea += pti.x * ptii.y - ptii.x * pti.y;
            }
            dArea = dArea / 2.0;

            Centroid.x = Centroid.x / (6.0 * dArea);
            Centroid.y = Centroid.y / (6.0 * dArea);

            List<double> dSegAreas = new List<double>();
            double dTotalArea = dArea;
            List<C2DPoint> SegCentroids = new List<C2DPoint>();

            for (int i = 0; i < Lines.Count; i++)
            {
                if (Lines[i] is C2DArc)
                {
                    C2DSegment Seg = new C2DSegment( Lines[i] as C2DArc );
                    double dSegArea = Seg.GetAreaSigned();
                    dTotalArea += dSegArea;
                    dSegAreas.Add( dSegArea );
                    SegCentroids.Add( Seg.GetCentroid() );
                }
            }

            Centroid.Multiply( dArea);

            for (int i = 0; i < dSegAreas.Count; i++)
            {
                Centroid.x += SegCentroids[i].x * dSegAreas[i];
                Centroid.y += SegCentroids[i].y * dSegAreas[i];
            }

            Centroid.Multiply( 1/ dTotalArea);
            return Centroid;
        }