绘制策略:在每两对点之间,加入一个新点(中间点)放在这两点的正中间。然后使用这些中间点作为起点和终点,而把最初的那些点(原始点)作为控制点。
转自:http://dishell.iteye.com/blog/504440
之前使用二次贝塞尔曲线绘制两点的策略是已知的两点作为起始点和终点,然后求出这两点的中点作为控制点来绘制,结果曲线的圆滑程度不符合我所要求,之后使用上面的策略,曲线平滑程度得到了改善。
- package
- {
- import flash.display.Sprite;
- import flash.events.MouseEvent;
- public class MultiCurves3 extends Sprite
- {
- private var numPoints:uint = 9;
- public function MultiCurves3()
- {
- init();
- }
- private function init():void
- {
- var points:Array = new Array();
- for (var i:int = 0; i < numPoints; i++)
- {
- points[i] = new Object();
- points[i].x = Math.random() * stage.stageHeight;
- points[i].y = Math.random() * stage.stageHeight;
- }
- // find the first midpoint and move to it
- var xc1:Number = (points[0].x + points[numPoints - 1].x) / 2;
- var yc1:Number = (points[0].y + points[numPoints - 1].y) / 2;
- graphics.lineStyle(1);
- graphics.moveTo(xc1, yc1);
- // curve through the rest, stopping at midpoints
- for (i = 0; i < numPoints - 1; i ++)
- {
- var xc:Number = (points[i].x + points[i + 1].x) / 2;
- var yc:Number = (points[i].y + points[i + 1].y) / 2;
- graphics.curveTo(points[i].x, points[i].y, xc, yc);
- }
- // curve through the last point, back to the first midpoint
- graphics.curveTo(points[i].x, points[i].y, xc1, yc1);
- }
- }
- }