Beispiel #1
0
        /// <summary>
        /// Gets the area.
        /// </summary>
        public double GetArea()
        {
            double dArea = 0;

            for (int i = 0; i < Lines.Count; i++)
            {
                C2DPoint pt1 = _Lines[i].GetPointFrom();
                C2DPoint pt2 = _Lines[i].GetPointTo();

                dArea += pt1.x * pt2.y - pt2.x * pt1.y;
            }
            dArea = dArea / 2.0;

            for (int i = 0; i < Lines.Count; i++)
            {
                if (_Lines[i] is C2DArc)
                {
                    C2DArc Arc = _Lines[i] as C2DArc;

                    C2DSegment Seg = new C2DSegment(Arc);

                    dArea += Seg.GetAreaSigned();
                }
            }

            return(Math.Abs(dArea));
        }
Beispiel #2
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;
        }
        /// <summary>
        /// Gets the area.
        /// </summary>
        public double GetArea()
        {
            double dArea = 0;

            for (int i = 0; i < Lines.Count; i++)
            {
                C2DPoint pt1 = _Lines[i].GetPointFrom();
                C2DPoint pt2 = _Lines[i].GetPointTo();

                dArea += pt1.x * pt2.y - pt2.x * pt1.y;
            }
            dArea = dArea / 2.0;

            for (int i = 0; i < Lines.Count; i++)
            {
                if (_Lines[i] is C2DArc)
                {
                    C2DArc Arc = _Lines[i] as C2DArc;

                    C2DSegment Seg = new C2DSegment( Arc );

                    dArea += Seg.GetAreaSigned();
                }
            }

            return Math.Abs(dArea);
        }