# Algorithms

Mappish draws the visualizations in real time. And it updates as the user changes the viewport, method of vizualisation and zoom. This can be computationally very heavy on a small handheld device. Calculations using GPS-locations and geodesy formulas are making heavy use of trigonometry and floating point maths. Considered that the data in this app can easily grow to several thousands datapoints that in a worst case scenario needs a handfull of trig calculations each. All done at a rate of several iterations per second requires the need for some optimization and work arounds.

One of the corner stones to making this responsive is a limitation in the GPS system. Since the location is updated once per minute to save battery the GPS one cannot assume that the GPS position has a better precision than approximately 10 meters at best. Because of that the coordinates are runded to four decimal points.

That allows us to map the gps points to a grid of 10*10 meters without loosing precision in the data.

## Selection and mapping of points

This is how the points are requested from the database

- Get the extreme latitudes and longitudes that can be found in the map view any given moment.
- Get all saved datapoints within that box.
- Translate the size of the box to meters.
- Create a matrix that represents the box where each element is equivalent to a Xm*Xm square.
- Map the GPS positions to the cells in the matrix. In this stage the elemets get weighted from 0 to n
- Perform any desired operation on the matrix
- Project the matrix to the OSM map

## Visualizations

There are a few variations of how Mappish visualizes the data. To gain these effects some calculations are done to the filled matrix. Display of frequently visited positions are shown either by a heatmap with a either very simple interpolation scheme to not be forced to convert between color spaces. Or it can be shown in shades of blue where the alpha channel is the changed varieble.

To smear the frequently visited positions and make them stand out Mappish applies either a box blur or a gaussian blur on the points. The methods performing that can be found in the class MatrixHelper.java. The application of the gaussian kernel is unpotimized (//TODO: Optimize the gaussian blur). Though the kernel itself is precalculated to speed things up.