FAQ Database Discussion Community

## List of coordinates to matrix of distances

python,numpy,matrix,distance
I've got a list of 8 coordinates stored as list of lists: coordinates = [[47.2486, -1.54806], [43.5656, 1.47417], [48.3592, -4.57], [48.1439, 17.1097], [39.6275, 140.198], [30.0458, 31.2625], [38.9371, -77.0869], [33.9, 35.4823]] With the following script, I seek to output a matrix of coordinates: import numpy from scipy.spatial.distance import pdist coordinates_array =...

## Measuring the distance between two relative frequency vectors

distance,shape,similarity,euclidean-distance
I am having a problem in choosing a adequate distance function to measure the similarity (dissimilarity) between two relative frequency vectors. More specifically, I am using shape feature vectors that contain data about the basic shapes (circle, triangle, square) present in an image. Thus the vectors are in the form...

## Euclidian Distance of Two (Non-traditional) Vectors in Python

python,out-of-memory,distance
I have two non-traditional vectors and I'd like to compute the Euclidian distance between them. The vectors are set up as follows: line1 = '2:20 3:20 5:10 6:10 10:20' line2 = '1:18 2:20 4:10 6:10 8:20 9:10 10:10' For each element, the first number is the location in the vector...

## How to aggregate in R with a custom function that uses two columns

r,aggregate,distance
Is it possible to aggregate with a custom function that uses two columns to return one column? Say I have a dataframe: x <- c(2,4,3,1,5,7) y <- c(3,2,6,3,4,6) group <- c("A","A","A","A","B","B") data <- data.frame(group, x, y) data # group x y # 1 A 2 3 # 2 A 4...

## In C#, how could I get a class's inheritance distance to base class?

c#,subclass,distance
For example: I have the following classes: public class A {} public class B:A {} public class C:B {} public class D:C {} If there is a convenient method like to get a hierarchy distance to the base class(instead of testing D.IsSubclassOf(B)) to determine if D is closer to A,...

## How to make simple calculation with Javascript to know travel time?

javascript,variables,time,distance
I'm stuck on this and it's so simple but I don't understand anything of Javascript. Basically I want to create a simple calculation to know the travel time, based on three different variables. I'll have to say real quick that I'm dutch so some words are dutch and some are...

## distance matrix google maps gives wrong distance between two locations while using in curl php code

\$userLat1=51.509904342252; \$userLong1= -0.13413459062576; \$userLat2=51.517618; \$userLong2= -0.096778; \$userLat3=51.5017863; \$userLong4= -0.0536478; \$userLat=51.509904342252; \$userLong= -0.13413459062576; \$lat2=51.495042; \$long2= -0.131382; \$url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=".\$userLat.",".\$userLong."&destinations=".\$lat2.",".\$long2."&mode=driving&sensor=false"; //\$response = file_get_contents(\$url); \$ch = curl_init(); curl_setopt(\$ch, CURLOPT_URL, \$url); curl_setopt(\$ch,...

## Calculating distance between two points in 3D

java,distance,getter-setter,coordinate,euclidean-distance
My assignment is to create main class in which I initialize the value of any point to be at (0,0,0) and to be able to access and mutate all three values (x,y,z) individually. To do this I have used getters and setters. My next task is to create a method...

## calculate distance live and order asc|desc

sql,order,distance,live
So when i start the web app, the server gets the user geolocation and save it as variable (latitude/longitude) I've got a database with: ID, Name, Latitude, Longitude Now i want to select all entries from the database and order them by distance I know how to calculate the distance...

## GMSGeometryLength in Android

android,ios,path,location,distance
I am porting a iOS code on Android, and I need to get the length of a polyline, which I have as an Array of LatLng's. This is the code of the IOS app that I'm trying to replicate: GMSPath *pathOfStep = nextDict[@"path"]; double progressOnStep = GMSGeometryLength(pathOfStep); Now how could...

## Android GestureDetector onScroll unexpected behavior

android,distance,gesture,repeat
I have SimpleGestureDetectorListener and implemented onScroll as follows: public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { Log.i("MOVE_LARGE", "e1.getY=" + e1.getY()+" "+"e2.getY="+e2.getY()); Log.i("MOVE_SMALL", "distanceY=" + distanceY); FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) fragmentContainer.getLayoutParams(); int nextMargin = params.topMargin - (int) distanceY; if (Math.abs(distanceY )> MOVE_TRESHOLD) { setContainerMargin(nextMargin); } return true; }...

## Find longest distance from a certain point (java, 2d diagram)

java,distance
I'm working on a clustering program in Java. I'm trying to find the point that has the longest distance from another point in an 2-dimentional diagram with x and y axis. I though I could use pytagoras: Where the square of the Y-axis of the starting point + the square...

## racket: maximum height of a binary tree

tree,binary,height,racket,distance
I'm trying to create a code in racket that will find the maximum distance in a binary search tree from the root to a leaf. I've seen this done in C++ but am having trouble translating it to racket. I've managed to calculate all the nodes in a tree, but...

## Calculating distance between two elements only in the array in python

python,arrays,distance,euclidean-distance
So I have two questions: First I'm trying to print my array that contains 1004 elements but it's printing only the first 29 elements and then jumping to 974 to continue printing. How can I get the full array of 1004 elements? This is my code paired_data = [] for...

## Google API Distance Matrix, no value for distance

Hi I receive the following error in my logcat and I do not know what is the problem: (I have added log statements) D/loop!﹕ rows D/loop!﹕ elements W/System.err﹕ org.json.JSONException: No value for distance W/System.err﹕ at org.json.JSONObject.get(JSONObject.java:355) W/System.err﹕ at org.json.JSONObject.getJSONObject(JSONObject.java:574) W/System.err﹕ at info.tabsswipe.Results.getDistance(Results.java:279) Here is my code: String distance = getDistance(currentlatitude,...

## NoSQL DB for searching in vector space

vector,redis,cassandra,nosql,distance
I am completely new to NoSQL DBS such as Cassandra, Mongo, Redis, etc. and I want to create this type of a structure : { "item_id": "ABC1", "x1": 0.55, "x2": -0.29, ... "x100": 0.17 } Basically, I have millions of items and 100 floats associated with each of them. My...

## storing a matrix as a collection in MongoDB

mongodb,matrix,distance,point,asymmetric
I have a bunch of points {A, B, C, ...., X} and I want to store their distances in a matrix. One extra complication is that the distance from A to B and not the same as the distance from B to A, they are asymmetric. My aim is to...

## How do I calculate the distances between a varied location and fixed coordinates?

matlab,grid,coordinates,distance
I have four supply stations (S1, S2, S3 S4) and End Point (EU) with fixed coordinates on a grid as follows. % Grid Definition n = 10; % Number of grids in the x-direction x = 50; % Dimension of a grid in the x-direction k = 8; % Number...

## Java comparator with relative distance

java,dictionary,data-structures,distance,comparator
I'm trying to create an ordered map which uses relative distance comparisons. However, the way ConcurrentSkipListMap(which is what I'm using at the moment) interprets comparisons from Comparator makes comparing relative distances impossible. Are there any data structures which allow for map like key-value operations and relative ordering? When I say...

## get nearest coordinate from sqlite database

sqlite,coordinates,distance
I have a point coordinate based on two double values x0,y0 both in this format: xx.x (point as decimal separator) In a database I have a list of lines that are defined by the coordinates x1,y1 as startpoint and x2,y2 as endpoint. Among other columns, (such as line thickness and...

## Calculating distances between unique Python array regions?

python,arrays,numpy,scipy,distance
I have a raster with a set of unique ID patches/regions which I've converted into a two-dimensional Python numpy array. I would like to calculate pairwise Euclidean distances between all regions to obtain the minimum distance separating the nearest edges of each raster patch. As the array was originally a...

## Google Maps Distance Matrix API versus others

I have been researching google maps distance matrix API and am wondering if google maps is the best/cheapest distance calculation API? I am currently developing an application that will need to quickly figure out the distance between two cities, but am relatively low on money. I know that Google Maps...

## Calculate the pixel distance to three defined pixel in matlab

matlab,distance
I want to classify pixels of one tiff image according to pixel's RGB colour. The input is an image and three predefined colours for water(r0,g0,b0), forest(r1,g1,b1) and building(r2,g2,c2). The classification is based on the distance between image pixel and these three colors. If a pixel is closet to the water,...

## How to calculate distance between a fixture and a point in Box2D/Farseer?

c#,c++,box2d,distance,farseer
Basically, I have a fixture, and a point. I want to know the distance between them (not between their centers). I know there exists the Distance API, but it only works with 2 fixtures :/...

## How can I zero out weak elements near stronger ones in a matrix?

matlab,image-processing,matrix,distance,vectorization
I have a pixel matrix containing some points and a lot of zero elements. From those non-zero points, I want to discard those that have a stronger point in range N withing the matrix. The range is an euclidean distance between the pixels. input = [0.0 0.0 0.0 0.9 0.0...

## Pandas Ordinal Variable Treatment in Similarity Calculation

python,pandas,distance,similarity,categorical-data
I have a Pandas version 0.15.2 dataframe as below with an ordinal column rate, represented initially as strings. My end goal is to find the similarities of different rows in the df (in reality I have a lot more rows and more ordinal variables). Currently, to factorize() while enforcing the...

## How to check a point is inside an ellipsoid with orientation?

algorithm,3d,geometry,distance,computational-geometry
For an ellipsoid of the form with orientation vector and centre at point , how to find whether a point is inside the ellipsoid or not? An additional note that the geometry actually is with a=b (spheroid) and therefore one axis is sufficient to define orientation Note: I see a...

## Combining distances measures ie. colour and edge

java,colors,distance,edge
Say I have calculated the euclidean distance between two images using colour as a feature and also calculated the distance between the two images using edge. I want to test to see if combining these two distance values will give a better representation of how similar the images are. To...

## Python, Pairwise 'distance', need a fast way to do it

python,performance,binary,distance
For a side project in my PhD, I engaged in the task of modelling some system in Python. Efficiency wise, my program hits a bottleneck in the following problem, which I'll expose in a Minimal Working Example. I deal with a large number of segments encoded by their 3D beginning...

## Maintaining a constant distance between two sprites

ios,objective-c,sprite-kit,distance
Here's a distance formula I run through the update method to keep track of the distance between 2 sprites: -(void)distance { double dx = (_spriteA.position.x - _spriteB.position.x); //(x2 - x1); double dy = (_spriteA.position.y - _spriteB.position.y); //(y2 - y1); dist = sqrt(dx*dx + dy*dy); } -(void)update:(NSTimeInterval)currentTime { [self distance]; //Calculate...

## Calculate distance on a grid between 2 points

java,math,language-agnostic,distance
I need to calculate the distance on a grid between 2 points. The movement allowed is horizontal and vertical as well diagonal to the next neighbor (so 45 degree rotations). So Manhattan distance is not an option. Also Euclidean distance is not an option cause then it does not move...

## sort graph by distance to end nodes

algorithm,sorting,graph,distance
I have a list of nodes which belong in a graph. The graph is directed and does not contain cycles. Also, some of the nodes are marked as "end" nodes. Every node has a set of input nodes I can use. The question is the following: How can I sort...

## Check if location is within a certain distance of a set of other locations using R

r,match,geospatial,distance,latitude-longitude
I've been trying to solve this problem for a while now, but I can't seem to wrap my head around it. I am still new to R and a first time poster here. I tried to follow the rules as much as possible, but please let me know if I...

## Place 2 Boxes [div's] side by side

html,css,distance
I want to place the two boxes at the bottom of link, the both article-boxes (div.content), side by side like you see, but without the big distance between them. How to fix this? Here is relevant code : div.content { text-align: justify; color: #939393; padding: 25px 90px; margin: 0px auto...

## Given point of (latitude,longitude), distance and bearing, How to get the new latitude and longitude

distance,latitude-longitude,bearing
I found a piece of code on web. It calculates the Minimum bounding rectangle by a given lat/lon point and a distance. private static void GetlatLon(double LAT, double LON, double distance, double angle, out double newLon, out double newLat) { double dx = distance * 1000 * Math.Sin(angle * Math.PI...

## NetLogo: Measure maximum distance between 2 patches

distance,netlogo
my question is really trivial but as a beginner in NetLogo I still cannot find my answer.. I have created a patchy surface (available here: basic nlogo code) to setup clear-all setup-patches reset-ticks end ;create patchy surface to setup-patches ask n-of 5 patches [ set pcolor green ] ask patch...

## Measure distance between data set of 5D

python,arrays,matrix,distance,pdist
I want to measure the distance (Euclidean) between data sets of 5 dimensions. It looks like this: center x 0 [0.09771348879, 1.856078237, 2.100760575, 9.25... [-1.35602640228e-12, -2.94706481441e-11, -6.51... 1 [8.006780488, 1.097849488, 0.6275244427, 0.572... [4.99212418613, 5.01853294023, -0.014304672946... 2 [-1.40785823, -1.714959744, -0.5524032233, -0.... [-1.61000102139e-11, -4.680034138e-12, 1.96087... index, then point (center), and the third...

## geodesic distance transform in python

python,arrays,numpy,scipy,distance
In python there is the distance_transform_edt function in the scipy.ndimage.morphology module. I applied it to a simple case, to compute the distance from a single cell in a masked numpy array. However the function remove the mask of the array and compute, as expected, the Euclidean distance for each cell,...