Nearest neighbor search with quadtrees

hi guys;
i'm interested in implementing an algorithm to watch for possible collisions between celestial planets...
this algorihm consists of checking for a given planet with coordinates(x,y) if some other planet in the system came closer than a given distance...this algorithm should perform better than the naive one which consists of cheking the distance against every other planet and which is o(n) (n is the number of planets in the system)
it would be preferable to use a quadtree for a nearest neighbor search algorithm to implement this collision watch algorithm...
please help me ! some sample code would be very welcomed
thanks

[url http://forum.java.sun.com/thread.jsp?thread=571601&forum=31]Cross-post.

Similar Messages

  • Exporting a movie with the settings "nearest neighbor"

    Hello everybody!
    I am trying to upscale a movie from an old video game. The resolution is 320x240 and should be upscaled to 1440x1080. The problem is that I don't want Adobe Premiere Pro 6 to upscale it using a chroma subsampling method (http://ingomar.wesp.name/2011/04/dosbox-gameplay-video-capture.html), instead I want to use something similar to the option "nearest neigbor" (the one you have in Adobe Photoshop when you resize images). Why I want this is because I want to keep the pixels from the video game sharp. Is this possible to do?

    And if you take a screen cap, import it into Photoshop and upscale by a factor 4 (with Nearest Neighbour) the result is amazing!
    Actually, I find that up-rezzing with the Nearest Neighbor algorithm to be about the lowest quality of any of the algorithms. It came first, and is basically a holdover from about PS version 2.5. Bicubic interpolation was added later, and then Bicubic Smoother and Bicubic Sharper.
    However, I am always working with continuous tone, high-rez digital photographs, and not screen-caps, so perhaps my material is not the ultimate to judge Nearest Neighbor?
    Still, for a 16x increase, about the only thing that I can suggest (and this is for Stills, and not Video) would be Genuine Fractals (once Human Softaware, but acquired by another company). Still, that is beyond the max limit that I would be comfortable with.
    Others have mentioned Red Giant's Magic Bullet Instant HD, and I would download the trial, then test. That might be "as good as it get."
    Good luck,
    Hunt

  • Mountains and nearest neighbor do not mix

    Note - this is not an Oracle question - but something as food for thought. Appropriate I think as graph is now a big component of the product...
    While on vacation in Colorado last week, we decided to head up to Crested Butte to see a local play production. My wife, searching for a local motel on a site I will not name, found one with great ratings that was quite reasonable and about "30 miles" away. Not being from Colorado, she went ahead and booked it, and then told me where it was. I shook my head. That is no where near 30 miles away, at least by road - it is on the other side of the mountain!
    Obviously this company uses a point to point with nearest neighbor "as the crow flies" method. While simple points might work reasonably well for small areas, say in a city road grid, it is a horrible solution for larger areas and places like Colorado. With mountains that take hours to drive around, those 30 miles or so turn out to be 90 miles of road and take about 3 hours to drive based on posted speeds!
    Needless to say, I was upset. After spending almost an hour on the phone to get this all straightened out and the bill credited, I thought I'd point this out. Not only for "buyer beware" - but mainly as a good example of what not to do when designing map-based systems for consumers. KISS is usually a good approach, but in this case it is a horrible one when a road network with speeds AKA network data model graph solution is required.
    Bryan

    Good point.
    Thinking further, even in a city grid you have one-way streets, parks, longer blocks, etc., which can make the real distance (by road) much further than "as the crow flies". So I'm not sure nn is really good for any such "close to me" analysis tool.
    And yes thanks, had a great vacation. Miss the cool weather from my native state!
    Bryan

  • Cloud of Points Tree /Nearest Neighbor

    Hi guys;
    I'm using a binary tree to construct a tree of two dimensional points .here is how i construct the tree :
    the tree is constructed by successive subdivision of the Plan by semi-Lines accross a given point.
    the first subdivision is done by say a horizantal line across a given point.the plan is then split into two regions : the upper and lower half plans. the points in the upper plan will be in the right subtree and those in the lower plan will go into the left subtree.
    in the next step the plan will be subdiveded by a VERTICAL semi-line at this time : the points at the left of this line will be placed in the left subtree and those on the right will be placed to right subtree.
    Now i managed to write an insert() method for this :
    static Tree insert(Point p, Tree a, boolean vertical)
         if (a == null)
         return new Tree(null, p, null);
         boolean estAGauche =
         (vertical) ? (p.x < a.p.x) : (p.y < a.p.y);
         if (estAGauche)
         Tree g = insert(p, a.filsG, !vertical);
         return new Tree(g, a.p, a.filsD);
         else
         Tree d = insert(p, a.filsD, !vertical);
         return new Tree(a.filsG, a.p, d);
         static Tree insert(Point p, Tree a)
         return insert(p, a, false);
         }Now i want to tackle another problem : given the tree is filled with a cloud of points.
    if i pick a given point in the cloud ,i want to find the nearest neighbor of this point using the tree construct i described above.
    is this possible ? How can I implement it ?
    Many thanks for helping !

    this is because i will be dealing with a verylarge
    number of points so efficiency here is definitelya
    crucial issue...what do you think josiah ?Well, I've used that little algorithm for a global
    map with, say, 1e6 known points
    and the response was always almost intantaneous. It
    depends on the distribution
    of your known points, i.e. you can easily draw
    pathetic situations on a piece of
    paper but on average the nearest point is found
    withing a few searches (after
    finding those two lines using an O(log(n)) binary
    search ...
    Two dimensional locality doesn't help you much when
    you're using quad-trees;
    as has been said before in this thread: two nearest
    points may be miles apart
    in the tree.
    What does help (altough not much) is, after sorting
    the points on increasing Y
    values, do a minor sort using Gray-codes on the X
    coordinate. But that's for a
    later discussion ;-)
    kind regards,
    Jos
    Well, I've used that little algorithm for a global
    map with, say, 1e6 known points
    and the response was always almost intantaneous. It
    depends on the distribution
    of your known points, i.e. you can easily draw
    pathetic situations on a piece of
    paper but on average the nearest point is found
    withing a few searches (after
    finding those two lines using an O(log(n)) binary
    search ...
    What you say is very encouraging so i will try your little algorithm for sure.
    any way At this first stage of my application i'm not demanding some extra ordinary work to be acheived , and this one would be surely very sufficient..
    Two dimensional locality doesn't help you much when
    you're using quad-trees;
    as has been said before in this thread: two nearest
    points may be miles apart
    in the tree.
    you right !
    What does help (altough not much) is, after sorting
    the points on increasing Y
    values, do a minor sort using Gray-codes on the X
    coordinate. But that's for a
    later discussion ;-)
    something interesting i'll be patiently waiting for ;)
    kind regards,
    JosMany thanks ,

  • Nearest Neighbor Query takes 7 minutes

    Hello there, First time poster on the forums. 
    I've been looking into spatial comparison recently and have come across a few problems. The query I run takes 7 minutes to return the nearest neighbor. 
    My table that has the Geographical locations is of the following structure and has 1.7 million rows. 
    CREATE TABLE [dbo].[PostCodeData](
    [OutwardCode] [varchar](4) NOT NULL,
    [InwardCode] [varchar](3) NOT NULL,
    [Longitude] [float] NULL,
    [Latitude] [float] NULL,
    [GeoLocation] [geography] NULL,
    CONSTRAINT [PK_PostCodeData] PRIMARY KEY CLUSTERED
    [OutwardCode] ASC,
    [InwardCode] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    I have another table with many records on which I only have a Geography point (which I call Geolocation) and I'm trying to get the postcode from the PostCodeData table based on the nearest [GeoLocation] naturally.
    This is my query at the moment :
    SELECT top 2 [PostCode]
    ,[Geolocation]
    , (select top 1 pc.InwardCode from PostCodeData pc order by pc.GeoLocation.STDistance(bg.Geolocation)) found_post_code
    FROM [tbl_potatoes] bg
    where bg.Geolocation is not null
    This query is taking 7 minutes and as you can see I'm only doing this for 2 (top 2) records from the burning_glass table. What would happen if I wanted to process the whole table which has like 700k rows.
    What I've tried: 
    1. Created a spatial index.
    2. Followed a post somewhere on these forums about applying it as a hint (WITH: WITH (INDEX(ixs_postcode)))
    It didn't let me apply the hint and gave the following error : 
    Query processor could not produce a query plan because of the hints defined in this query. Resubmit the query without specifying any hints and without using SET FORCEPLAN.
    Any help is appreciated. 

    Just before the end of the day yesterday, a colleague of mine spotted the missing 'Where' in the subquery and we added it in.
    The query now looks as such : 
    UPDATE top(200) tbl_potatoes
    SET PostCode =
    select top 1 pc.OutwardCode
    from PostCodeData pc
    where pc.GeoLocation.STDistance(Geolocation) < 1000
    order by pc.GeoLocation.STDistance(Geolocation)
    WHERE Geolocation is not null;
    The problem is, this query still takes a while. It now takes 3min27seconds for 200 rows. Not that this bit of math would be accurate in any way however if it takes 207seconds to do 200 rows, to do 300,00 it will most likely take somewhere between 80 to 90
    hours. 
    This is hardly going to be something that is going to work.
    That was the update - the SELECT statement :
    SELECT top 200 [PostCode]
    ,[Geolocation]
    , (select top 1 pc.OutwardCode
    from PostCodeData pc
    where pc.GeoLocation.STDistance(bg.Geolocation) < 1000
    order by pc.GeoLocation.STDistance(bg.Geolocation)) found_post_code
    FROM [tbl_potatoes] pot
    where Geolocation is not null
    Takes just 23seconds for 200 records. Meaning it would take around 10 hours for 300k.
    I tried Isaacs second example where he uses the STBuffer(10000) but it leads even more time in the select statement and quite frankly I don't get what is going on in his 3rd example where he talks about his declarative syntax.

  • K Nearest Neighbor Algorithm Code in Java

    I am looking for a code in Java for K nearest neighbor algorithm (considering clusters if possible which is able to detect outlier clusters).
    Thanks!
    Edited by: win13 on Oct 1, 2007 11:54 AM
    Edited by: win13 on Oct 1, 2007 12:00 PM

    interface MS{ // metric space
      double dist(MS p); // distance between this point and argument
    MS[] kNN(MS data, MS target, int k){
      MS[] res = new MS[k]; double[] d = new double[k];
      int n = 0; // number of element in the res
      // check inputs for validity
      if(data.length == 0 || k<=0) return res; // bail on bad input
      double dd = target.dist(data[0]); // load first one into list
      res[n] = data[0]; d[n++] = dd;
      // go through all other data points
      for(int i = 1; i<data.length; i++){
        if( n<k || d[k-1] > (dd = target.dist(data))){ //add one
    if(n<k){res[n] = data[i]; d[n++] = dd;}
    int j = n-1;
    while(j>0 && dd < data[j-1]){ // slide big data up
    res[j] = res[j-1]; d[j] = d[j-1]; j--;
    res[j] = data[i]; d[j] = dd;
    return res;
    As I said, I don't feel that this code is that difficult. I would be more concerned as to whether the data admits the particular definition of outlier that you have selected.
    It is a mistake to assume that one particular definition of a cluster or an outlier will work in all cases. For example using the definition you supply, if you have one single mega cluster of a thousand elements located within a foot of one another here on earth and you have about 10 other "clusters', each with but a single element, each a single light year apart but all somewhere out near the andromeda galaxy, you will conclude that cluster centers are on the average about one light year apart but that there is one bad outlier, that one way over there on earth.
    But, hey it's your data. Go nuts.
    Just for the record, I don't typically test code that I type into the forum so what I have supplied may not even compile and certainly should not be assumed to be correct. You will need to read it, and treat it as an outline for the code that you will need to write.
    Enjoy                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • The nearest neighbor interpolation problem

    Hello,
    After my Photoshop CS6 update I have problem with the Nearest Neighbor interpolation. It was working correctly before. I was setting the General and Free Transform preferences first and rotating pictures by 45 degrees then. It was always giving me pixel-perfect results in PS CS6. Now that stopped working. Am I missing something? I have made video showing my results and all the steps I am making:
    How about you? What your results are after rotating any picture by 45 degrees in the Nearest Neighbor interpolation mode? I would be happy to know what is wrong now and how to achieve good results. I will appreciate any help.

    What your results are after rotating any picture by 45 degrees in the Nearest Neighbor interpolation mode?
    The same mess with Ps 13.0.1 on OS X 10.6.8.
    Very interesting that the Free Transform looks good until it is actually commited.
    I don't know whether it was different in 13.0

  • How to use ADF Query search with EJB 3.0

    Hi,
    In ADF guide http://download.oracle.com/docs/cd/E12839_01/web.1111/b31974/web_search_bc.htm#CIHIJABA
    The steps to create query search with ADF Business Components says:
    "+From the Data Controls panel, select the data collection and expand the Named Criteria node to display a list of named view criteria.+"
    But with EJB, I'm not able to find Named Criteria node. Can we use ADF query search component with EJB? If yes, can you please show me some example, tutorial etc.?
    Thanks
    BJ

    For EJBs you'll need to implement the query model on your own.
    An example of how the model should look like is in the ADF Faces components demo.
    http://jdevadf.oracle.com/adf-richclient-demo/faces/components/query.jspx
    Code here:
    http://www.oracle.com/technology/products/adf/adffaces/11/doc/demo/adf_faces_rc_demo.html

  • How do i change the setting so that when i type something in the address bar, it searches with google. it's started using yahoo and i hate yahoo, i'm even considering leaving firefox

    somethings i type something in the address bar, like 'paypal', mozilla used to go straight to that website, which was helpful... then it started searching with google, this i was not too upset about... however now it has started searching with yahoo, this i am upset about, and i would like to change this, however i do not know how?

    1. Use  free  AdwareMedic by clicking “Download ” from here
        http://www.adwaremedic.com/index.php
        Install , open,  and run it by clicking “Scan for Adware” button   to remove adware.
        Once done, quit AdwareMedic by clicking AdwareMedic in the menu bar and selecting
        “Quit AdwareMedic”.
    2. Safari > Preferences > Extensions
         Turn those off and relaunch Safari to test .
         Turn those on one by one and test.
    3. Safari > Preferences >  Search > Search Engine :
        Select your preferred   search engine.
    4. Safari > Preferences > General > Homepage:
         Set your Homepage.

  • How to enhance the standard search with custom field?

    Hi all,
    I would like to know the general optimal procedure to enhance the standard searches like Opportunity search or Lead search.
    I've gone through some of the threads here. Some suggest, to add the new field using AET and copy the IMPL class of the search and then code the custom logic. Some say, append the new field to the structure of the search object and then implement the BADI.
    I'm actually a bit confused to understand the correct procedure.
    Can someone please help me with a generic procedure to enhance the standard search with a custom field?
    Thanks in advance.

    Hi Maren,
    Once I have got the same development. I have followed the below steps, please check with this. Let me know for further inputs.
      Add new field using Append structure of type ‘XXX’ in search
      Create BADI implementation for Enhancement spot ‘ES_CRM_RF_Q1O_SEARCH’ and include filter ‘BTQOPP’
      Put your logic in BADI implementation – SEARCH method
      Add it in WebUI configuration
      Remove the operator if required
    Regards,
    Swadini Sujanaranjan

  • Searching with in a SharePoint 2013 Document Library

    Hi,
    i want to search document library by passing values from Search box to Search Results webpart. I m not able to search with in the document library although i have configured content source and result sources. 
    With Regards,
    Jaskaran Singh

    You can try using a web form html webpart in a web part page instead.
    Use Designer to add additional search columns and you should be able to create something usable.
    Steven Andrews
    SharePoint Business Analyst: LiveNation Entertainment
    Blog: baron72.wordpress.com
    Twitter: Follow @backpackerd00d
    My Wiki Articles:
    CodePlex Corner Series
    Please remember to mark your question as "answered" if this solves (or helps) your problem.

  • How to customize quick query to search with SQL in contain keyword

    I want to build simple query using quick query component. But it will search with SQL equal keyword. How can I customize it to use contain keyword instead. That means, I enter 'sc' to return 'scott'.

    Not sure if the technique described here http://tompeez.wordpress.com/2011/08/21/extending-viewcriteria-to-use-sql-contains-4/ can be used for quick query, but you can try ...
    Timo

  • How to search with multiple constraints in the new java API?

    I'm having a problem using the new MDM API to do searches with multiple constraints.  Here are the classes I'm trying to use, and the scenario I'm trying to implement:
    Classes:
    SearchItem: Interface
    SearchGroup: implements SearchItem, empty constructor,
                 addSearchItem (requires SearchDimension and SearchConstraint, or just a SearchItem),
                 setComparisonOperator
    SearchParameter: implements SearchItem, constructor requires SearchDimension and SearchConstraint objects
    Search: extends SearchGroup, constructor requires TableId object
    RetrieveLimitedRecordsCommand: setSearch method requires Search object
    FieldDimension: constructor requires FieldId object or FieldIds[] fieldPath
    TextSearchConstraint: constructor requires string value and int comparisonOperator(enum)
    BooleanSearchConstraint: constructor requires boolean value
    Scenario:
    Okay, so say we have a main table, Products.  We want to search the table for the following:
    field IsActive = true
    field ProductColor = red or blue or green
    So the question is how to build this search with the above classes?  Everything I've tried so far results in the following error:
    Exception in thread "main" java.lang.UnsupportedOperationException: Search group nesting is currently not supported.
         at com.sap.mdm.search.SearchGroup.addSearchItem(Unknown Source)
    I can do just the ProductColor search like this:
    Search mySearch = new Search(<Products TableId>);
    mySearch.setComparisonOperator(Search.OR_OPERATOR);
    FieldDimension myColorFieldDim = new FieldDimension(<ProductColor FieldId>);
    TextSearchConstraint myTextConRed = new TextSearchConstraint("red",TextSearchConstraint.EQUALS);
    TextSearchConstraint myTextConBlue = new TextSearchConstraint("blue",TextSearchConstraint.EQUALS);
    TextSearchConstraint myTextConGreen = new TextSearchConstraint("green",TextSearchConstraint.EQUALS);
    mySearch.addSearchItem(myColorFieldDim,myTextConRed);
    mySearch.addSearchItem(myColorFieldDim,myTextConBlue);
    mySearch.addSearchItem(myColorFieldDim,myTextConGreen);
    the question is how do I add the AND of the BooleanSearchConstraint?
    FieldDimension myActiveFieldDim = new FieldDimension(<IsActive FieldId>);
    BooleanSearchConstraint myBoolCon = new BooleanSearchConstraint(true);
    I can't just add it to mySearch because mySearch is using OR operator, so it would return ALL of the Products records that match IsActive = true.  I tried creating a higher level Search object like this:
    Search topSearch = new Search(<Products TableId>);
    topSearch.setComparisonOperator(Search.AND_OPERATOR);
    topSearch.addSearchItem(mySearch);
    topSearch.addSearchItem(myActiveFieldDim,myBoolCon);
    But when I do this I get the above "Search group nesting is currently not supported" error.  Does that mean this kind of search cannot be done with the new MDM API?

    I'm actually testing a pre-release of SP05 right now, and it still is not functional.  The best that can be done is to use a PickListSearchConstraint to act as an OR within a field.  But PickList is limited to lookup Id values, text attribute values, numeric attribute values and coupled attribute values.  It works for me in some cases where I have lookup Id values, but not in other cases where the users want to search on multiple text values within a single field.

  • Personalized Simple Search with new messageLovInput - Search does not work

    I have currently set an Message LOV Input into a Simple Search Panel for IcxPorRcvSrchPG.
    I have got the LOV bringing back the correct values, but when I hit the GO button the Search does not work.
    Can someome please help me on how I am able to get the search working in the Simple Search Panel.
    Details of VO's are as follows:
    xxReceiveItemsDueVO (extended from ReceiveItemsDueVO)
    xxReceiveMyItemsVO (extended from ReceiveMyItemsVO )
    xxReceivePurchaseItemsVO (extended from ReceivePurchaseItemsVO)
    xxReceiveReqItemsVO (extended from ReceiveReqItemsVO)
    Extended Attribute I am looking to search with is xxWono.
    Current search items are working 100% with extended VO's, but when I try and search with new item, I am having no luck. The search is acting as though the new item has not even been created.
    Additional Lov Details are as follows:
    Level: Site
    Item Style: Message Lov Input
    ID: xxWONumSearch
    Data Type: VARCHAR2
    External LOV: /oracle/apps/icx/lov/webui/WorkOrderLovRN
    Prompt: Work Order Number
    Search Allowed: False
    Search Criteria: False
    Lov Map
    ID: xxWipEntityName
    Criteria Item: xxWONumSearch
    LOV Region: WipEntityName
    Programmatic Query: False
    Required: False
    Return Item: xxWONumSearch
    Framework version: 11.5.10.6RUP
    Is there a way of doing this through Personalization?
    With the version of framework I am not able to add a simpleSearchMapping through Personalization.
    Can someone please advise?
    Thanks
    Lee

    When I generate and then view the help, it looks perfect!  I changed the name of the project folder since the information is proprietary.  I have several pictures including the parent folder and the only 3 folders that are generated.  I cannot find the Webhelp output folder.  I think this is what you need to see.

  • IFS Searching with other Search Engines

    Is it possible to set up iFS searching with or without interMedia) that would work with a search engine for static pages, like Infoseek?
    From an "end-users" point of view, I would like to have them search for a document, some of which may be stored in the database, but others are html pages used for the site.

    You would have to write a custom program which would submit searches to IFS and to your Infoseek search engine, and then combine the results for the end user.
    Or you could use iFS and Intermedia to index the static HTML pages.

Maybe you are looking for

  • Class/member variables usage in servlets and/or helper classes

    I just started on a new dev team and I saw in some of their code where the HttpSession is stored as a class/member variable of a servlet helper class, and I was not sure if this was ok to do or not? Will there be problems when multiple users are acce

  • Give me some advice about the big message

    Whether JMS provider provide the function to deal with big message? i haven't found.Whether should I split the message myself? but if i split myself,the message as a whole will be difficult to ensure whole.I can only receive message one by one.If i o

  • Is it possible to make a fixed size page in muse, so it doesn't resize?

    I want to make a fixed size page (pic1), but there always an extra space on the bottom- pic2

  • Easily duplicate / paste layer in different group folder?

    I design Web sites using Layer Comps so the homepage and innerpage examples are all in one .PSD. This means my Photoshop CC file has TONS of layers and folders that require me to scroll in the Layers Palette. Is there a way to copy/paste or move a la

  • Can I use iMovie HD6 on new Core i5/i6 iMac?

    Can I use iMovie HD6 on new Core i5/i6 iMac with Snow Leopard? If not what older iMac version do I need? I want to be able to edit HDV mini-tapes (from Canon HV20) and retain excellent quality (no deinterlacing), and that's why I cannot use iMovie 8