distance

Distance from a point to a line

Distance from a point to a line Question: I have created a class “Point” and i want to calculate the shortest distance between a given point and a line ( characterized by 2 other points ), all points are known. I tried to use this formula : |Ax+By+C| / sqrt(A^2+B^2) , but i messed up …

Total answers: 4

Fast fuse of close points in a numpy-2d (vectorized)

Fast fuse of close points in a numpy-2d (vectorized) Question: I have a question similar to the question asked here: simple way of fusing a few close points. I want to replace points that are located close to each other with the average of their coordinates. The closeness in cells is specified by the user …

Total answers: 2

Python Turtle – How do I stop the turtle at a specific distance or coordinate?

Python Turtle – How do I stop the turtle at a specific distance or coordinate? Question: This is my attempt to make the turtle stop after traveling nearly 400 pixels. def race(): while True: alex.forward(r_alex) a = a + r_alex if a > 399.9: break And this is what I got back UnboundLocalError: local variable …

Total answers: 1

Coordinates of the closest points of two geometries in Shapely

Coordinates of the closest points of two geometries in Shapely Question: There is a polyline with a list of coordinates of the vertices = [(x1,y1), (x2,y2), (x3,y3),…] and a point(x,y). In Shapely, geometry1.distance(geometry2) returns the shortest distance between the two geometries. >>> from shapely.geometry import LineString, Point >>> line = LineString([(0, 0), (5, 7), (12, …

Total answers: 2

How do I find the difference between two values without knowing which is larger?

How do I find the difference between two values without knowing which is larger? Question: I was wondering if there was a function built into Python that can determine the distance between two rational numbers but without me telling it which number is larger. e.g. >>>distance(6,3) 3 >>>distance(3,6) 3 Obviously I could write a simple …

Total answers: 10

Pairwise Kullback Leibler (or Jensen-Shannon) divergence distance matrix in Python

Pairwise Kullback Leibler (or Jensen-Shannon) divergence distance matrix in Python Question: I have two matrices X and Y (in most of my cases they are similar) Now I want to calculate the pairwise KL divergence between all rows and output them in a matrix. E.g: X = [[0.1, 0.9], [0.8, 0.2]] The function should then …

Total answers: 2

Get lat/long given current point, distance and bearing

Get lat/long given current point, distance and bearing Question: Given an existing point in lat/long, distance in (in KM) and bearing (in degrees converted to radians), I would like to calculate the new lat/long. This site crops up over and over again, but I just can’t get the formula to work for me. The formulas …

Total answers: 14

Python: speeding up geographic comparison

Python: speeding up geographic comparison Question: I’ve written some code that includes a nested loop where the inner loop is executed about 1.5 million times. I have a function in this loop that I’m trying to optimize. I’ve done some work, and got some results, but I need a little input to check if what …

Total answers: 6

Haversine Formula in Python (Bearing and Distance between two GPS points)

Haversine formula in Python (bearing and distance between two GPS points) Question: Problem I would like to know how to get the distance and bearing between two GPS points. I have researched on the haversine distance. Someone told me that I could also find the bearing using the same data. Everything is working fine, but …

Total answers: 12