Recent comments
-
9 hours 19 min ago
-
9 hours 30 min ago
-
1 day 9 hours ago
-
2 weeks 1 day ago
-
3 weeks 4 hours ago
-
3 weeks 20 hours ago
-
3 weeks 1 day ago
-
4 weeks 21 hours ago
-
4 weeks 1 day ago
-
1 month 1 week ago
-
1 month 1 week ago
-
1 month 2 weeks ago
Follow us
Elk News - the email newsletter
Subscribe to the Elk RSS feed, including blog posts, pictures and videos.
Titles only
Full content
Comments aren't included in these feeds. For them you can click the RSS icon in the Recent Comments box.
Our videos at
YouTube
Add new reply
Neither, I just wrote it here straight from my mind. Today I understood what I was after. My explanation was wrong.
The idea was to find the farthest turning point where you can go straightly. Then find from that point the farthest point where you can go without turning etc. It doesn't necessarily find the shortest route, but now when I think about it, it actually feels rather natural. However, it's pretty likely not what you needed. I'm very sorry for my lack of talent.
In JavaScript-like pseudocode:
First produce a route from beginning to end and put it in a list:
Route = list of turning points with Route[0] as beginning and Route[n] as the end.
function find_straight(a,b) /* returns a straight route (without turns from point a to the point b if there's one, returns NULL if there isn't. That's probably something you're using already. */
/* Here's the new algorithm represented as function */
function straighten_route(Route) {
/* introduce four local variables */
var Beginning = 0
var End = n
var i = 1
var New_route = [] /* an empty list */
/* Set the original beginning as the beginning of a new route */
New_route[0] = Route[0]
/* go on until Beginning has reached the end point of the route */
while (Beginning < n) {
while (find_straight(Route[Beginning],Route[End]) == Null)
{
/* move the end point towards the beginning until a straight route is found */
End = End - 1
}
/* When there is a straight route (remember that there's always a straight one at least to the next turn in the original route) */
/* add it to the new route */
New_route[i] = Route[End]
/* increment i */
i = i + 1
/* set found turn as a new beginning and End back to n */
Beginning = End
End = n
}
/* return the solution */
return New_route
}