Recently, as Maths made my Xmas Break

In the last posting I mentioned that I made the routes in MoNav more persistent:

As a consequence, I’ve just written some code that detects whether the vehicle is still “on track”. The route only gets recalculated in case the vehicle left it for more than x meters. This makes the route much more persistent and will cause far less headache than the previous approach.

Since the GPS position is always a bit inaccurate, it will almost never be exactly on the computed route. Instead, it will aberrate a bit from it. What you want to achieve is to detect whether the current position still is either near the route, e.g. left or right of it, no more than x meters away and still in direction to the planned target, or in the opposite direction.

First the computed route:

This hardcopy shows a small deviation in the opposite direction of the route. MoNav does neither force the source indicator to the route’s polygon nor does it recompute the route, as long the distance is still near the originally planned route:

In case the position was in direction of the route, but somewhere in the houses nearby, MoNav will determine the nearest position on the computed route, shorten it accordingly and show the source indicator at the startpoint of the shortened route instead of somewhere in the houses nearby:

IIRC I’ve seen such a feature as an option called »Lock to road« in commercial routing software.

The problem seems to be easy to solve, and actually, it is. However, it requires some linear algebra (aka vector maths). You can find a couple of places with solutions using a search engine, and the example of Rod Stephens finally did the job for me after porting it to C++ and adopting it to my needs (thanks for the kind permission to use it BTW).

So what is this posting all about? Remembering my school days, many pupils disliked maths, especially word problems. Which is a pity. The world is full of issues solvable by applying a little math, while people refrain from solving them due to some aversion. Got interested? Great.

Maths have been invented to better describe the world we live in. And computers executing maths help to make the world a better place, day by day. Be the one who converts maths into useful computer programs. And you’ll feel good during the Xmas break :) .