在 Actionscript 中绘制三次贝塞尔曲线?
在 AS3 中以编程方式绘制三次贝塞尔曲线的最佳方法是什么? Graphics 类似乎仅支持二次曲线。 :( 我希望能够做类似的事情:
var startPoint:Point = new Point(0, 0);
var endPoint:Point = new Point(5, 5);
var control1:Point = new Point(5, 0);
var control2:Point = new Point(0, 5);
var myBezier:Sprite = getBezier(startPoint, control1, control2, endPoint);
对于性能目标,我计划一次在舞台上安排大约 50 个这样的人。
What's the best way to draw cubic bezier curves programmatically in AS3? The Graphics
class only seems to support quadratic curves. :( I want to be able to do something like:
var startPoint:Point = new Point(0, 0);
var endPoint:Point = new Point(5, 5);
var control1:Point = new Point(5, 0);
var control2:Point = new Point(0, 5);
var myBezier:Sprite = getBezier(startPoint, control1, control2, endPoint);
For a performance target, I'm planning on having ~50 of these on the stage at once.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
就在上周,我写了一个类来绘制任意顺序的贝塞尔曲线。
该代码尚未优化,但在我的测试中运行良好。对于制作动画来说,性能是可以接受的事件(尽管我认为滥用它不是一个好主意,因为正如我所说,它没有优化;当然,将它们用于二次曲线是没有意义的,因为玩家可以本地这样做)。
如果您想使用它,代码就在这里,或者看一下:
BezierCurve 类
示例代码
我认为通过示例代码,您将能够毫无困难地弄清楚如何使用它(它非常直接转发并发表一些评论);但如果您遇到问题,请及时询问!
您可以随意使用它。
Just last week I wrote a class to draw Bezier curves of arbitrary order.
The code is not optimized but works fine in my tests. Performance is acceptable event for doing animations (although I don't think it's a good idea to abuse it, since as I said it's not optimized; it doesn't make sense to use these for quadratic curves, of course, since the player can do that natively).
The code is here if you want to use it or take a look:
The BezierCurve class
Sample code
I think that with the sample code you will be able to figure out how to use it without trouble (it's quite straight forward and somewhat commented); but if you run into problems, ask away!
Feel free to use it as you see fit.
如果二次函数内置于该 API 调用中,您必须充分了解贝塞尔曲线才能编写自己的三次函数实现。
就像这个。
If quadratic are built into that API call, you'll have to understand Bezier well enough to write your own cubic implementation.
Like this.
该网站列出并解释了近似三次贝塞尔曲线的各种方法:
http://timotheegroleau.com/Flash/articles/cubic_bezier_in_flash.htm
在最底部他给出了一种标题为固定中点方法的方法,该方法使用四个二次曲线作为近似值,并且似乎是所有方法中精度和性能最好的。
This site lists and explains various ways of approximating cubic Bezier curves :
http://timotheegroleau.com/Flash/articles/cubic_bezier_in_flash.htm
At the very bottom he gives a method with the heading Fixed MidPoint approach which uses four quadratic curves as an approximation and seems to be the best in terms of accuracy and performance out of all the methods.