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 6377337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:51:29+00:00 2026-05-25T01:51:29+00:00

I have a three dimensional array which I want to fill in with values

  • 0

I have a three dimensional array which I want to fill in with values in C#. By looping one dimension at a time it will start at one corner, and work in rows until it finishes at the opposite corner.

Standard loop:

for (int x = 0; x < 10; x++)
   for (int y = 0; y < 10; y++)
      for (int z = 0; z < 10; z++)
         {
            // fill value
         }

I want to loop the same values, but start at the center of the array, and slowly work my way outward, so that if I look at the array in 3D space as it’s being filled, it will slowly grow as a ball (or cube) from the middle.

Any good ideas on how I can do this? Ideas for both filling a cube form, and filling as a sphere (ie. closest distance to middle) would be great!

  • 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-25T01:51:29+00:00Added an answer on May 25, 2026 at 1:51 am

    You may use something like BFS
    C-style pseudocode, not C#:

    class Point{int x,y,z;};
    
    queue<Point> q;
    bool used[100][100][100]; //all false. true when add point to queue
    Point vectors[]={(0,0,1),(0,0,-1),(0,1,0),(0,-1,0),(1,0,0),(-1,0,0)}
    q.push(Point(50,50,50)); //start point
    used[50][50][50]=true;
    while(!q.empty()){
         Point cur=q.front();
         //use cur;
         q.pop();
         for(i=0;i<6;++i){
             if(!used[cur+vectors[i]] && (cur+vectors[i] is in our diapason)){
                 q.push(cur+vectors[i]);
                 used[cur+vectors[i]]=true;
             }
         }
    }
    

    It will fill area by Manhettan distance. So it will cube, but corner to top and bottom

    Also you may use this naive solution(pseudocode too):

    Point points[];
    for (int x = 0; x < 10; x++)
        for (int y = 0; y < 10; y++)
            for (int z = 0; z < 10; z++)
                {
                     add to point array
                }
    
    sort points[] by function r() (if r(a)<r(b) then a before b)
    
    loop points here
    
    r(a)=sqrt((a.x-5)^2+(a.y-5)^2+(a.z-5)^2) for ball
    r(a)=max(abs(a.x-5),abs(a.y-5),abs(a.z)-5) for cube
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multi-dimensional array, which basically consists of one sub-array for each year.
I have a 2-dimensional array of objects (predominantly, but not exclusively strings) that I
I have a function that has to accept an array of points, or an
Hey guys this is a followup to my previous question . I now have
I have two arrays for a chess variant I am coding in java...I have
So ... I have an image loaded into an NSBitmapImageRep object, so I am
This question is likely to be somewhat longer than SO's average questions, so I'll
This is probably a simple question for you php whizzes out there but I
This is actually a problem that I've already solved, but I suspect that there
I'm trying to write a little CLI Hangman game, just to create something in

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.