变形最小的平滑折线

发布于 2024-08-05 09:56:51 字数 543 浏览 5 评论 0 原文

我有一条二维闭合折线,相当平滑。然而,定义多段线的顶点的间距并不相等。有时两个人会非常接近,有时多达四个人会非常接近。

我想平滑折线,但常规平均算法往往会缩小面积:

for (int i = 0; i < (V.Length-1); i++)
{
   PointF prev = V[i-1]; //I have code that wraps the index around.
   PointF next = V[i+1];       
   PointF pt = V[i];

   float ave_x = one_third * (prev.X + next.X + pt.X);
   float ave_y = one_third * (prev.Y + next.Y + pt.Y);

   smooth_polyline[i] = new PointF(ave_x, ave_y);
}

我的折线包含​​数千个点,并且两个相邻线段之间的角度通常小于 1 度。

是否有更好的方法来平滑这些曲线,使顶点间隔更均匀,而不会对面积产生太大影响?

I've got a 2D closed polyline, which is reasonably smooth. The vertices that define the polyline however are not spaced equally. Sometimes two will be very close, sometimes as many as four will be very close together.

I'd like to smooth the polyline, but a regular averaging algorithm tends to shrink the area:

for (int i = 0; i < (V.Length-1); i++)
{
   PointF prev = V[i-1]; //I have code that wraps the index around.
   PointF next = V[i+1];       
   PointF pt = V[i];

   float ave_x = one_third * (prev.X + next.X + pt.X);
   float ave_y = one_third * (prev.Y + next.Y + pt.Y);

   smooth_polyline[i] = new PointF(ave_x, ave_y);
}

My polylines contain thousands of points and the angle between two adjacent segments is typically less than 1 degree.

Is there a better way to smooth these curves, something which will space the vertices more equally, without affecting the area too much?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

起风了 2024-08-12 09:56:51

我认为您正在寻找 Chaikin 算法 。这个想法有一个变体,可以使平滑曲线直接穿过控制点(而不是“内部”),但我目前在谷歌上搜索它时遇到了麻烦。

I think you are looking for Chaikin's Algorithm. There is a variant of this idea that makes the smoothed curve pass directly through (instead of "inside" of) the control points, but I'm having trouble googling it at the moment.

忘年祭陌 2024-08-12 09:56:51

您可以查看“曲线简化”文献,例如 Douglas-Peucker 算法或本文 http://www.cs.ait.ac.th/~guha/papers/simpliPoly.pdf

如果您需要均匀间隔的顶点,即使它们定义的相邻线段几乎共线,这也可能无法正常工作。

You could look at the "curve simplication" literature such as the Douglas-Peucker algorithm or this paper http://www.cs.ait.ac.th/~guha/papers/simpliPoly.pdf.

This probably won't work well if you need evenly spaced vertices even when the adjacent line segments they define are nearly collinear.

哭了丶谁疼 2024-08-12 09:56:51

您还可以使用样条线进行插值 - 只需在维基百科中搜索

You can also use splines to interpolate - just search in wikipedia

就此别过 2024-08-12 09:56:51

有人使用 CPOL(免费)许可证将 2 种平滑算法移植到 C#,请参阅此处:

https:// github.com/RobinCK/smooth-polyline

Somebody has ported 2 smoothing algorithms to C#, with a CPOL (free) license, see here:

https://github.com/RobinCK/smooth-polyline

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