Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / I Can't figure out this Nested Loop

Author
Message
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 5th Jul 2012 18:48 Edited at: 5th Jul 2012 18:58
I've been trying to figure out how to automate this nested loop for months...



The first 6 balls of particles are 0.06 from centre, with 6 more balls 0.03 from centre. This creates 12 balls around a single 13th ball at the centre. Then I instance this object as a bunch of limbs.

Now I need to make the same shape again but from this instanced object, and because it is bigger the distances change to 0.09, and 0.06. This then just repeats but moving the origin over, and to the side 0.09, and 0.06, -0.09, and -0.06. To create a bigger version.

My problem has been repeating this shape infinitely in a loop determined by the user. It will be very large, at least 40,000 sphere objects.

The idea is to get a ball, where all of the sphere are a repeating pattern. So a nested loop should work. I just can't figure it out.

Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 5th Jul 2012 21:15 Edited at: 5th Jul 2012 21:23
Perhaps you could use the formula for a sphere to build your ultimate sphere of particles.

1. Build your single molecule of 12 individual spheres.
2. get the radius of this individual molecule.
3a. Plug this radius*2*shell_layer into the sphere formula and build the next shell of molecules

3b. The first shell is at 2*radius*1 from the original center
The second shell is at 2*radius*2 from the original center and so on.

4. You have to determine the increase in molecules per shell. I'm not really sure what the calculation for this value is. But this should be proportional to the angles between molecules as the radius increases from center.

The pseudo code might look like


My assumption is that you are creating a solid mass of multilayered molecules as opposed to a single shell of molecules on the outside of the sphere at some radius from the center.

Enjoy your day.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 5th Jul 2012 21:46 Edited at: 5th Jul 2012 21:48
Quote: "My assumption is that you are creating a solid mass of multilayered molecules as opposed to a single shell of molecules on the outside of the sphere at some radius from the center."


Yeah, the instanced object is 12 particles around 1, and that is the repeat pattern that I need to loop. The Radius is 1.8.... which is
3 * 0.6

chromatic3d
14
Years of Service
User Offline
Joined: 7th Oct 2011
Location: rnd
Posted: 5th Jul 2012 21:52 Edited at: 5th Jul 2012 21:53
Not sure if I know enough to help but here is how I would do it.



You could use three mods and base it off of where in the x,y,z grid the first mole of each set is located to create a blend of +/- mods.
Not sure if helping.
How do you expand in the sphere?
Do you want to vary the sphere size or distance between sets based on total number of molecules?
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 5th Jul 2012 22:20 Edited at: 5th Jul 2012 22:25
Yeah that's sort of how it works. Each positive is followed by a negative from an origin which is reset to zero. All locations must be divisible by 3. So X can be 0.06, 0.6, 1.8, 6, 9, 12, 18. Same with Y, and Z. Every particle must fall on these exact locations. It's such a perfect shape that there might be a way to do it with an array.

Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 6th Jul 2012 16:20
Got the first part to loop through which is a start.



Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 6th Jul 2012 21:29 Edited at: 6th Jul 2012 21:55
It's no good, I've tried lots of ways to make this into a ball, and now it's currently spiky...


Here's the code so far. Can anyone make this into a ball where all of the sphere are on X/Y/Z coordinates divisible by 0.03 close together, and not overlapping? It can be a ball, or 3D hexagon stacking, that doesn't matter so long as the first shape is repeated...



Latch
19
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 7th Jul 2012 23:40 Edited at: 7th Jul 2012 23:42
I tried the shell building suggestion I made using the sphere formula. It works - but it needs the proper modifiers to expand each layer the correct amount. It also showed something interesting. Here's a screeny, but it might be a bit hard to understand what you are seeing:



There are three sphere layers in this example: red at the center, green in the middle, and yellow on the outside. Each sphere is made up of individual cubes spaced at about 10 times the radius of an individual cube from the center (so I could see the layers). Each layer is the radius times the current shell number from the center so each layer should be the same distance from the previous layer.

What is interesting is, though the sphere formula works, as we approach the polar caps, the distance between particles decreases, and as we approach the equator, the distance between particles increases. Each shell layer has more particles than the previous one, which stands to reason because it's a larger surface area so that's a compensation to a degree. The problem is that a standard sphere formula won't give you the equidistant particles that you want. I don't know if there is a way to maintain the same proportions and maintain a sphere shape. Maybe instead of the standard sphere formula, you could use an icosahedron of some sort.

Enjoy your day.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 8th Jul 2012 02:28 Edited at: 8th Jul 2012 02:47
It's very important to get the exact 0.03 multiple distribution. The problem it's more of a nested loop problem. If I could figure out a few layers thick, and take the X/Y/Z distribution, then I might figure out by how much the loop is growing. It's really annoying, because after this is made, the rest of the program is a lot more exciting.

You see this second shape could be copied, and pasted with the exact same rules as the first shape. Then 13 of those would also have the same rules. But I found that Instancing instanced objects repeatedly isn't easy.


Login to post a reply

Server time is: 2026-07-08 03:48:58
Your offset time is: 2026-07-08 03:48:58