distance
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
Find K nearest neighbors, starting from a distance matrix
Try to use FastKNN CRAN package (although it is not well documented). It offers k.nearest.neighbors function where an arbitrary distance matrix can be given. Below you have an example that computes the matrix you need. # arbitrary data train <- matrix(sample(c(“a”,”b”,”c”),12,replace=TRUE), ncol=2) # n x 2 n = dim(train)[1] distMatrix <- matrix(runif(n^2,0,1),ncol=n) # n x … 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
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
d3 force directed layout – link distance priority
If I understand correctly, I believe there is a potential solution. To get link distance to be accurate, you need to set charge and collision forces to zero, but as your image suggests, then nodes aren’t spaced in a way that accounts for other nodes, just those nodes which they share links with. As d3.force … Read more
Measure distance between two HTML elements’ centers
Get their positions, and use the Pythagorean Theorem to determine the distance between them… function getPositionAtCenter(element) { const {top, left, width, height} = element.getBoundingClientRect(); return { x: left + width / 2, y: top + height / 2 }; } function getDistanceBetweenElements(a, b) { const aPosition = getPositionAtCenter(a); const bPosition = getPositionAtCenter(b); return Math.hypot(aPosition.x – … Read more
Fastest available algorithm for distance transform
The OpenCV library uses for its approximate cv::distanceTransform function a algorithm which passes the image from top left to bottom right and back. The algorithm is described in the paper “Distance transformations in digital images” from Gunilla Borgefors (Comput. Vision Graph. Image Process. 34 3, pp 344–371, 1986). The algorithm calculates the distance through a … Read more
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
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