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

  • Home
  • SEARCH
  • 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 8231793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:36:51+00:00 2026-06-07T17:36:51+00:00

I am having a difficult time grasping how to iterate an octree or quad.

  • 0

I am having a difficult time grasping how to iterate an octree or quad. And it may be because I am not experienced with different mythologies of iterating. But let’s suppose that I produced a quad tree that holds float x,y,z; dword color. Now, Let’s also say that this node can only produce 4 children at a time (and those children can both produced 4 children, etc, etc) up until: 7 levels are reached (so that child can’t create anymore children, but its brothers/sisters can), all 4 children created are the same dword color (again, if that happens, its brothers/sisters can still produce), or total nodes created are equal to 87380. When the above happens, it is placed into a container. And the process continues.

Now this container that holds the nodes is (for example) 7 levels deep, all children of children of children all different x,y,zs, and colors. The problem I am having is how I iterate this container, how can I go through all the children, sisters? Since the root leads to 4 children, and those 4 children have 4 children, etc, etc, etc: 4^1+4^2….+4^7. How can I find the node I want, without writing complex if statements, and iterating over the whole node (starting from root)? Does the container (the one that produces the node) need additional code that allows this process to be simple?

Sorry if the question is to general.

  • 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-06-07T17:36:53+00:00Added an answer on June 7, 2026 at 5:36 pm

    Iterating over the whole tree is easy, you can do it recursively.

    void iterate(node *n) {
        // do something with n
        if (n->child1 != NULL) iterate(n->child1);
        if (n->child2 != NULL) iterate(n->child2);
        if (n->child3 != NULL) iterate(n->child3);
        if (n->child4 != NULL) iterate(n->child4);
    }
    

    Then call iterate(root) and the do something will happen on every node in the quadtree.

    I suspect this isn’t really what you’re asking, though. There’d be no point in keeping your data in a quadtree if that’s all you were doing. If you want to find a particular node in the quadtree, then you need something else. Let’s say you want to find a point x,y in a quadtree. Then you do something like:

    void find(node *n, float x, float y) {
        if (x == n->x && y == n->y) // you've found it!
        if (x < n->x) {
            if (y < n->y) {
                if (n->child1 != NULL) {
                    find(n->child1, x, y);
                } else {
                    // point not in quadtree
                }
            } else {
               ...same, but child2
            }
        } else {
            ...same, child3 & 4
        }
    }
    

    Note that quadtrees aren’t normally split on the points they store themselves, they are usually split by storing the splitting coordinates separately from the points (which are only stored at the leaves of the quadtree). See the wikipedia picture for an example.

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

Sidebar

Related Questions

I am new to JavaScript (but not programming) and am having a difficult time
Having a difficult time with this, trying all these different date functions but no
I am having a difficult time trying to set up Cruise (not cruise control)
I am using CakePHP and jqGrid, but am having a difficult time making them
I am having a difficult time understanding what the fork() command does under different
I know this should be simple but I am having a difficult time navigating
I am having a difficult time sorting through this PHP/MySQL issue. Let me show
I'm having a difficult time figuring out how to add a .jar/library to a
I am having a difficult time trying to find my answer on my own,
I'm having a difficult time locating an HTML parser that works with JRuby. I've

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.