Fastest available algorithm for distance transform

This paper reviews the known exact distance transform algorithms: “2D Euclidean distance transform algorithms: A comparative survey” https://rfabbri.github.io/stuff/fabbri-EDT-survey-ACMCSurvFeb2008.pdf The fastest exact distance transform is from Meijster: “A General Algorithm for Computing Distance Transforms in Linear Time.” http://fab.cba.mit.edu/classes/S62.12/docs/Meijster_distance.pdf The design of the algorithm is particularly well suited for parallel calculation. This is implemented in my open … Read more

How to find my distance to a known location in JavaScript

If your code runs in a browser, you can use the HTML5 geolocation API: window.navigator.geolocation.getCurrentPosition(function(pos) { console.log(pos); var lat = pos.coords.latitude; var lon = pos.coords.longitude; }) Once you know the current position and the position of your “target”, you can calculate the distance between them in the way documented in this question: Calculate distance between … Read more

Calculating distance between zip codes in PHP

This is mike’s answer with some annotations for the magic numbers. It seemed to work fine for me for some test data: function calc_distance($point1, $point2) { $radius = 3958; // Earth’s radius (miles) $deg_per_rad = 57.29578; // Number of degrees/radian (for conversion) $distance = ($radius * pi() * sqrt( ($point1[‘lat’] – $point2[‘lat’]) * ($point1[‘lat’] – … Read more

How to calculate distance from a point to a line segment, on a sphere?

Here’s my own solution, based on the idea in ask Dr. Math. I’d be happy to see your feedback. Disclaimer first. This solution is correct for spheres. Earth isn’t a sphere, and the coordinates system (WGS 84) doesn’t assume it’s a sphere. So this is just an approximation, and I can’t really estimate is error. … Read more