Пример #1
0
        public static List <Point> DDA(Point point1, Point point2)
        {
            Point        point3 = new Point(point1.X, point2.Y);
            Point        point4 = new Point(point2.X, point1.Y);
            List <Point> points = new List <Point>();
            List <Point> temp   = new List <Point>();

            temp = DrawLine.DDA(point1, point3);
            points.AddRange(temp);
            temp = DrawLine.DDA(point1, point4);
            points.AddRange(temp);
            temp = DrawLine.DDA(point4, point2);
            points.AddRange(temp);
            temp = DrawLine.DDA(point2, point3);
            points.AddRange(temp);
            return(points);
        }
Пример #2
0
        private void DrawArrow(PointF ArrowStart, PointF ArrowEnd, int ArrowMultiplier)
        {
            //tip of the arrow
            PointF arrowPoint = ArrowEnd;

            //determine arrow length
            double arrowLength = Math.Sqrt(Math.Pow(Math.Abs(ArrowStart.X - ArrowEnd.X), 2) +
                                           Math.Pow(Math.Abs(ArrowStart.Y - ArrowEnd.Y), 2));

            //determine arrow angle
            double arrowAngle = Math.Atan2(Math.Abs(ArrowStart.Y - ArrowEnd.Y), Math.Abs(ArrowStart.X - ArrowEnd.X));

            //get the x,y of the back of the point

            //to change from an arrow to a diamond, change the 3
            //in the next if/else blocks to 6

            double pointX, pointY;

            if (ArrowStart.X > ArrowEnd.X)
            {
                pointX = ArrowStart.X - (Math.Cos(arrowAngle) * (arrowLength - (3 * ArrowMultiplier)));
            }
            else
            {
                pointX = Math.Cos(arrowAngle) * (arrowLength - (3 * ArrowMultiplier)) + ArrowStart.X;
            }

            if (ArrowStart.Y > ArrowEnd.Y)
            {
                pointY = ArrowStart.Y - (Math.Sin(arrowAngle) * (arrowLength - (3 * ArrowMultiplier)));
            }
            else
            {
                pointY = (Math.Sin(arrowAngle) * (arrowLength - (3 * ArrowMultiplier))) + ArrowStart.Y;
            }

            PointF arrowPointBack = new PointF((float)pointX, (float)pointY);

            //get the secondary angle of the left tip
            double angleB = Math.Atan2((3 * ArrowMultiplier), (arrowLength - (3 * ArrowMultiplier)));

            double angleC = Math.PI * (90 - (arrowAngle * (180 / Math.PI)) - (angleB * (180 / Math.PI))) / 180;

            //get the secondary length
            double secondaryLength = (3 * ArrowMultiplier) / Math.Sin(angleB);

            if (ArrowStart.X > ArrowEnd.X)
            {
                pointX = ArrowStart.X - (Math.Sin(angleC) * secondaryLength);
            }
            else
            {
                pointX = (Math.Sin(angleC) * secondaryLength) + ArrowStart.X;
            }

            if (ArrowStart.Y > ArrowEnd.Y)
            {
                pointY = ArrowStart.Y - (Math.Cos(angleC) * secondaryLength);
            }
            else
            {
                pointY = (Math.Cos(angleC) * secondaryLength) + ArrowStart.Y;
            }

            //get the left point
            PointF arrowPointLeft = new PointF((float)pointX, (float)pointY);

            //move to the right point
            angleC = arrowAngle - angleB;

            if (ArrowStart.X > ArrowEnd.X)
            {
                pointX = ArrowStart.X - (Math.Cos(angleC) * secondaryLength);
            }
            else
            {
                pointX = (Math.Cos(angleC) * secondaryLength) + ArrowStart.X;
            }

            if (ArrowStart.Y > ArrowEnd.Y)
            {
                pointY = ArrowStart.Y - (Math.Sin(angleC) * secondaryLength);
            }
            else
            {
                pointY = (Math.Sin(angleC) * secondaryLength) + ArrowStart.Y;
            }

            PointF arrowPointRight = new PointF((float)pointX, (float)pointY);

            //create the point list
            PointF[] arrowPoints = new PointF[4];
            arrowPoints[0] = arrowPoint;
            arrowPoints[1] = arrowPointLeft;
            arrowPoints[2] = arrowPointBack;
            arrowPoints[3] = arrowPointRight;
            Point arrowPointInt      = new Point((int)Math.Round(arrowPoint.X), (int)Math.Round(arrowPoint.Y));
            Point arrowPointBackInt  = new Point((int)Math.Round(arrowPointBack.X), (int)Math.Round(arrowPointBack.Y));
            Point arrowPointLeftInt  = new Point((int)Math.Round(arrowPointLeft.X), (int)Math.Round(arrowPointLeft.Y));
            Point arrowPointRightInt = new Point((int)Math.Round(arrowPointRight.X), (int)Math.Round(arrowPointRight.Y));

            List <Point> points = DrawLine.DDA(arrowPointInt, arrowPointLeftInt);

            DrawMyShape(points, 1);

            points = DrawLine.DDA(arrowPointInt, arrowPointRightInt);
            DrawMyShape(points, 1);

            points = DrawLine.DDA(arrowPointLeftInt, arrowPointBackInt);
            DrawMyShape(points, 1);

            points = DrawLine.DDA(arrowPointRightInt, arrowPointBackInt);
            DrawMyShape(points, 1);

            //draw the outline
            //g.DrawPolygon(pen, arrowPoints);

            //fill the polygon
            //g.FillPolygon(new SolidBrush(pen.Color), arrowPoints);
        }
Пример #3
0
        private void drawPanel_MouseDown(object sender, MouseEventArgs e)
        {
            // xu ly ve doan thang
            if (drawLine == false)
            {
                moving   = true;
                point1.X = e.X;
                point1.Y = e.Y;
            }
            else
            {
                Label label = new Label();
                Point point = MyCoordinate.ConvertToMyPoint(new Point(e.X, e.Y));
                label.Location = new Point(e.X + 10, e.Y);
                label.Text     = "(" + MyCoordinate.ConvertToMyPoint(point).X + ", " + MyCoordinate.ConvertToMyPoint(point).Y + ")";
                label.Text     = "(" + point.X + ", " + point.Y + ")";
                label.SendToBack();
                label.ForeColor = Color.Red;
                label.AutoSize  = true;
                drawPanel.Controls.Add(label);
                label.Show();
                if (isPoint1 == false)
                {
                    this.transformationComboBox.Enabled = false;
                    point1.X = e.X;
                    point1.Y = e.Y;
                    isPoint1 = true;
                    if (isEllipseCenter == false && lineStyleComboBox.SelectedIndex == 6)
                    {
                        centerPoint     = point1;
                        isPoint1        = false;
                        isEllipseCenter = true;
                    }
                }
                else if (isPoint1 && !isPoint2)
                {
                    this.transformationComboBox.Enabled = true;
                    point2.X = e.X;
                    point2.Y = e.Y;
                    isPoint2 = true;
                    Point        firstPoint   = point1;
                    Point        seccondPoint = point2;
                    List <Point> points       = DrawLine.DDA(firstPoint, seccondPoint);

                    switch (lineStyleComboBox.SelectedIndex)
                    {
                    case 0:
                    {
                        DrawMyShape(points);
                        if (hasArrowCheckBox.Checked)
                        {
                            DrawArrow(point1, point2, 3);
                        }
                        break;
                    }

                    case 1:
                    {
                        points = DrawLine.DashLine(points);
                        DrawMyShape(points, 1);
                        if (hasArrowCheckBox.Checked)
                        {
                            DrawArrow(point1, point2, 3);
                        }
                        break;
                    }

                    case 2:
                    {
                        points = DrawLine.DashedLineWithOneDot(points);
                        DrawMyShape(points, 1);
                        if (hasArrowCheckBox.Checked)
                        {
                            DrawArrow(point1, point2, 3);
                        }

                        break;
                    }

                    case 3:
                    {
                        points = DrawLine.DashLineWithTwoDot(points);
                        DrawMyShape(points, 1);
                        if (hasArrowCheckBox.Checked)
                        {
                            DrawArrow(point1, point2, 3);
                        }
                        break;
                    }

                    case 4:
                    {
                        points = DrawRecangle.DDA(point1, point2);
                        DrawMyShape(points);
                        break;
                    }

                    case 5:
                    {
                        int radius = (int)Math.Sqrt(Math.Pow(point2.X - point1.X, 2) + Math.Pow(point2.Y - point1.Y, 2));
                        points = DrawCircle.circleBrese(point1.X, point1.Y, radius);
                        DrawMyShape(points);
                        break;
                    }

                    case 6:
                    {
                        int radiusX = (int)Math.Sqrt(Math.Pow(point1.X - centerPoint.X, 2) + Math.Pow(point1.Y - centerPoint.Y, 2));
                        int radiusY = (int)Math.Sqrt(Math.Pow(point2.X - centerPoint.X, 2) + Math.Pow(point2.Y - centerPoint.Y, 2));;
                        points = DrawEllipse.MidPoint(centerPoint, radiusX, radiusY);
                        DrawMyShape(points);
                        isEllipseCenter = false;
                        break;
                    }

                    default:
                        break;
                    }

                    shapesPoints.Add(points);
                    defaultPoints = shapesPoints.ElementAt(shapesPoints.Count - 1);
                    isPoint1      = isPoint2 = false;
                }
            }
        }