Ejemplo n.º 1
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            BinaryFormatter formatter = new BinaryFormatter();

            SaveFileDialog saveDialog = new SaveFileDialog();

            GraphicPoint point = new GraphicPoint(0, 0);

            point.X = 0;
            point.Y = 0;
            point.Z = 0;
            //selectableGraphicObjects
            List <object> allInfo = new List <object>();

            allInfo.Add(Rxyz);
            allInfo.Add(RxyzLocal);
            allInfo.Add(point);
            allInfo.Add(selectableGraphicObjects);

            saveDialog.DefaultExt = "dat";
            saveDialog.ShowDialog();


            using (FileStream fs = new FileStream(saveDialog.FileName, FileMode.OpenOrCreate))
            {
                formatter.Serialize(fs, allInfo);
            }
        }
Ejemplo n.º 2
0
        public Line(int maxX, int maxY)
        {
            int x = rand.Next(0, maxX);
            int y = rand.Next(0, maxY);

            A = new GraphicPoint(x, y);

            x = rand.Next(0, maxX);
            y = rand.Next(0, maxY);
            B = new GraphicPoint(x, y);
        }
Ejemplo n.º 3
0
        private Line[] SetAxes(float x, float y, float z)
        {
            GraphicPoint gpX1 = new GraphicPoint(1, 1);

            gpX1.point = new PointF(x + 100000, y);
            gpX1.z     = z;

            GraphicPoint gpX2 = new GraphicPoint(1, 1);

            gpX2.point = new PointF(x - 100000, y);
            gpX2.z     = z;

            GraphicPoint gpY1 = new GraphicPoint(1, 1);

            gpY1.point = new PointF(x, y + 100000);
            gpY1.z     = z;

            GraphicPoint gpY2 = new GraphicPoint(1, 1);

            gpY2.point = new PointF(x, y - 100000);
            gpY2.z     = z;

            GraphicPoint gpZ1 = new GraphicPoint(1, 1);

            gpZ1.point = new PointF(x, y);
            gpZ1.z     = z - 100000;

            GraphicPoint gpZ2 = new GraphicPoint(1, 1);

            gpZ2.point = new PointF(x, y);
            gpZ2.z     = z + 100000;


            PointF nullPointZ1 = new PointF(x, y);
            PointF nullPointZ2 = new PointF(x, y);

            AxisLines[0] = new Line(gpX1, gpX2);
            AxisLines[1] = new Line(gpY1, gpY2);
            AxisLines[2] = new Line(gpZ1, gpZ2);

            //TODO: перевычислить X и Y относительно матрицы изменений
            //for (int i = 0; i < 3; i++)
            //{
            //lines[i].A = ApplyMatrix(lines[i].A,);
            //lines[i].B = ApplyMatrix(lines[i].A,);
            //}

            return(AxisLines);
            //throw new NotImplementedException();
        }
Ejemplo n.º 4
0
        public override void ApplyMatrixLocal(float[][] matrix)
        {
            GraphicPoint changedPoint = new GraphicPoint(1, 1);

            float[] pointData = new float[] { this.X, this.Y, this.Z, 1 };//{ point.X, point.Y, point.Z, 1 };//
            float   pqrs      = 0;

            for (int i = 0; i < 4; i++)
            {
                switch (i)
                {
                case 0: { changedPoint.X = ApplyRow(pointData, GetColumn(matrix, i)); break; }

                case 1: { changedPoint.Y = ApplyRow(pointData, GetColumn(matrix, i)); break; }

                case 2: { changedPoint.Z = ApplyRow(pointData, GetColumn(matrix, i)); break; }

                case 3: { pqrs = ApplyRow(pointData, GetColumn(matrix, i)); break; }
                }
            }
            //changedPoint.X = tempX;
            //changedPoint.Y = tempY;
            for (int i = 0; i < 3; i++)
            {
                switch (i)
                {
                case 0: { changedPoint.X = changedPoint.point.X / pqrs; break; }

                case 1: { changedPoint.Y = changedPoint.point.Y / pqrs; break; }

                case 2: { changedPoint.Z = changedPoint.Z / pqrs; break; }
                }
            }
            //changedPoint.X = tempX;
            //changedPoint.Y = tempY;
            changedPoint.point = new PointF(changedPoint.point.X - GraphicObject.NullPoint.X, changedPoint.point.Y - GraphicObject.NullPoint.Y);
            changedPoint.z    -= NullZ;
            this.point         = changedPoint.point;
            this.z             = changedPoint.z;
            //this.X = changedPoint.X;
            //this.Y = changedPoint.Y;
            //this.Z = changedPoint.Z;
        }
Ejemplo n.º 5
0
        public override void ApplyMatrix(float[][] matrix)
        {
            GraphicPoint point        = this;
            GraphicPoint changedPoint = new GraphicPoint(1, 1);

            float[] pointData = new float[] { point.pointBeforeChanges.X, point.pointBeforeChanges.Y, point.zBeforeChanges, 1 };//{ point.X, point.Y, point.Z, 1 };//
            float   pqrs = 0;
            float   tempX = 0, tempY = 0;

            for (int i = 0; i < 4; i++)
            {
                switch (i)
                {
                case 0: { tempX = ApplyRow(pointData, GetColumn(matrix, i)); break; }

                case 1: { tempY = ApplyRow(pointData, GetColumn(matrix, i)); break; }

                case 2: { changedPoint.z = ApplyRow(pointData, GetColumn(matrix, i)); break; }

                case 3: { pqrs = ApplyRow(pointData, GetColumn(matrix, i)); break; }
                }
            }
            changedPoint.point = new PointF(tempX, tempY);
            //changedPoint.X = tempX;
            //changedPoint.Y = tempY;
            for (int i = 0; i < 3; i++)
            {
                switch (i)
                {
                case 0: { tempX = changedPoint.point.X / pqrs; break; }

                case 1: { tempY = changedPoint.point.Y / pqrs; break; }

                case 2: { changedPoint.z = changedPoint.z / pqrs; break; }
                }
            }
            changedPoint.point = new PointF(tempX, tempY);
            //changedPoint.X = tempX;
            //changedPoint.Y = tempY;

            this.point = changedPoint.point;
            this.z     = changedPoint.z;
        }
Ejemplo n.º 6
0
        //TODO: понять, как получить реальную высоту объекта graphics
        public override string GetInfo(Size size)
        {
            //Параметры прямой
            float A = -1, B = -1, C = -1;

            //Координаты точек
            float Ax = this.A.X, Ay = this.A.Y; //size.Height - this.A.Y;
            float Bx = this.B.X, By = this.B.Y; // size.Height - this.B.Y;

            //Вычисляем параметры прямой
            A = Ay - By;
            B = Bx - Ax;
            C = Ax * By - Ay * Bx;
            //return "x:" + this.A.X.ToString() + " y: " + this.A.Y.ToString();
            string pointA = this.A.GetInfo(size);
            string pointB = this.B.GetInfo(size);

            return("A:" + A.ToString() + " B: " + B.ToString() + " C: " + C.ToString() + "\n" +
                   "Точка А: " + pointA + "\n" + "Точка B: " + pointB + "\n");
        }
Ejemplo n.º 7
0
        private GraphicPoint ApplyMatrix(GraphicPoint point, float[][] matrix)
        {
            GraphicPoint changedPoint = new GraphicPoint(1, 1);

            float[] pointData = new float[] { point.point.X, point.point.Y, point.z, 1 };//{ point.X, point.Y, point.Z, 1 };//
            float   pqrs = 0;
            float   tempX = 0, tempY = 0;

            for (int i = 0; i < 4; i++)
            {
                switch (i)
                {
                case 0: { tempX = ApplyRow(pointData, GetColumn(matrix, i)); break; }

                case 1: { tempY = ApplyRow(pointData, GetColumn(matrix, i)); break; }

                case 2: { changedPoint.z = ApplyRow(pointData, GetColumn(matrix, i)); break; }

                case 3: { pqrs = ApplyRow(pointData, GetColumn(matrix, i)); break; }
                }
            }
            changedPoint.point = new PointF(tempX, tempY);
            //changedPoint.X = tempX;
            //changedPoint.Y = tempY;
            for (int i = 0; i < 3; i++)
            {
                switch (i)
                {
                case 0: { tempX = changedPoint.point.X / pqrs; break; }

                case 1: { tempY = changedPoint.point.Y / pqrs; break; }

                case 2: { changedPoint.z = changedPoint.z / pqrs; break; }
                }
            }
            changedPoint.point = new PointF(tempX, tempY);
            //changedPoint.X = tempX;
            //changedPoint.Y = tempY;
            return(changedPoint);
        }
Ejemplo n.º 8
0
 public Line(PointF A, PointF B)
 {
     this.A = new GraphicPoint(A.X, A.Y);
     this.B = new GraphicPoint(B.X, B.Y);
 }
Ejemplo n.º 9
0
        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            Pen        specPen        = new Pen(Color.OrangeRed, 3);
            SolidBrush solidBrushSpec = new SolidBrush(Color.Orange);

            foreach (var obj in selectableGraphicObjects)
            {
                if (obj is Line)
                {
                    Line line = (Line)obj;
                    if (line != selectedObj)
                    {
                        line.DrawObject(e.Graphics, null, null);
                    }
                    else
                    {
                        line.DrawObject(e.Graphics, specPen, solidBrushSpec);
                    }
                }
                if (obj is GraphicGroup)
                {
                    if (obj != selectedObj)
                    {
                        obj.DrawObject(e.Graphics, null, null);
                    }
                    else
                    {
                        obj.DrawObject(e.Graphics, specPen, solidBrushSpec);
                    }
                }
                if (!(selectedObj is null))
                {
                    selectedObj.DrawObject(e.Graphics, specPen, solidBrushSpec);
                }
            }
            if (morph)
            {
                for (int j = 0; j < pointsA.Count; j += 2)
                {
                    GraphicPoint Ap = new GraphicPoint(1, 1);
                    GraphicPoint Bp = new GraphicPoint(1, 1);

                    PointF pA = new PointF((pointsA[j].point.X * curT / T + pointsB[j].point.X * (T - curT) / T), (pointsA[j].point.Y * curT / T + pointsB[j].point.Y * (T - curT) / T));
                    PointF pB = new PointF((pointsA[j + 1].point.X * curT / T + pointsB[j + 1].point.X * (T - curT) / T), (pointsA[j + 1].point.Y * curT / T + pointsB[j + 1].point.Y * (T - curT) / T));

                    Ap.point = pA;
                    Ap.z     = (pointsA[j].z * curT / T + pointsB[j].z * (T - curT) / T);

                    Bp.point = pB;
                    Bp.z     = (pointsA[j + 1].z * curT / T + pointsB[j + 1].z * (T - curT) / T);

                    Line newLine = new Line(0, 0);
                    newLine.A = Ap;
                    newLine.B = Bp;
                    newLine.DrawObject(e.Graphics, null, null);
                }
            }

            if (checkBoxAxes.Checked)
            {
                float  nullX = GraphicObject.NullPoint.X;
                float  nullY = GraphicObject.NullPoint.Y;
                float  nullZ = GraphicObject.NullZ;
                Line[] axes  = AxisLines;

                for (int i = 0; i < 3; i++)
                {
                    switch (i)
                    {
                    case 0: specPen = new Pen(Color.LightBlue, 3); solidBrushSpec = new SolidBrush(Color.LightBlue); break;

                    case 1: specPen = new Pen(Color.PaleVioletRed, 3); solidBrushSpec = new SolidBrush(Color.PaleVioletRed); break;

                    case 2: specPen = new Pen(Color.LightGreen, 3); solidBrushSpec = new SolidBrush(Color.LightGreen); break;
                    }
                    axes[i].DrawObject(e.Graphics, specPen, solidBrushSpec);
                }
            }
        }
Ejemplo n.º 10
0
        //Сканирование рисунка на клик по объекту
        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            isMouseDown = true;
            //selectMode = -1;


            //Координаты клика
            float clckX = e.Location.X;
            float clckY = e.Location.Y;

            if (mhb != 0 && selectedObj != null && selectedObj is GraphicObject)
            {
                Point loc = e.Location;
                switch (mhb)
                {
                case 1:
                    if (selectedObj is Line)
                    {
                        Line median = new Line(loc, new PointF(
                                                   ((selectedObj as Line).A.point.X + (selectedObj as Line).B.point.X) / 2,
                                                   ((selectedObj as Line).A.point.Y + (selectedObj as Line).B.point.Y) / 2));
                        median.A.z = ((selectedObj as Line).A.z + (selectedObj as Line).B.z) / 2;

                        selectableGraphicObjects.Add(median);
                    }
                    break;

                case 2:
                    if (selectedObj is Line)
                    {
                        //Через x1, y1
                        //A(y-y1)-B(x-x1)=0

                        //Координаты точек
                        float Ax = (selectedObj as Line).A.point.X, Ay = (selectedObj as Line).A.point.Y;
                        float Bx = (selectedObj as Line).B.point.X, By = (selectedObj as Line).B.point.Y;

                        //Вычисляем параметры прямой
                        float A = By - Ay;
                        float B = Ax - Bx;
                        float C = -Ay * B - Ax * A;
                        float d = (float)((Math.Abs(A * clckX + B * clckY + C)) / Math.Sqrt(A * A + B * B));

                        float Aheight = B;
                        float Bheight = -A;
                        float Cheight = -Aheight * loc.X - Bheight * loc.Y;

                        Line height = new Line(loc, GetIntersection(A, B, C, Aheight, Bheight, Cheight));

                        selectableGraphicObjects.Add(height);
                    }
                    break;

                case 3:
                    if (selectedObj is GraphicGroup)
                    {
                        Line Aline = (Line)(selectedObj as GraphicGroup).objectsGroup[0];
                        Line Bline = (Line)(selectedObj as GraphicGroup).objectsGroup[1];

                        float AlineX = Aline.A.point.X - Aline.B.point.X;
                        float AlineY = Aline.A.point.Y - Aline.B.point.Y;
                        float Alen   = (float)Math.Sqrt(Math.Pow(AlineX, 2) + Math.Pow(AlineY, 2));

                        float BlineX = Bline.A.point.X - Bline.B.point.X;
                        float BlineY = Bline.A.point.Y - Bline.B.point.Y;
                        float Blen   = (float)Math.Sqrt(Math.Pow(BlineX, 2) + Math.Pow(BlineY, 2));

                        PointF bissectrPoint = new PointF(AlineX * 100 / Alen + BlineX * 100 / Blen + Aline.A.point.X, AlineY * 100 / Alen + BlineY * 100 / Blen + Aline.A.point.Y);
                        Line   bissectr      = new Line(new PointF(Aline.A.point.X, Aline.A.point.Y), bissectrPoint);

                        selectableGraphicObjects.Add(bissectr);

                        /*
                         *
                         * float Alen = (float)Math.Sqrt(Math.Pow(A.A.point.X - A.B.point.X, 2) + Math.Pow(A.A.point.Y - A.B.point.Y, 2));
                         * float Blen = (float)Math.Sqrt(Math.Pow(B.A.point.X - B.B.point.X, 2) + Math.Pow(B.A.point.Y - B.B.point.Y, 2));
                         * float newX = A.A.point.X + (Alen/Blen)*
                         */
                    }
                    break;
                }
                mhb = 0;
            }

            if (selectMode != 1)
            {
                selectedPoint = new GraphicPoint(clckX, clckY);
                selectedObj   = null;

                foreach (var obj in selectableGraphicObjects)
                {
                    if (obj.ChangeSelection(clckX, clckY))
                    {
                        if (selectMode == -1)
                        {
                            selectedObj = obj;
                        }
                    }
                    //selectMode = 1;


                    /*if (obj is Line)
                     *  if ((obj as Line).ChangeSelection(clckX, clckY))
                     *  {
                     *      selectedObj = obj;
                     *      selectMode = 1;
                     *  }
                     *
                     * key = -1;
                     *  if (System.Windows.Input.Keyboard.IsKeyDown(System.Windows.Input.Key.LeftCtrl))
                     *  {
                     *      if (key == (int)System.Windows.Input.Key.LeftCtrl)
                     *          ;
                     *
                     *      key = (int)System.Windows.Input.Key.LeftCtrl;
                     *  };
                     * else
                     * }
                     */
                }
                if (e.Button == MouseButtons.Right &&
                    selectedObj != null &&
                    ((selectedObj as Line).A.isSelected || (selectedObj as Line).B.isSelected))
                {
                    GraphicPoint selectedPoint = (selectedObj as Line).A.isSelected ? (selectedObj as Line).A : (selectedObj as Line).B;
                    pictureBox1.ContextMenuStrip.Items[0].Text = "X: " + selectedPoint.X.ToString();
                    pictureBox1.ContextMenuStrip.Items[1].Text = "Y: " + selectedPoint.Y.ToString();
                    pictureBox1.ContextMenuStrip.Items[2].Text = "Z: " + selectedPoint.Z.ToString();
                    isMouseDown      = false;
                    isRightClickLast = true;
                    rcmPoint         = selectedPoint;
                }
                else
                {
                    pictureBox1.ContextMenuStrip.Visible = false;
                    isRightClickLast = false;
                    rcmPoint         = null;
                }
            }
            if (selectMode == 1 && selectedObj is GraphicGroup)
            {
                foreach (var obj in selectableGraphicObjects)
                {
                    if (obj.CheckSelection(clckX, clckY))
                    {
                        (selectedObj as GraphicGroup).Add(obj);
                    }
                }
            }

            if (selectMode == 2)
            {
                bool checker = false;
                foreach (var obj in selectableGraphicObjects)
                {
                    if (obj.CheckSelection(clckX, clckY))
                    {
                        checker = true;
                        if (A == null)
                        {
                            A = obj;
                        }
                        else
                        {
                            B = obj;
                        }
                    }
                }

                if (!checker)
                {
                    A = null;
                    B = null;
                }
            }
        }