コード例 #1
0
        private void CalculateRoundLines(CornersLine line1, CornersLine line2,
                                         CornersArc arc)
        {
            double f1   = Math.Atan2(line1.Y1 - line1.Y2, line1.X1 - line1.X2);
            double f2   = Math.Atan2(line2.Y2 - line2.Y1, line2.X2 - line2.X1);
            double alfa = f2 - f1;

            if ((alfa == 0) || (Math.Abs(alfa) == Math.PI))
            {
                addWithoutArc(arc);
            }
            else
            {
                addWithArc(line1, line2, arc, f1, f2, alfa);
            }
        }
コード例 #2
0
        private void fillList()
        {
            CornersLine line;

            switch (points.Length)
            {
            case 2:
                line = new CornersLine();
                list.Add(line);
                line.X1 = points[0].X;
                line.Y1 = points[0].Y;
                line.X2 = points[1].X;
                line.Y2 = points[1].Y;
                break;

            default:
                PointF firstPoint = new PointF(points[0].X, points[0].Y);
                for (int i = 1, j = 0; i < points.Length; i++)
                {
                    line = new CornersLine();
                    list.Add(line);
                    line.X1 = points[j].X;
                    line.Y1 = points[j].Y;
                    ++j;
                    line.X2 = points[j].X;
                    line.Y2 = points[j].Y;
                    if (i != points.Length - 1)
                    {
                        CornersArc arc = new CornersArc();
                        list.Add(arc);
                    }
                    else
                    {
                        if ((firstPoint.X == points[j].X) && (firstPoint.Y == points[j].Y))
                        {
                            CornersArc arc = new CornersArc();
                            list.Add(arc);
                        }
                    }
                }
                break;
            }
        }
コード例 #3
0
        private void addWithArc(CornersLine line1, CornersLine line2, CornersArc arc, double f1, double f2, double alfa)
        {
            double s           = radius / Math.Tan(alfa / 2);
            double line1Length = Math.Sqrt(Math.Pow(line1.X1 - line1.X2, 2) + Math.Pow(line1.Y1 - line1.Y2, 2));
            double line2Length = Math.Sqrt(Math.Pow(line2.X1 - line2.X2, 2) + Math.Pow(line2.Y1 - line2.Y2, 2));
            double newRadius   = radius;

            if ((Math.Abs(s) > line1Length / 2) || (Math.Abs(s) > line2Length / 2))
            {
                if (s < 0)
                {
                    s = -Math.Min(line1Length / 2, line2Length / 2);
                }
                else
                {
                    s = Math.Min(line1Length / 2, line2Length / 2);
                }
                newRadius = s * Math.Tan(alfa / 2);
            }

            line1.NewX2 = line1.X2 + Math.Abs(s) * Math.Cos(f1);
            line1.NewY2 = line1.Y2 + Math.Abs(s) * Math.Sin(f1);
            line2.NewX1 = line2.X1 + Math.Abs(s) * Math.Cos(f2);
            line2.NewY1 = line2.Y1 + Math.Abs(s) * Math.Sin(f2);

            double circleCenterAngle = f1 + alfa / 2;
            double cs           = newRadius / Math.Sin(alfa / 2);
            PointF circleCenter = new PointF();

            if (s > 0)
            {
                circleCenter.X = (float)(line1.X2 + cs * Math.Cos(circleCenterAngle));
                circleCenter.Y = (float)(line1.Y2 + cs * Math.Sin(circleCenterAngle));
            }
            else
            {
                circleCenter.X = (float)(line1.X2 - cs * Math.Cos(circleCenterAngle));
                circleCenter.Y = (float)(line1.Y2 - cs * Math.Sin(circleCenterAngle));
            }

            double firstAngle  = Math.Atan2(line1.NewY2 - circleCenter.Y, line1.NewX2 - circleCenter.X);
            double secondAngle = Math.Atan2(line2.NewY1 - circleCenter.Y, line2.NewX1 - circleCenter.X);
            double startAngle  = firstAngle;
            double sweepAngle  = secondAngle - firstAngle;

            if (sweepAngle > Math.PI)
            {
                sweepAngle = -(2 * Math.PI - sweepAngle);
            }
            else
            {
                if (sweepAngle < -Math.PI)
                {
                    sweepAngle = (2 * Math.PI + sweepAngle);
                }
            }
            arc.X          = circleCenter.X - newRadius;
            arc.Y          = circleCenter.Y - newRadius;
            arc.Width      = newRadius * 2;
            arc.Height     = newRadius * 2;
            arc.StartAngle = startAngle * (180 / Math.PI);
            arc.SweepAngle = sweepAngle * (180 / Math.PI);
        }