For green dots equidistant along the polyline:
First run: go through the list of points, calculate the length of each segment and the cumulative length to the current point. Pseudocode:
cumlen[0] = 0; for (int i=1; i < numPoints; i++) { len = Sqrt((Point[i].x - Point[i-1].x)^2 + (Point[i].y - Point [i-1].y)^2) cumlen[i] = cumlen[i-1] + len; }
Now find the length of each new piece
plen = cumlen[numpoints-1] / numpieces;
Now the second run - go through the list of points and insert new points in the corresponding segments.
i = 0; for (ip=0; ip<numpieces; ip++) { curr = plen * ip; while cumlen[i+1] < curr i++; P[ip].x = Points[i].x + (curr - cumlen[i]) * (Points[i+1].x - Points[i].x) / (cumlen[i+1] - cumlen[i]); ..the same for y }
Real output examples for numpieces > numPoints and vice versa

source share