Exemplo n.º 1
0
        public PointF[] GetNormalisedOutline(float xmin, float xmax, float ymin, float ymax, Size screensize)
        {
            PointF[] normoutline = new PointF[Outline.Length];

            for (int i = 0; i < Outline.Length; i++)
            {
                normoutline[i].X = Normalisation.NormaliseX(Outline[i].X, xmin, xmax, screensize.Width);
                normoutline[i].Y = Normalisation.NormaliseY(Outline[i].Y, ymin, ymax, screensize.Height);
            }

            return(normoutline);
        }
Exemplo n.º 2
0
        public cg_lr3()
        {
            InitializeComponent();

            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

            OldTransVals = new PointF3D();
            TransVals    = new PointF3D();
            ScalVal      = OldScalVal = 1;
            XRotValue    = ZRotValue = YRotValue = OldXRotValue = OldYRotValue = OldZRotValue = 0;

            // Lower pentagon
            PointF3D LowerP1 = new PointF3D(1, 0, 0);
            PointF3D LowerP2 = new PointF3D(0, 0, 3);
            PointF3D LowerP3 = new PointF3D(2.5f, 0, 4.8f);
            PointF3D LowerP4 = new PointF3D(5, 0, 3);
            PointF3D LowerP5 = new PointF3D(4, 0, 0);

            // Upper pentagon
            PointF3D UpperP1 = new PointF3D(1.5f, 5, 1);
            PointF3D UpperP2 = new PointF3D(1.1f, 5, 2.6f);
            PointF3D UpperP3 = new PointF3D(2.5f, 5, 3.9f);
            PointF3D UpperP4 = new PointF3D(4.1f, 5, 2.6f);
            PointF3D UpperP5 = new PointF3D(3.5f, 5, 1f);

            InitObj = new Polygon3D[]   //pyramid
            {
                // lower pentagon
                new Polygon3D(new PointF3D[] { LowerP1, LowerP2, LowerP3, LowerP4, LowerP5 }),
                // lines connecting the pentagons
                new Polygon3D(new PointF3D[] { LowerP1, UpperP1 }),
                new Polygon3D(new PointF3D[] { LowerP2, UpperP2 }),
                new Polygon3D(new PointF3D[] { LowerP3, UpperP3 }),
                new Polygon3D(new PointF3D[] { LowerP4, UpperP4 }),
                new Polygon3D(new PointF3D[] { LowerP5, UpperP5 }),
                //upper pentagon
                new Polygon3D(new PointF3D[] { UpperP1, UpperP2, UpperP3, UpperP4, UpperP5 })
            };
            obj = (Polygon3D[])InitObj.Clone();

            InitObjCentre = new PointF3D(2, 2, 2);
            objCentre     = InitObjCentre;

            InitCntrlPoints = new PointF3D[4, 4]
            {
                { new PointF3D(0, 0, 0), new PointF3D(1, 0, 0), new PointF3D(2, 0, 0), new PointF3D(3, 0, 0) },
                { new PointF3D(0, 0, 1), new PointF3D(1, 0, 1), new PointF3D(2, 0, 1), new PointF3D(3, 0, 1) },
                { new PointF3D(0, 0, 2), new PointF3D(1, 0, 2), new PointF3D(2, 0, 2), new PointF3D(3, 0, 2) },
                { new PointF3D(0, 0, 3), new PointF3D(1, 0, 3), new PointF3D(2, 0, 3), new PointF3D(3, 0, 3) }
            };

            bs             = new BezierSurface(InitCntrlPoints, 0.2);
            InitSurfCentre = new PointF3D(1.5f, 0, 1.5f);
            SurfCentre     = InitSurfCentre;
            RedactCPIndex  = new Point(-1, -1);
            DefaultTransformVals();

            PointF[] ProjectedDimAxes = Affinity3D.ProjectDimetric(CoordinateLines);
            PointF[] ProjectedXYAxes  = Affinity3D.ProjectToXY(CoordinateLines);
            PointF[] ProjectedYZAxes  = Affinity3D.ProjectToYZ(CoordinateLines);
            PointF[] ProjectedZXAxes  = Affinity3D.ProjectToZX(CoordinateLines);

            NormalisedDimetricAxes = new Point[ProjectedDimAxes.Length];
            NormalisedXYAxes       = new Point[ProjectedXYAxes.Length];
            NormalisedYZAxes       = new Point[ProjectedYZAxes.Length];
            NormalisedZXAxes       = new Point[ProjectedZXAxes.Length];

            for (int i = 0; i < CoordinateLines.Length; i++)
            {
                NormalisedDimetricAxes[i].X = Normalisation.NormaliseX(ProjectedDimAxes[i].X, DimetricMinBorder, DimetricMaxBorder, paneldimetric.Width);
                NormalisedDimetricAxes[i].Y = Normalisation.NormaliseY(ProjectedDimAxes[i].Y, DimetricMinBorder, DimetricMaxBorder, paneldimetric.Height);
                NormalisedXYAxes[i].X       = Normalisation.NormaliseX(ProjectedXYAxes[i].X, SideProjMinBorder, SideProjMaxBorder, panelxy.Width);
                NormalisedXYAxes[i].Y       = Normalisation.NormaliseY(ProjectedXYAxes[i].Y, SideProjMinBorder, SideProjMaxBorder, panelxy.Height);
                NormalisedYZAxes[i].X       = Normalisation.NormaliseX(ProjectedYZAxes[i].X, SideProjMinBorder, SideProjMaxBorder, panelyz.Width);
                NormalisedYZAxes[i].Y       = Normalisation.NormaliseY(ProjectedYZAxes[i].Y, SideProjMinBorder, SideProjMaxBorder, panelyz.Height);
                NormalisedZXAxes[i].X       = Normalisation.NormaliseX(ProjectedZXAxes[i].X, SideProjMinBorder, SideProjMaxBorder, panelzx.Width);
                NormalisedZXAxes[i].Y       = Normalisation.NormaliseY(ProjectedZXAxes[i].Y, SideProjMinBorder, SideProjMaxBorder, panelzx.Height);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Draws Bezier surface to the Graphics object.
        /// </summary>
        /// <param name="g">0 - dimetric, 1 - xy, 2 - yz, 3 - zx</param>
        private void DrawSurface(Graphics g, int drawTo)
        {
            int PointCount = bs.DrawPoints.GetLength(0);

            PointF3D[] Surfpoints = new PointF3D[PointCount * PointCount];
            PointF[]   prSurfPoints;
            Point[]    nPrSurfPoints = new Point[Surfpoints.Length];

            switch (drawTo)
            {
            case 0:
                prSurfPoints = bs.ProjectDimetric();
                for (int i = 0; i < nPrSurfPoints.Length; i++)
                {
                    nPrSurfPoints[i].X = Normalisation.NormaliseX(prSurfPoints[i].X, DimetricMinBorder, DimetricMaxBorder, paneldimetric.Width);
                    nPrSurfPoints[i].Y = Normalisation.NormaliseY(prSurfPoints[i].Y, DimetricMinBorder, DimetricMaxBorder, paneldimetric.Height);
                }
                break;

            case 1:
                prSurfPoints = bs.ProjectXY();
                for (int i = 0; i < nPrSurfPoints.Length; i++)
                {
                    nPrSurfPoints[i].X = Normalisation.NormaliseX(prSurfPoints[i].X, SideProjMinBorder, SideProjMaxBorder, panelxy.Width);
                    nPrSurfPoints[i].Y = Normalisation.NormaliseY(prSurfPoints[i].Y, SideProjMinBorder, SideProjMaxBorder, panelxy.Height);
                }
                break;

            case 2:
                prSurfPoints = bs.ProjectYZ();
                for (int i = 0; i < nPrSurfPoints.Length; i++)
                {
                    nPrSurfPoints[i].X = Normalisation.NormaliseX(prSurfPoints[i].X, SideProjMinBorder, SideProjMaxBorder, panelyz.Width);
                    nPrSurfPoints[i].Y = Normalisation.NormaliseY(prSurfPoints[i].Y, SideProjMinBorder, SideProjMaxBorder, panelyz.Height);
                }
                break;

            case 3:
                prSurfPoints = bs.ProjectZX();
                for (int i = 0; i < nPrSurfPoints.Length; i++)
                {
                    nPrSurfPoints[i].X = Normalisation.NormaliseX(prSurfPoints[i].X, SideProjMinBorder, SideProjMaxBorder, panelzx.Width);
                    nPrSurfPoints[i].Y = Normalisation.NormaliseY(prSurfPoints[i].Y, SideProjMinBorder, SideProjMaxBorder, panelzx.Height);
                }
                break;
            }

            Point[,] nPrSP2Dim = new Point[PointCount, PointCount];
            for (int r = 0; r < PointCount; r++)
            {
                for (int c = 0; c < PointCount; c++)
                {
                    nPrSP2Dim[r, c] = nPrSurfPoints[r * PointCount + c];
                }
            }

            Pen pen = new Pen(Color.Red);

            for (int r = 0; r < PointCount - 1; r++)
            {
                for (int c = 0; c < PointCount - 1; c++)
                {
                    g.DrawLine(pen, nPrSP2Dim[r, c], nPrSP2Dim[r, c + 1]);
                    g.DrawLine(pen, nPrSP2Dim[r, c], nPrSP2Dim[r + 1, c]);
                }
            }
            for (int i = 0; i < PointCount - 1; i++)
            {
                g.DrawLine(pen, nPrSP2Dim[i, PointCount - 1], nPrSP2Dim[i + 1, PointCount - 1]);
                g.DrawLine(pen, nPrSP2Dim[PointCount - 1, i], nPrSP2Dim[PointCount - 1, i + 1]);
            }

            if (checkBox1.Checked)
            {
                PointF     cp        = new Point();
                SolidBrush brush     = new SolidBrush(Color.Black);
                int        circleRad = 3;
                for (int r = 0; r < 4; r++)
                {
                    for (int c = 0; c < 4; c++)
                    {
                        cp   = Affinity3D.ProjectDimetric(new PointF3D[] { bs.ControlPoints[r, c] })[0];
                        cp.X = Normalisation.NormaliseX(cp.X, DimetricMinBorder, DimetricMaxBorder, paneldimetric.Width);
                        cp.Y = Normalisation.NormaliseY(cp.Y, DimetricMinBorder, DimetricMaxBorder, paneldimetric.Height);

                        g.FillEllipse(brush, cp.X - circleRad, cp.Y - circleRad, circleRad * 2, circleRad * 2);
                        g.DrawString("P" + (r + 1) + (c + 1), Font, brush, cp);
                    }
                }
            }
        }