distance

What is the quickest way to find the shortest cartesian distance between two polygons

夙愿已清 提交于 2019-12-03 04:57:48
问题 I have 1 red polygon say and 50 randomly placed blue polygons - they are situated in geographical 2D space . What is the quickest/speediest algorithim to find the the shortest distance between a red polygon and its nearest blue polygon? Bear in mind that it is not a simple case of taking the points that make up the vertices of the polygon as values to test for distance as they may not necessarily be the closest points. So in the end - the answer should give back the closest blue polygon to

Python calculate lots of distances quickly

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 04:06:51
I have an input of 36,742 points which means if I wanted to calculate the lower triangle of a distance matrix (using the vincenty approximation) I would need to generate 36,742*36,741*0.5 = 1,349,974,563 distances. I want to keep the pair combinations which are within 50km of each other. My current set-up is as follows shops= [[id,lat,lon]...] def lower_triangle_mat(points): for i in range(len(shops)-1): for j in range(i+1,len(shops)): yield [shops[i],shops[j]] def return_stores_cutoff(points,cutoff_km=0): below_cut = [] counter = 0 for x in lower_triangle_mat(points): dist_km = vincenty(x[0]

How to get straight distance between two location in android?

安稳与你 提交于 2019-12-03 03:58:54
问题 First read Question carefully ... I need straight distance , not by walking,car ,or etc. Take a look to this image which given below, Google provide us distance by car and driving. But I don't want it, I want straight distance between two location (latitude - longitude). Which is displayed as as RED LINE. NOTE : I don't want to put red line on Google map, just want the Distance in Units (mile,km,etc.) 回答1: ANDROID double distance Location locationA = new Location(“point A”) locationA

Distance between Long Lat coord using SQLITE

六眼飞鱼酱① 提交于 2019-12-03 03:48:28
I've got an sqlite db with long and lat of shops and I want to find out the closest 5 shops. So the following code works fine. if(sqlite3_prepare_v2(db, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) { while (sqlite3_step(compiledStatement) == SQLITE_ROW) { NSString *branchStr = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)]; NSNumber *fLat = [NSNumber numberWithFloat:(float)sqlite3_column_double(compiledStatement, 1)]; NSNumber *fLong = [NSNumber numberWithFloat:(float)sqlite3_column_double(compiledStatement, 2)]; NSLog(@"Address %@, Lat = %@,

Jensen-Shannon Divergence

眉间皱痕 提交于 2019-12-03 03:19:42
问题 I have another question that I was hoping someone could help me with. I'm using the Jensen-Shannon-Divergence to measure the similarity between two probability distributions. The similarity scores appear to be correct in the sense that they fall between 1 and 0 given that one uses the base 2 logarithm, with 0 meaning that the distributions are equal. However, I'm not sure whether there is in fact an error somewhere and was wondering whether someone might be able to say 'yes it's correct' or

Algorithm for finding nearby points?

匆匆过客 提交于 2019-12-03 02:46:30
问题 Given a set of several million points with x,y coordinates, what is the algorithm of choice for quickly finding the top 1000 nearest points from a location? "Quickly" here means about 100ms on a home computer. Brute force would mean doing millions of multiplications and then sorting them. While even a simple Python app could do that in less than a minute, it is still too long for an interactive application. The bounding box for the points will be known, so partitioning the space into a simple

Approximate, incremental nearest-neighbour algorithm for moving bodies

橙三吉。 提交于 2019-12-03 02:04:16
问题 Bounty This question raises several issues. The bounty will go to an answer which addresses them holistically. Here's a problem I've been playing with. NOTE I'm especially interested in solutions that are not based in Euclidian space. There is a set of Actors which form a crowd of size K. The distance d(ActorA,ActorB) is easily computable for any two actors (solutions should work for various definitions of 'distance') and we can find the set of N nearest neighbours for any given Actor using

I want to calculate the distance between two points in Java

拜拜、爱过 提交于 2019-12-03 01:14:08
OK, so I've written most of a program that will allow me to determine if two circles overlap. I have no problems whatsoever with my program aside from one issue: the program won't accept the code I've written for the distance between the two center points. I can figure out the if/else logic to tell the user what happens depending on the value of distance later, but I want to know what's wrong now. Eclipse, the program I'm coding on, is telling me that distance should be resolved to an array, but I've already told you that it's an int. Here is my code: package circles; import java.util.Scanner;

Distance between 2 hexagons on hexagon grid

本小妞迷上赌 提交于 2019-12-03 01:05:31
I have a hexagon grid: with template type coordinates T. How I can calculate distance between two hexagons? For example: dist((3,3), (5,5)) = 3 dist((1,2), (1,4)) = 2 First apply the transform (y, x) |-> (u, v) = (x, y + floor(x / 2)). Now the facial adjacency looks like 0 1 2 3 0*-*-*-* |\|\|\| 1*-*-*-* |\|\|\| 2*-*-*-* Let the points be (u1, v1) and (u2, v2). Let du = u2 - u1 and dv = v2 - v1. The distance is if du and dv have the same sign: max(|du|, |dv|), by using the diagonals if du and dv have different signs: |du| + |dv|, because the diagonals are unproductive In Python: def dist(p1,

Nearest Neighbours using Quaternions

爱⌒轻易说出口 提交于 2019-12-03 00:27:10
Given a quaternion value, I would like to find its nearest neighbour in a set of quaternions. To do this, I clearly need a way to compare the "distance" between two quaternions. What distance representation is needed for such a comparison and how is it computed? Thanks, Josh Olhovsky Is your quaternion just a point in 3D space with an orientation? Then the distance between two quaternions x1,y1,z1,w1 and x2,y2,x2,w2 is given by: distance = sqrt((x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2) , assuming that the w component is used for orientation. I.e. this is the same as the distance between two 3D points