ITeye博客

[转]三次贝尔曲线

AS3 · 2011-11-10 01:09 · 文章转载 · 问题总结 · 算法技术 · AS3常用开源库 · 源码范例 · AS3收集 · Web前端 · Markdown

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

 

最近做的项目要用到曲线方程,从c++扒出来的 曲线方程 里面 还有优化的地方 要用的朋友自己优化 去。  berzier.swf (1.98 KB) 

  1. /********************************
  2. * 项  目:Bezier
  3. * 包  名:
  4. * 文件名:Bezier.as
  5. * 功  能:
  6. * 创建者:rui
  7. * 修改者:
  8. * 修改目的:
  9. * 创建日期: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 <= t <= 1
  23. * @return
  24. *
  25. */
  26. private static function pointOnCubicBezier(cp:Vector.<Point>, 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.<Point>,pointSize:int=10):Vector.<Point>
  54. {
  55. var   dt:Number;
  56. var   i:int;
  57. var   curve:Vector.<Point> = new Vector.<Point>();
  58. dt = 1.0 /(pointSize-1);
  59. for( i = 0; i < pointSize; i++)
  60. {
  61. curve.push(pointOnCubicBezier(cp,dt*Number(i)));
  62. }
  63. return curve;
  64. }
  65. }
  66. }

复制代码

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。