Esempio n. 1
0
        //klasa tworząca listy segmentów, do rysowania figur geometrycznych.
        // 1.Prostokąt - GetPolygon_Rect
        // 2.Wielokąt Foremny - GetPolygon_Regular



        public static cPolygon GetPolygon_Rect(cPoint xPoint, int xWidth, int xHeight)
        {
            //funkcja dodająca 4 cSegmenty do listy, z której powstaje prostokąt
            //xPoint - współrzędne punktu bazowego
            //xWidth - szerokość prostokąta
            //xHeight - wysokość prostokąta

            cPolygon pPolygon_Rect;
            cSegment pSegment;

            pPolygon_Rect = new cPolygon();

            pSegment = GetSegment(0, 0, xPoint, 1);
            pPolygon_Rect.AddSegment(pSegment, 0);

            pSegment = GetSegment(xWidth, 0, xPoint, 2);
            pPolygon_Rect.AddSegment(pSegment, 1);

            pSegment = GetSegment(xWidth, -xHeight, xPoint, 3);
            pPolygon_Rect.AddSegment(pSegment, 2);

            pSegment = GetSegment(0, -xHeight, xPoint, 4);
            pPolygon_Rect.AddSegment(pSegment, 3);

            pPolygon_Rect.ShowSegmentsList();

            return(pPolygon_Rect);
        }
Esempio n. 2
0
        public void DrawPolygon(cPolygon xPolygon, PaintEventArgs e)
        {
            //funkcja rysująca dowolny wielobok
            //xPolygon - baza punktów

            Pen pBluePen;                                   //kolor mazaka

            PointF[] pPointsLine;                           //punkty tworzące linie
            int      pCount;                                //liczba boków figury
            int      pIndexNext;                            //następny index segmentu
            int      pIndex;

            pBluePen    = new Pen(Color.Blue, 3);
            pPointsLine = new PointF[2];
            pCount      = xPolygon.Segments.Count;

            //pętla rysująca linię składającą się z dwóch punktów
            for (pIndex = 0; pIndex <= (pCount - 1); pIndex++)
            {
                pIndexNext = pIndex + 1;

                if (pIndex == (pCount - 1))                      //następcą ostatniego punktu jest punkt początkowy
                {
                    pIndexNext = 0;
                }

                cSegment pSegment      = xPolygon.GetSegmentByNumer(pIndex);
                cSegment pSegment_Next = xPolygon.GetSegmentByNumer(pIndexNext);
                //wrzucić do xPolygon^^


                if (!pSegment.IsCurve)                  //sprawdzenie lini: prosta, czy krzywa
                {
                    pPointsLine[0] = new PointF(pSegment.Point.X,
                                                pSegment.Point.Y);
                    pPointsLine[1] = new PointF(pSegment_Next.Point.X,
                                                pSegment_Next.Point.Y);
                    e.Graphics.DrawPolygon(pBluePen, pPointsLine);
                }
                else
                {
                    // DrawBezierCurve(pSegment, pSegment_Next, e);
                    //[MO 10.03.2020] funkcja chwilowo wyłączona do poprawnej kompilacji
                }
            }
        }
Esempio n. 3
0
        private void btnDrawRectangle_Click(object sender, EventArgs e)
        {
            //funkca tworząca poligon prostokąta

            double pRect_Height, pRect_Width;               //przeskalowana wysokość, szerokość prostokąta
            cPoint pStartPoint;                             //punkt bazowy

            CalculateScale();

            pStartPoint   = new cPoint(new PointF());
            pRect_Width   = int.Parse(txtWidth.Text) * (mScale);
            pRect_Height  = int.Parse(txtHeight.Text) * (mScale);
            pStartPoint.X = (pnlCanvas.Width - (int)pRect_Width) / 2;
            pStartPoint.Y = (pnlCanvas.Height - (int)pRect_Height) / 2 + (int)pRect_Height;

            mPolygon_Rect = cPolygonFactory.GetPolygon_Rect(pStartPoint, (int)pRect_Width, (int)pRect_Height);

            this.pnlCanvas.Refresh();
        }
Esempio n. 4
0
        private void btnDrawRegularPolygon_Click(object sender, EventArgs e)
        {
            //funkca tworząca poligon wielokąta foremnego

            double pBaseAngle;                              //kąt pomiędzy: punkt1 segmentu - środek koła - punkt2 segmentu
            cPoint pCircleCenter;                           //punkt - środek okręgu
            double pRadiusOfCircle;                         //przeskalowany promień koła

            CalculateScale();

            pCircleCenter   = new cPoint(new PointF());
            pCircleCenter.X = pnlCanvas.Width / 2;
            pCircleCenter.Y = pnlCanvas.Height / 2;
            pRadiusOfCircle = double.Parse(txtDiameter.Text) / 2 * (mScale);
            pBaseAngle      = 360 / int.Parse(txtSlides.Text); //dodać blokadę dzielenia przez 0

            cDrawingAdapter.CircleCenter = pCircleCenter;

            mPolygon_Regular = cPolygonFactory.GetPolygon_Regular(pCircleCenter, (int)pRadiusOfCircle, -pBaseAngle);

            this.pnlCanvas.Refresh();
        }
Esempio n. 5
0
        public static cPolygon GetPolygon_Regular(cPoint xCircleCenter, int xRadius, double xAngle)
        {
            //funkcja dodająca segmenty do listy, z której powstaje wielokąt foremny
            //xCircleCenter - środek koła, na którym wpisana jest figura
            //xRadius - promień koła w który jest wpisana figura
            //xAngle - kąt pomiędzy [punktem pPoint - środkiem koła xCircleCenter - punktem pPoint(z kolejnego segmentu)]

            double   pAngleTemp;                            //wartość kąta pomiędzy punktem pierwszego segmentu - środkiem koła - punktem kolejnego segmentu
            double   pAngleTotal;                           //kąt pAngleTemp przedstawiony w radianach
            double   pCosinusOfAngleTotal;                  //cosunus kąta pAngleTemp
            int      pNumber;                               //numer danego segmentu
            cPolygon pPolygon_Regular;
            cSegment pSegment;
            double   pSinusOfAngleTotal;                    //sinus kąta pAngleTemp
            double   pTotalSegments;                        //liczba wszystkich boków figury
            double   pAngleIncremental;

            pNumber          = 0;
            pTotalSegments   = 360 / Math.Abs(xAngle);
            pPolygon_Regular = new cPolygon();

            for (pAngleIncremental = 0; pAngleIncremental <= 360 - Math.Abs(xAngle); pAngleIncremental += Math.Abs(xAngle))
            {
                pAngleTemp           = xAngle / 2 + (Math.Abs(xAngle)) * pNumber;
                pAngleTotal          = (pAngleTemp * (Math.PI)) / 180;
                pCosinusOfAngleTotal = Math.Cos(pAngleTotal);
                pSinusOfAngleTotal   = Math.Sin(pAngleTotal);
                pNumber++;

                pSegment = GetSegment((int)(xRadius * pSinusOfAngleTotal), (int)(xRadius * pCosinusOfAngleTotal),
                                      xCircleCenter, pNumber);

                pPolygon_Regular.AddSegment(pSegment, pNumber - 1);
            }

            return(pPolygon_Regular);
        }