Yar*_* U. 3 graphics drawing actionscript-3
我需要使用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);
}
}
Run Code Online (Sandbox Code Playgroud)
我认为它足够接近完美的圈子.我不太了解里面的数学,但我希望参数对你来说足够清楚.