---
title: "[转]三次贝尔曲线"
author: "AS3"
date: "2011-11-10T01:09:01Z"
tags: []
categories: ["Web前端"]
slug: "untitled"
draft: false
lastmod: "2011-11-10T01:09:01Z"
id: 1249029
url: "https://as3.iteye.com/blog/1249029"
---

[http://bbs.9ria.com/viewthread.php?tid=103262&extra=page%3D1%26amp%3Borderby%3Ddateline%26amp%3Bfilter%3D2592000](http://bbs.9ria.com/viewthread.php?tid=103262&extra=page%3D1%26amp%3Borderby%3Ddateline%26amp%3Bfilter%3D2592000)

 

最近做的项目要用到曲线方程，从c++扒出来的 曲线方程 里面 还有优化的地方 要用的朋友自己优化 去。 ![](http://bbs.9ria.com/images/attachicons/flash.gif) [**berzier.swf**](http://bbs.9ria.com/attachment.php?aid=NTg2NTF8NGZhMzJiMTZ8MTMyMDg1Nzg4M3w0YTY2bW41M0g5Z2pIU2NFVWI2S3p4K0ZSRVY1YkswaEkwcUdRQXcvazRLWVNsbw%3D%3D) (1.98 KB) 

01. /\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**
02. \* 项  目：Bezier
03. \* 包  名：
04. * 文件名：Bezier.as
05. \* 功  能：
06. \* 创建者：rui
07. \* 修改者：
08. \* 修改目的：
09. \* 创建日期：2011-11-82010-11-15
10. \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/
11. package
12. {
13. import flash.geom.Point;
14. public class Bezi
15. {
16. public function Bezi()
17. {
18. }
19. /\**
20. \* 在贝尔曲线上的点
21. \* @param cp 对应的四个控制点
22. \* @param t         t為參數值，0 &lt;= t &lt;= 1
23. \* @return
24. \*
25. \*/
26. private static function pointOnCubicBezier(cp:Vector.&lt;Point&gt;, t:Number ):Point
27. {
28. var  ax:Number, bx:Number, cx:Number;
29. var  ay:Number, by:Number, cy:Number;
30. var  tSquared:Number, tCubed:Number;
31. var  result:Point = new Point();;
32. // 计算对应的多项式系数点
33. cx = 3.0 * (cp\[1].x - cp\[0].x);
34. bx = 3.0 * (cp\[2].x - cp\[1].x) - cx;
35. ax = cp\[3].x - cp\[0].x - cx - bx;
36. cy = 3.0 * (cp\[1].y - cp\[0].y);
37. by = 3.0 * (cp\[2].y - cp\[1].y) - cy;
38. ay = cp\[3].y - cp\[0].y - cy - by;
39. //对应参数t 对应的曲线点
40. tSquared = t * t;
41. tCubed = tSquared * t;
42. result.x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp\[0].x;
43. result.y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp\[0].y;
44. return result;
45. }
46. /\**
47. \* 生成 贝尔曲线的对应 point
48. \* @param cp 生成曲线的对应的四个贝尔曲线控制点
49. \* @param pointSize 要生成多少个点
50. \* @return
51. \*
52. \*/
53. public static function computeBezier(cp:Vector.&lt;Point&gt;,pointSize:int=10):Vector.&lt;Point&gt;
54. {
55. var   dt:Number;
56. var   i:int;
57. var   curve:Vector.&lt;Point&gt; = new Vector.&lt;Point&gt;();
58. dt = 1.0 /(pointSize-1);
59. for( i = 0; i &lt; pointSize; i++)
60. {
61. curve.push(pointOnCubicBezier(cp,dt\*Number(i)));
62. }
63. return curve;
64. }
65. }
66. }

*复制代码*