actionscript-3 - 使用curveTo绘制完美圆的一部分

标签 actionscript-3 graphics drawing

我需要使用 graphics.curveTo 绘制完美圆的一部分(我有我想绘制的半径和角度)但我无法理解 cotorol x&y 的确切公式以使曲线完美

我知道如何使用循环和许多 lineTo但这还不足以满足我的需求......

提前致谢!

最佳答案

我使用这个函数来绘制圆段(我想我很久以前从一个关于如何绘制完整圆的在线 AS2 示例中移植了它):

    /**
     * Draw a segment of a circle
     * @param graphics      the graphics object to draw into
     * @param center        the center of the circle
     * @param start         start angle (radians)
     * @param end           end angle (radians)
     * @param r             radius of the circle
     * @param h_ratio       horizontal scaling factor
     * @param v_ratio       vertical scaling factor
     * @param new_drawing   if true, uses a moveTo call to start drawing at the start point of the circle; else continues drawing using only lineTo and curveTo
     * 
     */
    public static function drawCircleSegment(graphics:Graphics, center:Point, start:Number, end:Number, r:Number, h_ratio:Number=1, v_ratio:Number=1, new_drawing:Boolean=true):void
    {
        var x:Number = center.x;
        var y:Number = center.y;
        // first point of the circle segment
        if(new_drawing)
        {
            graphics.moveTo(x+Math.cos(start)*r*h_ratio, y+Math.sin(start)*r*v_ratio);
        }

        // draw the circle in segments
        var segments:uint = 8;

        var theta:Number = (end-start)/segments; 
        var angle:Number = start; // start drawing at angle ...

        var ctrlRadius:Number = r/Math.cos(theta/2); // this gets the radius of the control point
        for (var i:int = 0; i<segments; i++) {
             // increment the angle
             angle += theta;
             var angleMid:Number = angle-(theta/2);
             // calculate our control point
             var cx:Number = x+Math.cos(angleMid)*(ctrlRadius*h_ratio);
             var cy:Number = y+Math.sin(angleMid)*(ctrlRadius*v_ratio);
             // calculate our end point
             var px:Number = x+Math.cos(angle)*r*h_ratio;
             var py:Number = y+Math.sin(angle)*r*v_ratio;
             // draw the circle segment
             graphics.curveTo(cx, cy, px, py);
        }

    }

我认为它足够接近完美的圆圈。里面的数学我不是很懂,但我希望参数对你来说足够清楚。

关于actionscript-3 - 使用curveTo绘制完美圆的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10359351/

相关文章:

c++ - 是否可以从覆盖(非事件)窗口获取 pixelcolor(x,y)?

c# - 在屏幕上画线?

javascript - Adobe Air 可以做到这一点吗?

actionscript-3 - Flex移动应用中的Google Analytics(分析)

python - 如何简化这个很长的 if 语句?

java - 如何将 JLabel 的文本放在其图标下

algorithm - 加入混合抗锯齿线时浸入

actionscript-3 - 第1084章

apache-flex - 访问 flash.net.URLLoader 对象的 HTTP 响应 header ?

r - 组合由 R base、lattice 和 ggplot2 创建的图