在 Actionscript 中绘制三次贝塞尔曲线?

发布于 2024-09-09 17:26:24 字数 369 浏览 4 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤云独去闲 2024-09-16 17:26:25

注意:Flash Player 11 及以上版本包含绘制三次曲线的本机方法,cubicCurveTo() 如果您的目标是 FP11,这应该是最快的方法。

就在上周,我写了一个类来绘制任意顺序的贝塞尔曲线。

该代码尚未优化,但在我的测试中运行良好。对于制作动画来说,性能是可以接受的事件(尽管我认为滥用它不是一个好主意,因为正如我所说,它没有优化;当然,将它们用于二次曲线是没有意义的,因为玩家可以本地这样做)。

如果您想使用它,代码就在这里,或者看一下:

BezierCurve 类

示例代码

我认为通过示例代码,您将能够毫无困难地弄清楚如何使用它(它非常直接转发并发表一些评论);但如果您遇到问题,请及时询问!

您可以随意使用它。

Note: Flash Player 11 onwards includes a native method to draw cubic curves, cubicCurveTo() which should be the fastest method if you are targeting FP11.

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.

愁以何悠 2024-09-16 17:26:25

如果二次函数内置于该 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.

蓝梦月影 2024-09-16 17:26:25

该网站列出并解释了近似三次贝塞尔曲线的各种方法:
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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文