There are many implementations for calculating the geodetic distance on a triangular grid. Some are approximate and some are accurate.
1. Fast marching method. This method is approximate, and in practice the average error is less than 1%. You can contact Gabriel Peyru about the implementation of the fast marching method in Matlab. http://www.mathworks.com/matlabcentral/fileexchange/6110-toolbox-fast-marching
The IMF method proposed in [1] and implemented in [2]. This method is accurate and the code is at https://code.google.com/p/geodesic/ . Same as Ante's comment. The disadvantage is that when the grid is a stall, the MMP method will consume a lot of memory, O (n ^ 2), n is the number of vertices.
CH proposed in [3], and improved and implemented in [4]. This method is accurate and consumes less memory than the MMP method. The code is at https://sites.google.com/site/xinshiqing/knowledge-share
The heat method proposed in [5]. One of the implementations is located at https://github.com/dgpdec/course. This method is approximate and requires a preprocessing process. This is faster than the Fast Marching method.
[1] Joseph S. B. Mitchell, David M. Mount, and Christos H. Papadimitriou. 1987. Discrete geodesic problem. SIAM J. Comput. 16, 4 (August 1987), 647-668.
[2] Vitaliy Surazhsky, Tatyana Surazhskaya, Danil Kirsanov, Stephen Gortler, Hyug Hoppe. Fast accurate and approximate geodesics on grids. ACM Trans. Graphics (SIGGRAPH), 24 (3), 2005
[3] Chen, J. and Han, Y. 1990. Shortest paths on a polyhedron. InSCG '90: Proceedings of the Sixth Annual Symposium on Computational Geometry. ACM Press, New York, NY, USA, 360 {369
[4] Shi-Qing Xin and Guo-Jin Wang. 2009. Improving the Chen and Hann algorithm for a discrete geodesic problem. ACM Trans. Schedule. 28, 4, article 104 (September 2009), 8 pages.
[5] Crane K, Weischedel C, Wardetzky M. Geodesics in heat: a new approach to calculating distance based on heat flux [J]. ACM Transactions on Graphics (TOG), 2013, 32 (5): 152.