I am currently working on recreating an atom using THREE.js and I have encountered my first hurdle. Each type of atom contains varying numbers of Protons and Neutrons, so I am trying to figure out a way to automatically position them without colliding with each other. The goal is to arrange them in such a way that they collectively form a shape as close to a sphere as possible. You can refer to this image for a visual representation:
https://i.sstatic.net/XuxzN.jpg
(source: alternativephysics.org)
.
Is there a method to calculate this and assign positions to each Neutron/Proton using a formula? Or would it be necessary to involve a physics engine to handle the task of positioning the spheres together to achieve the desired result?
At this stage, I do not have any code written since I am primarily focused on determining how to approach this issue.
UPDATE
I want to clarify that my intention is to pack the spheres closely inside the larger sphere's space instead of distributing them along its radius.
UPDATE 2
While exploring the option of using a physics engine to compress the spheres within a confined area, I faced challenges finding one that allows me to apply gravitational forces to move all objects to a specific position (0,0,0). Most engines seem to only exert gravity downwards on individual objects. I prefer a solution based on a formula for sphere positioning rather than integrating an entire physics engine into my project.
UPDATE 3, 04/06/06
Despite some experimentation, I have yet to achieve the desired outcome. Here is the current state:
https://i.sstatic.net/AaT4n.jpg
As seen, the arrangement appears far from ideal. This occurred when attempting to create a Uranium atom, which involves more protons/neutrons/electrons compared to Carbon.
https://i.sstatic.net/jk5gE.jpg
To me, it seems more like an intricate ratatouille dish rather than resembling a Uranium atom.
My approach so far:
(particleObject
acts as the parent of particles, enabling relative movement)
- I summed up the lengths of all protons and neutrons to iterate through them.
- If the
sum % 2 == 0
, (which holds true for testing), I set rotation to(PI * 2) / 2
. The last two digits symbolize the preceding two units. - Each iteration incremented the variable
l
. Wheni
reached the value ofloopcount
, indicating the completion of one spherical layer, I multipliedloopcount
by 3 to determine the number of spheres needed for the subsequent round. Settingl
to 0 reset the sphere positions, advancing the loop to place the next row of spheres one unit on the x-axis.
(Pardon the technical jargon; it's challenging to elucidate. Refer to the code for clarity.)
var PNamount = atomTypes[type].protons + atomTypes[type].neutrons;
var loopcount = 1;
if(PNamount % 2 == 0) {
var rotate = (PI * 2) / 2;
loopcount = 2;
}
var neutrons = 0,
protons = 0,
loop = 1,
l = 0;
for(var i = 0; i < PNamount; i++) {
if(i == loopcount){
loopcount = loopcount * 3;
loop++;
rotate = (PI * 2) / loopcount;
l = 0;
} else {
l++;
}
particleObject.rotation.x = rotate * l;
particleObject.rotation.y = rotate * l;
particleObject.rotation.z = rotate * l;
particle.position.x = loop;
}
Admittedly, I struggle with 3D mathematics. Any assistance or guidance will be greatly appreciated. It is feasible that my method for positioning the spheres may be flawed at every level. Thank you!
You can view the live code here.