distance

Distance between istream_iterators

∥☆過路亽.° 提交于 2019-11-28 12:45:30
I am trying to count the amount of elements read by std::cin by using std::distance for the constructor argument of a vector in advance, like so: // Gives correct amount, but now can't use to put into vector int size = std::distance(std::istream_iterator<std::string>(std::cin), std::istream_iterator<std::string>()); std::vector v(size); // Already read from stream std::copy(...); Obviously I can complete this in one step with std::copy , but that would require setting a size beforehand. My question isn't about vectors though, it's about getting the size of an arbitrary input using std::istream

android google map finding distance

对着背影说爱祢 提交于 2019-11-28 12:42:25
I am trying to find distance between two locations. I have longitudes and latitudes and I can calculate Euclidean distance. But I want to find road distance. I mean, , I want to calculate the distance of the road that I am going on while going to destination from source. In this case how to calculate this? The easiest way would be to use the Google Directions API to get the directions, this gives you a list of all the points along the route (and the total distance). Check out : http://code.google.com/apis/maps/documentation/directions/ If your not sure how to do this let me know and i'll post

Efficient (memory-wise) function for repeated distance matrix calculations AND chunking of extra large distance matrices

感情迁移 提交于 2019-11-28 11:43:16
I wonder if anyone could have a look at the following code and minimal example and suggest improvements - in particular regarding efficiency of the code when working with really large data sets. The function takes a data.frame and splits it by a grouping variable (factor) and then calculates the distance matrix for all the rows in each group. I do not need to keep the distance matrices - only some statistics ie the mean, the histogram .., then they can be discarded. I don't know much about memory allocation and the like and am wondering what would be the best way to do this, since I will be

as.matrix on a distance object is extremely slow; how to make it faster?

拟墨画扇 提交于 2019-11-28 10:01:31
问题 I found an R package Rlof which uses multithreading to calculate distance matrices and it does a wonderful job. However, the output of the function distmc is a vector rather than a matrix. Applying as.matrix to this "dist" object turns out much more expensive than the multi-threaded calculation of distances. Looking at the function help, the options for printing the diagonal and upper triangle are there, but I don't understand where they are supposed to be used. Is there a way of saving the

Python: speeding up geographic comparison

浪子不回头ぞ 提交于 2019-11-28 09:17:36
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 I'm doing is sensible. Some background: I have two collections of geographic points (latitude, longitude), one relatively small collection and one relatively huge collection. For every point in the small collection, I need to find the closest point in the large collection. The obvious way to do this would be to use the haversine formula. The

Calculate distance between colors in HSV space

人走茶凉 提交于 2019-11-28 08:41:21
I intend to find a distance metric between two colours in HSV space. Suppose that each colour element has 3 components: hue, saturation, and value. Hue is ranged between 0 to 360, saturation is ranged between 0 to 1, and value is ranged between 0 to 255. Also hue has a circular property, for example, 359 in hue is closer to 0 in hue value than 10 in hue. Can anyone provide a good metric to calculate the distance between 2 colour element in HSV space here? First a short warning: Computing the distance of colors does not make sense (in most cases). Without considering the results of 50 years of

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

孤人 提交于 2019-11-28 06:56:06
问题 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 definition to calculate which is larger and then just do a simple subtraction: def distance(x, y): if x >= y: result = x - y else: result = y - x return result but I'd rather not have to call a custom function like this. From my limited experience I've

Parallel distance Matrix in R

非 Y 不嫁゛ 提交于 2019-11-28 06:29:15
currently I'm using the build in function dist to calculate my distance matrix in R. dist(featureVector,method="manhattan") This is currently the bottlneck of the application and therefore the idea was to parallize this task(conceptually this should be possible) Searching google and this forum did not succeed. Does anybody has an idea? Will Beason Here's the structure for one route you could go. It is not faster than just using the dist() function, instead taking many times longer. It does process in parallel, but even if the computation time were reduced to zero, the time to start up the

which data structure is appropriate to query “all points within distance d from point p”

扶醉桌前 提交于 2019-11-28 06:01:50
I have a 3D pointcloud and I'd like to efficiently query all points within distance d from an arbitrary point p (which is not necessarily part of the stored pointcloud) The query would look something like Pointcloud getAllPoints(Point p, float d); what accelerationstructure would be appropriate for this? A range-tree seems to be appropriate only for querying rectangular volumes, not sphere volumes (of course I could query the boundingbox of the sphere and then sort out all vertices that have larger distance than d - but maybe there is a better way to do this??) thanks! according to Novelocrats

Manhattan Distance between tiles in a hexagonal grid

梦想的初衷 提交于 2019-11-28 05:26:34
For a square grid the euclidean distance between tile A and B is: distance = sqrt(sqr(x1-x2)) + sqr(y1-y2)) For an actor constrained to move along a square grid, the Manhattan Distance is a better measure of actual distance we must travel: manhattanDistance = abs(x1-x2) + abs(y1-y2)) How do I get the manhattan distance between two tiles in a hexagonal grid as illustrated with the red and blue lines below? aaz I once set up a hexagonal coordinate system in a game so that the y -axis was at a 60-degree angle to the x -axis. This avoids the odd-even row distinction. (source: althenia.net ) The