# How to traverse all points from an ofPolyLine progressively ?

Hi there,
working on my visual sequencer, I’d need to efficiently (if possible…) to traverse all the points of an ofPolyLine from the first one to the last one (which can be the first one in case of closed ofPolyLine)

I think about something building a kind of cumulative distance arrays while adding each points of the ofPolyLine, then to traverse this one but …

Any ideas or nice trick for this ?

``````

for(int i=0; i<myPolyline.size(); i++){

ofCircle(myPolyline[i],2);

}

``````

if you want set get steps between two polyline points then you should use getResampledBySpacing to create more in-between points.

I discovered ofPolyLine.getPerimeter() too, in order to calculate the distance.

My “problem” is, I’d need to traverse from 0 to lastpoint with a particular speed.
With the distance, the total time it has to take… I can calculate the speed

speed in the for() loop could be given by the increment of course, but it has to do with the regularity of the point in my ofPolyLine.
I saw the 3 methods getResampledByCount(…) & getResampledBySpacing(…) & resize(…)

Maybe, I can resize by default ALL ofPolyLine to 100, for instance, then, I’d have something constant …

It works doing something like that:

``````
ofPoint Sequence::calculateXYFromPosition(float _position){

return thePath[(int)(_position * thePath.size() / 100)];
}

``````

where _position is a master index from 0 to 99

BUT, now my problem is regularity.
Is there a way to process a polyline to make constant all spaces between points ?

I guess it would involve interpolation.
Especially, if the path as some brutal variation, the cursor over the path jumps literally from one point to the other.