views:

236

answers:

4
+1  A: 

loop though all the points starting with index 1 instead of 0, and get the 'direction' for the path. If the direction changes, add the last of the two points( the current, not the previous ) to the optimized array.

If you think it's going to help, you should either think that the Earth is flat ;-)

Try this: if the path changes slightly, then skip every second point, thus finishing with twice as less points. If path changes appreciably, keep nodes as is. Then repeat with half of the threshold of what "slightly is (your lengths are doubled, so your sensitivity must increase) until you make no changes after a run.

Pavel Shved
I should read Flatland soon, I keep delaying that. Thanks for the flat Earth reference ;)
George Profenza
A: 

I would go with your suggestion, but keep the current and previous point when the direction changes.

That way, you end up with the first and last point of each line segment.

mbeckish
+6  A: 

Check out Ramer-Douglas-Peucker algorithm

Stephen Nutt
this looks interesting. I will try different methods, but so far this one looks most appealing.
George Profenza
A: 

I think your initial idea is great. I would add/change two things:

1) I would throw in a distance threshold into your algorithm: Only when the currently tested point is some minimum distance away from your last 'good' point, should you even test it. Depending on the source of your path data (a magnetic tracker perhaps?), stationarity may not be reflected well in your raw data, due to measurement noise. This might lead to relatively large directional changes in a very small area that are essentially meaningless.

2) When you detect a large enough change, do not add the currently tested point (as you suggested), but the previous one. Otherwise you may end up misrepresenting the path. An example (in 2D): the path consisting of (0,0)->(1,0)->(2,0)->(3,0)->(4,0)->(5,5) would end up as (0,0)->(5,5) using your methods, which I wouldn't consider a good representation of the path. Better would be (0, 0)->(4,0)->(5,5).

Andreas F
I will keep that in mind, thank you for the tip.
George Profenza