Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 910291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:01:11+00:00 2026-05-15T17:01:11+00:00

I’ve got a 1km square, I’m dividing it up into 100meters both on the

  • 0

I’ve got a 1km square, I’m dividing it up into 100meters both on the positive and negative sides of it..

         __________y__________
         |         |         |
         |         |         |
         |         |         |
         |---------|---------| x
         |         |         |
         |         |         |
         |_________|_________|

Basically I’m making a square just like the one above. I’m diving it up into 100 meter squares both on the positive side and negative side of the x axis. I’m then plotting each point in their respective co-ords , I’m planning on throwing an (x,y) value through a bunch of if/else statements (at least 50 , upto 100) but I’m concerned with how expensive this would be. Is there a more efficient way of doing what I want to do?

Here is an example of how I plan on doing it…

              if(tlat < lat && tlat > lat - 89930.7){
            //point is within 100 meters on lat
            //On the NEGATIVE SIDE.
            if(tlng > lng && tlng < lng + 147999.8){
            //point is within 100 meters on lat NEGATIVE &&
            //withing 100 meters on lng POSITIVE
                layers.addcube(highlng100p, lowlng100p, yhigh, ylow, highlat100p, lowlat100p);
                highlng100p = highlng100p + 5;
                lowlng100p = lowlng100p + 5;
                highlat100p = highlat100p + 5;
                lowlat100p = lowlat100p + 5;
            }else if(tlng < lng && tlng > lng - 147999.8){
                //point is within 100 meters on lat NEGATIVE &&
                //withing 100 meters on lng NEGATIVE
                layers.addcube(highlat100n, lowlat100n, yhigh, ylow, highlng100n, lowlng100n);
                highlat100n = highlat100n + 5;
                lowlat100n = lowlat100n + 5;
                highlng100n = highlng100n + 5;
                lowlat100n = lowlat100n + 5;
            }else if(tlng > lng && tlng < lng + 295999.6){
                //point is within 200 meters on lat NEGATIVE &&
                //withing 200 meters on lng POSITIVE
                layers.addcube(highlat200n, lowlat200n, yhigh, ylow, highlng200p, lowlng200n);
                highlat200n = highlat200n + 5;
                lowlat200n = lowlat200n + 5;
                highlng200p = highlng200p + 5;
                lowlng200p = lowlng200p + 5;
            }else if(tlng < lng && tlng > lng - 295999.6){
                //point is within 200 meters on lat NEGATIVE &&
                //withing 200 meters on lng NEGATIVE
                layers.addcube(highlat200n, lowlat200n, yhigh, ylow, highlng200n, lowlng200n);
                highlat200n = highlat200n + 5;
                lowlat200n = lowlat200n + 5;
                highlng200n = highlng200n + 5;
                lowlng200n = lowlng200n + 5;
            }else if(tlng > lng && tlng < lng + 443999.4){
                //point is within 300 meters on lat NEGATIVE &&
                //withing 300 meters on lng POSITIVE
                layers.addcube(highlat300n, lowlat300n, yhigh, ylow, highlng300p, lowlng300p);
                highlat300n = highlat300n + 5;
                lowlat300n = lowlat300n + 5;
                highlng300p = highlng300p + 5;
                lowlng300p = lowlng300p + 5;
            }else if(tlng < lng && tlng > lng - 443999.4){
                //point is within 300 meters on lat NEGATIVE &&
                //withing 300 meters on lng NEGATIVE
                layers.addcube(highlat300n, lowlat300n, yhigh, ylow, highlng300n, lowlng300n);
                highlat300n = highlat300n + 5;
                lowlat300n = lowlat300n + 5;
                highlng300n = highlng300n + 5;
                lowlng300n = lowlng300n + 5;
            } else if(tlng > lng && tlng < lng + 591999.2){
                //point is within 400 meters on lng
                //on the POSITIVE SIDE
                layers.addcube(highlat400n, lowlat400n, yhigh, ylow, highlng400p, lowlng400p);
                highlat400n = highlat400n + 5;
                lowlat400n = lowlat400n + 5;
                highlng400p = highlng400p + 5;
                lowlng400p = lowlng400p + 5;
            }else if(tlng < lng && tlng > lng - 591999.2){
                //point is within 400 meters on lng
                //on the NEGATIVE SIDE
                layers.addcube(highlat400n, lowlat400n, yhigh, ylow, highlng400n, lowlng400n);
                highlat400n = highlat400n + 5;
                lowlat400n = lowlat400n + 5;
                highlng400n = highlng400n + 5;
                lowlng400n = lowlng400n + 5;
            }else if(tlng > lng && tlng < lng + 739999){
                //point is within 500 meters on lng
                //on the POSITIVE SIDE
                layers.addcube(highlat500n, lowlat500n, yhigh, ylow, highlng500p, lowlng500p);
                highlat500n = highlat500n + 5;
                lowlat500n = lowlat500n + 5;
                highlng500p = highlng500p + 5;
                lowlng500p = lowlng500p + 5;
            }else if(tlng < lng && tlng > lng - 739999){
                //point is within 500 meters on lng
                //on the NEGATIVE SIDE
                layers.addcube(highlat500n, lowlat500n, yhigh, ylow, highlng500n, lowlng500n);
                highlat500n = highlat500n + 5;
                lowlat500n = lowlat500n + 5;
                highlng500n = highlng500n + 5;
                lowlng500n = lowlng500n + 5;
            }
            } 

If anyone could help me make what I want to do much more efficient I’d appreciate it!
Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:01:11+00:00Added an answer on May 15, 2026 at 5:01 pm

    One way is to make a grid of cells, and use the distance of the point from the origin and the size of the cell to work out which cell the point goes into. The formula for calculating the cell is O(1) – so its efficiency doesn’t depend on the size of the grid. This is a rough stab at some code – uncompiled and untested so you might have to modify it to get it to work:

    public class SquareGrid
    {
        /** Lower, left corner of the grid */
        private Point2D m_origin;
        private double  m_cellSize;
        private List<List<List<Point2D>>> m_cells;
    
        public SquareGrid(Point2D origin, int numberOfCellsPerSide, double cellSize)
        {
            m_origin = origin;
            m_cellSize = cellSize;
            m_cells = new ArrayList<List<List<Point2D>>>(numberOfCellsPerSide);
    
            for (int i = 0; i < numberOfCellsPerSide; i++)
            {
                List<List<Point2D>> row = new ArrayList<List<Point2D>>(numberOfCellsPerSide);
                m_cells.add(row);
    
                for (int j = 0; j < numberOfCellsPerSide; j++)
                {
                    row.add(new ArrayList<Point2D>>());
                }
            }
        }
    
        public void add(Point2D point)
        {
            int xCell = Math.floor((point.getX() - m_origin.getX()) / m_cellSize);
            int yCell = Math.floor((point.getY() - m_origin.getY()) / m_cellSize);
    
            m_cells.get(xCell).get(yCell).add(point);
        }
    }
    

    If you want the origin in the middle of the grid you will need to adjust the add algorithm, and decide how you want to deal with odd numbers of cells per side.

    The professionals would probably use an R-Tree or some other data structure that can be used to build an efficient spatial index instead of a grid.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I am currently running into a problem where an element is coming back from
I am writing an app with both english and french support. The app requests

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.