distance

2D Game: Fast(est) way to find x closest entities for another entity - huge amount of entities, highly dynamic

本小妞迷上赌 提交于 2019-12-03 00:08:02
I'm working on a 2D game that has a huge amount of dynamic entities. For fun's sake, let's call them soldiers, and let's say there are 50000 of them (which I just randomly thought up, it might be much more or much less :)). All these soldiers are moving every frame according to rules - think boids / flocking / steering behaviour. For each soldier, to update it's movement I need the X soldiers that are closest to the one I'm processing. What would be the best spatial hierarchy to store them to facilitate calculations like this without too much overhead ? (All entities are updated/moved every

How do I manipulate/access elements of an instance of “dist” class using core R?

試著忘記壹切 提交于 2019-12-03 00:05:59
A basic/common class in R is called "dist" , and is a relatively efficient representation of a symmetric distance matrix. Unlike a "matrix" object, however, there does not seem to be support for manipulating an "dist" instance by index pairs using the "[" operator. For example, the following code returns nothing, NULL , or an error: # First, create an example dist object from a matrix mat1 <- matrix(1:100, 10, 10) rownames(mat1) <- 1:10 colnames(mat1) <- 1:10 dist1 <- as.dist(mat1) # Now try to access index features, or index values names(dist1) rownames(dist1) row.names(dist1) colnames(dist1)

Programmatical approach in Java for file comparison

核能气质少年 提交于 2019-12-02 23:58:06
What would be the best approach to compare two hexadecimal file signatures against each other for similarities. More specifically, what I would like to do is to take the hexadecimal representation of an .exe file and compare it against a series of virus signature. For this approach I plan to break the file (exe) hex representation into individual groups of N chars (ie. 10 hex chars) and do the same with the virus signature. I am aiming to perform some sort of heuristics and therefore statistically check whether this exe file has X% of similarity against the known virus signature. The simplest

MongoDB Bound Queries: How do I convert mile to radian?

好久不见. 提交于 2019-12-02 20:44:44
I have a collection of stores with a geospacial index on the location propery. What I am trying to do is given the user's latitude, latitude and a search radius (mi), I want to return the list of stores that are within those parameters. I saw the following example on the MongoDB documentation ( http://www.mongodb.org/display/DOCS/Geospatial+Indexing ), but it looks like the distance is in radians. center = [50, 50] radius = 10 db.places.find({"loc" : {"$within" : {"$center" : [center, radius]}}}) So, what is the formula to convert miles to radians? Solution The awesome people at mongodb-user

PHP/MySQL: Select locations close to a given location from DB

情到浓时终转凉″ 提交于 2019-12-02 19:44:19
In PHP, I have the following code for calculating the distance between two locations: <?php function distance($lat1, $long1, $lat2, $long2) { // DEGREE TO RADIAN $latitude1 = $lat1/180*pi(); $longitude1 = $long1/180*pi(); $latitude2 = $lat2/180*pi(); $longitude2 = $long2/180*pi(); // FORMULA: e = ARCCOS ( SIN(Latitude1) * SIN(Latitude2) + COS(Latitude1) * COS(Latitude2) * COS(Longitude2-Longitude1) ) * EARTH_RADIUS $distance = acos(sin($latitude1)*sin($latitude2)+cos($latitude1)*cos($latitude2)*cos($longitude2-$longitude1))*6371; return $distance; } echo distance(9.9921962, 53.5534074, 9

Objective c string formatter for distances

孤街醉人 提交于 2019-12-02 19:37:56
I have a distance as a float and I'm looking for a way to format it nicely for human readers. Ideally, I'd like it to change from m to km as it gets bigger, and to round the number nicely. Converting to miles would be a bonus. I'm sure many people have had a need for one of these and I'm hoping that there's some code floating around somewhere. Here's how I'd like the formats: 0-100m: 47m (as a whole number) 100-1000m: 325m or 320m (round to the nearest 5 or 10 meters) 1000-10000m: 1.2km (round to nearest with one decimal place) 10000m +: 21km If there's no code available, how can I write my

Finding maximum distance between two points in a list (scheme)

拈花ヽ惹草 提交于 2019-12-02 19:24:20
问题 I'm currently trying to write a function from a list of points that returns the distance from a point p to a point in my point list that is farthest away from p. My list of points are the following: ((2 . 4) (3 . 6) (5 . 12) (-4 . 3) (8.4 . 9) (0 . -1)) I have also made some abstractions to retrieve the general car and cdr (for easier visibility in the code), as well as the car and cdr of the list itself. (define (get-x p) (car p) (define (get-y p) (car p) (define (get-first-point pt-list)

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

不羁的心 提交于 2019-12-02 18:14:10
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 the singular red one. This is harder than it sounds! I doubt there is better solution than calculating

Finding closest point from other data frame

纵饮孤独 提交于 2019-12-02 17:35:12
问题 I have two data frames , one is with 0.8 million rows with x and Y coordinates, another data frame is of 70000 rows with X and Y coordinates. I want to know logic and code in R where I want to associate data point from frame 1 to closest point in data frame 2. Is there any standard package to do so ? I am running nested for loop. But this is very slow as it is getting iterated for 0.8 million * 70000 times which is very time consuming. 回答1: I found a faster way to get the expected result

How to assign a name to lat-long observations based on shortest distance

女生的网名这么多〃 提交于 2019-12-02 17:25:00
问题 I have two dataframes: df1 contains observations with lat-lon coordinates; df2 has names with lat-lon coordinates. I want to create a new variable df1$name which has for each observation the name of df2 that has the shortest distance to that observation. Some sample data for df1 : df1 <- structure(list(lat = c(52.768, 53.155, 53.238, 53.253, 53.312, 53.21, 53.21, 53.109, 53.376, 53.317, 52.972, 53.337, 53.208, 53.278, 53.316, 53.288, 53.341, 52.945, 53.317, 53.249), lon = c(6.873, 6.82, 6.81,