平滑贝塞尔曲线
我想平滑 iPhone 中的一些手绘线。 我在中使用了以下代码 http://webdocs.cs.ualberta.ca/~graphics /books/GraphicsGems/gems/FitCurves.c
但是,我发现有些贝塞尔曲线是错误的,第二个控制点和终点无效。 以前有人遇到过同样的问题吗? 谢谢。
I want to smooth some hand draw lines in iphone.
I have used the following code in
http://webdocs.cs.ualberta.ca/~graphics/books/GraphicsGems/gems/FitCurves.c
However, I found that some bezier curved was wrong, the second control point and end point is invalid.
Did anybody have the same problem before?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
贝塞尔曲线并非设计用于穿过提供的顶点!
它们旨在塑造受控制点影响的平滑曲线。
首先,您必须决定是否要在缺失点之间进行插值,
或者如果您想过滤不平滑的数据:
过滤
您应该查看带有小平均窗口的“滑动平均值”。 (尝试 5 - 10 像素)。
其工作原理如下:(查找 wiki 以获得详细说明)
我在这里使用 10 点的平均窗口:
首先计算点 0 - 9 的平均值,并将结果输出为结果点 0
然后计算点1 - 10的平均值并输出,结果1
等等。
插值
如果要使用平滑曲线在(缺失的)点之间进行插值,可以使用分段三次样条:
通过 3 个顶点计算三次多边形的系数。
您首先通过以下方式计算立方多边形:
Point[0] - Point[2],但您仅从 Point[0] 到 Point[1] 绘制输出。
然后你继续下一步:并计算
Point[1] - Point[3],但仅从 p1 到 p2 绘制。
等等。
您需要在 wiki 上搜索三次插值,以获取如何计算三次多边形(有时称为三次样条)的详细说明。
Bezier Curves are not designed to go through the provided vertices!
They are designed to shape a smooth curve influenced by the control points.
First you must decide if you want to interpolate between missing points,
or if you want to filter non smooth data:
Filtering
You should look at "sliding average" with a small averaging window. (try 5 - 10 pixel).
This works as follows: (look for wiki for a detailed description)
I use here an average window of 10 points:
start by calculation of the average of points 0 - 9, and output the result as result point 0
then calculate the average of point 1 - 10 and output, result 1
And so on.
Interpolation
If you want to interpolate between (missing) points using a smooth curve, you could use piece - wise cubic splines:
You calculate the coefficients of a cubic polygon through 3 vertices.
You start with calculating the cubic polygon through:
Point[0] - Point[2], but you draw your output only from Point[0] to Point[1] .
Then you move on one step: and calculate through
Point[1] - Point[3], but you draw only from p1 to p2.
And so on.
You need to search on wiki for cubic interpolation for a detailed explanation how to caluclate a cubic polygon (sometimes called cubic spline).