我有一个矢量绘图应用程序,用户可以在其中使用多个二次贝塞尔曲线绘制线条。例如,一条曲线可以有 5 个点 - 二次贝塞尔曲线的点 0-2,点 2-4 形成另一个点。如果第一条贝塞尔曲线末端的斜率不等于第二条贝塞尔曲线起点的斜率,则曲线不平滑。
我想包括一个“平滑”按钮,用户可以点击它来自动平滑线条。我想保持原始曲线和平滑曲线之间的整体 MSE 较小,而不是使斜率完美匹配。然而,100% 的准确度并不是必需的,因为它是一个绘图程序——速度更重要。有没有什么好的算法可以做到这一点?我似乎找不到任何参考资料。
如果您想保持线条的整体形状并使角变圆,您可以:在每个角周围创建新点:
例如,在您描述的情况下,P2 将有一个角落
为此,我们可以使用任何小于 0.5 的 epsilon 让我们使用 0.1 所以我们有 P1.9、P2.1。
P1.9.x = (9 * P2.x + P1.x)/10
P1.9.y = (9 * P2.y + P1.y)/10
P2.1.x = (9 * P2.x + P3.x)/10
P2.1.y = (9 * P2.y + P3.y)/10
Run Code Online (Sandbox Code Playgroud)
你可以这样做:
Bezier(P0, P1, P1.9);
Bezier(P1.9, P2, P2.1);
Bezier(P2.1, P3, P4);
Run Code Online (Sandbox Code Playgroud)
而不是做:
Bezier(P0, P1, P2);
Bezier(P2, P3, P4);
Run Code Online (Sandbox Code Playgroud)
I hope this new answer helps.. otherwise I would like to see an image describing the kind of line you have, and the result you would like to see.(this would help filter out answers that do not match the criteria)
Old answer: The users input 3 points for each bezier curve?
If you wish to make a smooth line you could do the following :
1.Create new interpolated points :
p0.5[x] = (p0[x] + p1[x]) / 2;
p0.5[y] = (p0[y] + p1[y]) / 2;
Run Code Online (Sandbox Code Playgroud)
1.b do the same for p1.5, p2.5... where p(N.5) uses p(N) and p(N+1)
2.Instead of drawing:
Bezier(p0, p1, p2);
Bezier(p2, p3, p4);
Run Code Online (Sandbox Code Playgroud)
Draw
Line(p0, 0.5);
Bezier(p0.5, p1, p1.5);
Bezier(p1.5, p2, p2.5);
Bezier(p2.5, p3, p3.5);
Line(p3.5, p4);
Run Code Online (Sandbox Code Playgroud)
I hope this is easy to understand and helpful.
| 归档时间: |
|
| 查看次数: |
2668 次 |
| 最近记录: |