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

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

Vector Space Model: Cosine Similarity vs Euclidean Distance

One informal but rather intuitive way to think about this is to consider the 2 components of a vector: direction and magnitude. Direction is the “preference”https://stackoverflow.com/”style”https://stackoverflow.com/”sentiment”https://stackoverflow.com/”latent variable” of the vector, while the magnitude is how strong it is towards that direction. When classifying documents we’d like to categorize them by their overall sentiment, so we … Read more

Coordinates of the closest points of two geometries in Shapely

The GIS term you are describing is linear referencing, and Shapely has these methods. # Length along line that is closest to the point print(line.project(p)) # Now combine with interpolated point on line p2 = line.interpolate(line.project(p)) print(p2) # POINT (5 7) An alternative method is to use nearest_points: from shapely.ops import nearest_points p2 = nearest_points(line, … Read more

tech