## Jaro–Winkler distance algorithm in C#

public static class JaroWinklerDistance { /* The Winkler modification will not be applied unless the * percent match was at or above the mWeightThreshold percent * without the modification. * Winkler’s paper used a default value of 0.7 */ private static readonly double mWeightThreshold = 0.7; /* Size of the prefix to be concidered by … Read more

## 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

## Calculate second point knowing the starting point and distance

It seems you are measuring distance (R) in meters, and bearing (theta) counterclockwise from due east. And for your purposes (hundereds of meters), plane geometry should be accurate enough. In that case, dx = R*cos(theta) ; theta measured counterclockwise from due east dy = R*sin(theta) ; dx, dy same units as R If theta is … Read more

## Is it possible to measure distance to object with camera?

I accept the question has been answered adequately (with the obvious caveats of requiring level ground and possible accuracy problems) but for those who don’t believe it can be done or that it needs a video camera, let me explain the low-level math needed to do it…. The picture above shows me standing outside my … 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

## R – How to get row & column subscripts of matched elements from a distance matrix

A distance matrix is a lower triangular matrix in packed format, where the lower triangular is stored as a 1D vector by column. You can check this via str(distMatrix) # Class ‘dist’ atomic [1:10] 1 4 10 15 3 9 14 6 11 5 # … Even if we call dist(vec1, diag = TRUE, upper … Read more

Categories r

## 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