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);
        }
Beispiel #3
0
        /// <summary>
        /// Draws a segment filled.
        /// </summary>
        public void DrawFilled(C2DSegment Segment, Graphics graphics, Brush brush)
        {
            C2DRect Rect        = new C2DRect();
            int     nStartAngle = 0;
            int     nSweepAngle = 0;

            GetArcParameters(Segment.Arc, Rect, ref nStartAngle, ref nSweepAngle);

            if (nSweepAngle == 0)
            {
                nSweepAngle = 1;
            }

            int Width = (int)Rect.Width();

            if (Width == 0)
            {
                Width = 1;
            }
            int Height = (int)Rect.Height();

            if (Height == 0)
            {
                Height = 1;
            }

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

            gp.AddArc((int)Rect.TopLeft.x, (int)Rect.BottomRight.y,
                      Width, Height, nStartAngle, nSweepAngle);

            C2DPoint ptFrom = Segment.Arc.Line.GetPointFrom();
            C2DPoint ptTo   = Segment.Arc.Line.GetPointTo();

            ScaleAndOffSet(ptFrom);
            ScaleAndOffSet(ptTo);
            gp.AddLine((int)ptTo.x, (int)ptTo.y, (int)ptFrom.x, (int)ptFrom.y);

            graphics.FillPath(brush, gp);
        }
        /// <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);
        }
 /// <summary>
 /// Returns the inverse of this i.e. the other part of the circle to this.
 /// </summary>
 /// <param name="Other">The other segment.</param>
 public void GetInverse(C2DSegment Other)
 {
     Other.Set(Arc.Line, Arc.Radius,
               Arc.CentreOnRight, !Arc.ArcOnRight);
 }
 /// <summary>
 /// Returns the inverse of this i.e. the other part of the circle to this.
 /// </summary>
 /// <param name="Other">The other segment.</param>	
 public void GetInverse( C2DSegment Other)
 {
     Other.Set(Arc.Line, Arc.Radius,
             Arc.CentreOnRight, !Arc.ArcOnRight );
 }
        /// <summary>
        /// Draws a segment filled.
        /// </summary>
        public void DrawFilled(C2DSegment Segment, Graphics graphics, Brush brush)
        {
            C2DRect Rect = new C2DRect();
            int nStartAngle = 0;
            int nSweepAngle = 0;

            GetArcParameters(Segment.Arc, Rect, ref nStartAngle, ref nSweepAngle);

            if (nSweepAngle == 0)
                nSweepAngle = 1;

            int Width = (int)Rect.Width();
            if (Width == 0)
                Width = 1;
            int Height = (int)Rect.Height();
            if (Height == 0)
                Height = 1;

            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

            gp.AddArc((int)Rect.TopLeft.x, (int)Rect.BottomRight.y,
                Width, Height, nStartAngle, nSweepAngle);

            C2DPoint ptFrom = Segment.Arc.Line.GetPointFrom();
            C2DPoint ptTo = Segment.Arc.Line.GetPointTo();
            ScaleAndOffSet(ptFrom);
            ScaleAndOffSet(ptTo);
            gp.AddLine((int)ptTo.x, (int)ptTo.y, (int)ptFrom.x, (int)ptFrom.y);

            graphics.FillPath(brush, gp);
        }
 /// <summary>
 /// Draws a Segment
 /// </summary>
 public void Draw(C2DSegment Segment, Graphics graphics, Pen pen)
 {
     Draw(Segment.Arc, graphics, pen);
     Draw(Segment.Arc.Line, graphics, pen);
 }
Beispiel #10
0
 /// <summary>
 /// Draws a Segment
 /// </summary>
 public void Draw(C2DSegment Segment, Graphics graphics, Pen pen)
 {
     Draw(Segment.Arc, graphics, pen);
     Draw(Segment.Arc.Line, graphics, pen);
 }