emgucv 원호 그리기

3420 단어 EmguCV
emgucv에는 정점에 원호를 그리는 함수에 근거하지 않고 스스로 하나를 써서 이 함수를 제시합니다.여기서 DrawPixel 함수는 호의 점을 표시하는 것으로, 자체 프로그램의 함수에 따라 구체적으로 제시해야 한다.
    private void DrawArc( List<Point> points ) //   
    {
        double x1 = points[0].X;
        double x2 = points[1].X;
        double x3 = points[2].X;
        double y1 = points[0].Y;
        double y2 = points[1].Y;
        double y3 = points[2].Y;
        double x, y;
        double r;
        double a, b, c, d, e, f;
        a = 2 * (x2 - x1);
        b = 2 * (y2 - y1);
        c = x2 * x2 + y2 * y2 - x1 * x1 - y1 * y1;
        d = 2 * (x3 - x2);
        e = 2 * (y3 - y2);
        f = x3 * x3 + y3 * y3 - x2 * x2 - y2 * y2;
        x = (b * f - e * c) / (b * d - e * a);
        y = (d * c - a * f) / (b * d - e * a);
        r = Math.Sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));

        double startAngle = Math.Atan2( points[0].Y-y, points[0].X-x );
        double endAngle = Math.Atan2(points[2].Y - y, points[2].X - x);
        double midAngle = Math.Atan2(points[1].Y - y, points[1].X - x);

        double xi, yi;  //         

        double minAngle = startAngle <= endAngle ? startAngle : endAngle;
        double maxAngle = startAngle <= endAngle ? endAngle : startAngle;

        if (midAngle < minAngle || midAngle > maxAngle) //                ,    2    
        {
            xi = (r * Math.Cos(minAngle));
            yi = (r * Math.Sin(minAngle));

            do
            {
                if ((int)(x + xi + 0.5) >= 0 && (int)(x + xi + 0.5) < currentImage.Width && (int)(y + yi + 0.5) >= 0 && (int)(y + yi + 0.5) < currentImage.Height)
                {
                    ps.Add(new Point((int)(x + xi + 0.5), (int)(y + yi + 0.5)));
                    currentImage[ps[ps.Count - 1].Y, ps[ps.Count - 1].X] = new Gray(255);
                }
                minAngle -= 0.001;

                xi = (r * Math.Cos(minAngle));
                yi = (r * Math.Sin(minAngle));
            }
            while (minAngle >= -Math.PI);


            minAngle = maxAngle;
            xi = (r * Math.Cos(minAngle));
            yi = (r * Math.Sin(minAngle));

            do
            {
                if ((int)(x + xi + 0.5) >= 0 && (int)(x + xi + 0.5) < currentImage.Width && (int)(y + yi + 0.5) >= 0 && (int)(y + yi + 0.5) < currentImage.Height)
                {
                    drawPixel((int)(y + yi + 0.5) , (int)(x + xi + 0.5));
                }
                minAngle += 0.001;

                xi = (r * Math.Cos(minAngle));
                yi = (r * Math.Sin(minAngle));
            }
            while (minAngle <= Math.PI);
        }
        else //                        ,          
        {
            xi = (r * Math.Cos(minAngle));
            yi = (r * Math.Sin(minAngle));

            do
            {
                if ((int)(x + xi + 0.5) >= 0 && (int)(x + xi + 0.5) < currentImage.Width && (int)(y + yi + 0.5) >= 0 && (int)(y + yi + 0.5) < currentImage.Height)
                {
                    drawPixel((int)(y + yi + 0.5) , (int)(x + xi + 0.5));
                }
                minAngle += 0.001;

                xi = (r * Math.Cos(minAngle));
                yi = (r * Math.Sin(minAngle));
            }
            while (minAngle <= maxAngle);
        }
    }

좋은 웹페이지 즐겨찾기