Smooth polyline with minimal deformation

I have a 2D closed polyline that is smooth enough. However, the vertices that define the polyline are not equally spaced. Sometimes two will be very close, sometimes as many as four will be very close to each other.

I would like to smooth the polyline, but the usual 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 usually less than 1 degree.

Is there a better way to smooth out these curves, which will distribute the vertices more evenly without affecting the area too much?

+3
source share
4 answers

, . , ( "" ) , .

+2

- wikipedia

0

Source: https://habr.com/ru/post/1718338/


All Articles