如何最优地绘制参数连续曲线?
假设我们有一条参数曲线,例如一个圆:
x = r * cos(t)
y = r * sin(t)
我们希望以如下方式在屏幕上绘制曲线:
- 每个像素仅绘制一次(最佳部分)
- 每个 (x, y) 都有一个绘制的像素位于曲线上(连续部分)
如果我们只为 [t1, t2] 中的每个 t 绘制 (x, y),则不会满足这些条件。
我正在寻找任何参数曲线的通用解决方案。
Let's say we have a parametric curve, for example a circle:
x = r * cos(t)
y = r * sin(t)
We want to plot the curve on the screen in a way that:
- every pixel is painted just once (the optimal part)
- there is a painted pixel for each (x, y) that lies on the curve (the continuous part)
If we just plot (x, y) for each t in [t1, t2], these conditions will not be met.
I am searching for a general solution for any parametric curve.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
100% 满足您的标准的通用解决方案并不存在。
所以我们必须妥协。
通常,这是通过从步长(通常是例程的参数)开始来解决的,该步长可以通过启发式触发进行细分,例如:
当分段覆盖的距离大于给定距离(例如一个像素)时进行细分)
当曲线方向变化太大时进行细分
或组合这些。
通常还会对细分给出一些限制,以避免永远占用。
许多提供参数化绘图的系统都是从启发式参数和步长的一些可更改的默认设置开始的。如果曲线不够“好”或者花费的时间太长,用户可以调整这些。
问题在于,总有病态的曲线会破坏您的绘图方法,使其错过细节或花费太长的时间。
A general solution that 100% satisfies your criteria does not exist.
So we have to compromize.
Usually this is tackled by starting with a stepsize (usually a parameter to your routine), this stepsize can be subdivided triggered by a heuristic e.g.:
subdivide when the distance covered by a segment is larger than a given distance (e.g. one pixel)
subdivide when the curve direction changes too much
Or a combination of these.
Usually some limit to subdivision is also given to avoid taking forever.
Many systems that offer parametric plotting start with some changeable default setting for the heuristic params and step size. The user can adapt these if the curve is not "nice" enough or if it takes too long.
The problem is that there are always pathological curves that will defeat your method of drawing making it miss details or taking overly long.
查看贝塞尔样条线。
Check out Bézier splines.