Determining the precise coordinates of each sphere to construct a larger sphere comprised entirely of interconnected spheres

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)

  1. I summed up the lengths of all protons and neutrons to iterate through them.
  2. 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.
  3. Each iteration incremented the variable l. When i reached the value of loopcount, indicating the completion of one spherical layer, I multiplied loopcount by 3 to determine the number of spheres needed for the subsequent round. Setting l 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.

Answer №1

Utilizing a physics engine in this scenario seems like the ideal choice. Creating such a simulation without the aid of a physics engine could be quite cumbersome, making the inclusion of one a minor trade-off considering the benefits it provides. Most JavaScript physics engines I've come across are lightweight and efficient. However, it's important to note that running physics calculations may require additional CPU power!

To experiment with a similar setup as described, I tested out a physics engine called CANNON.js. While setting up a basic simulation was relatively straightforward, fine-tuning the parameters proved to be a bit challenging and required some adjustment.

If you encountered difficulties in getting particles to gravitate towards a specific point, using CANNON.js (and likely other physics engines) allows for achieving this by applying a force in the opposite direction of the object's position:

function pullOrigin(body){
    body.force.set(
        -body.position.x,
        -body.position.y,
        -body.position.z
    );
}

Additionally, creating behaviors where objects are attracted to a parent object, which in turn is drawn towards the average position of other parent objects, enables the formation of entire molecules.

A complex aspect involved ensuring electrons orbit protons and neutrons at a distance. To achieve this, I applied a subtle force pulling them towards the center and then slightly away from all protons and neutrons simultaneously. Additionally, giving them a slight initial push sideways kick-started their circulation around the center.

Feel free to reach out if you need further clarification on any particular segment.

// Your script goes here...
<script src="https://cdnjs.cloudflare.com/ajax/libs/cannon.js/0.6.2/cannon.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r75/three.min.js"></script>

EDIT

I have structured the particles into an Atom object for organizational purposes, offering more details within the code for clarity. I recommend thoroughly examining the code and referencing the CANNON.js documentation for comprehensive information. The mechanics related to force can be found in the Body class of Cannon.js. By combining a THREE.Mesh and a CANNON.Body for each particle, movements were simulated on CANNON.Body before syncing positions and rotations with THREE.Mesh prior to rendering.

The Atom function below encompasses modified electron physics:

// Atom function implementation...

To utilize the provided code:

// Your usage instructions go here...

Answer №2

Dealing with a similar issue, I devised a solution using Cannon.js as well. However, as the complexity of elements increased, it led to significant load times, especially on mobile devices.

To mitigate this issue, I proposed capturing the final position of nucleons post-settlement and storing them in a json file for all elements.

This approach allows the nucleons to orbit the nucleus in a linear fashion without relying on physics simulations.

Answer №3

To accurately determine the location of Neutrons and Protons, one effective approach is to utilize the icosphere algorithm in order to derive their positions based on the vertex point of a generated sphere.

If you are interested, you can access a helpful algorithm by visiting this link.

An interesting aspect of this method is that the distance between these points remains consistently equal across the entire surface.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Transferring previously obtained data to templateProvider within AngularJS

I'm currently working with AngularJS 1.3 and UI-Router. I have a state set up with a resolve and a templateProvider. My goal is to utilize the data fetched from the database in the resolve within the templateProvider without having to make duplicate ...

Error: The database has encountered a duplication error in the followers index of the MERNSM.users collection, with a duplicate key value of undefined

Encountered a MongoServerError: E11000 duplicate key error collection: MERNSM.users index: followers_1 dup key: { followers: undefined }. This is puzzling as there is no unique constraint set in my schema. I am unsure of what could be causing this issue, e ...

Store the running of a JavaScript file in memory

It seems highly unlikely that achieving the following is possible without expert confirmation: On page number 1, user and application data is requested as soon as the page loads. Page number 2 utilizes the same script, so requesting the same information w ...

Tips for utilizing the date-formatter feature of bootstrap-table with Angular 2

Hello there! I have integrated the bootstrap-table library with Angular4, but I am facing an issue with the date-formatter feature. Here is the HTML code snippet: <table id="table" data-show-refresh="true" data-show-toggle="true" data-show-columns="tr ...

What is the best way to reset an event back to its original state once it has been clicked on again

As a newcomer to web development, I'm currently working on creating my own portfolio website. One of the features I am trying to implement is triangle bullet points that can change direction when clicked - kind of like an arrow. My idea is for them to ...

What could be causing localstorage to malfunction in Firefox 57 and Vuejs2?

I am looking to implement language change functionality in my application by clicking on the language name. I am currently using vuex-i18n to manage the language settings in the frontend. However, I have encountered an issue with localStorage not functioni ...

Checking CORS permissions with a pre-flight OPTIONS request

During development, I implement a middleware called cors using the following syntax: app.use(cors({origin: 'http://localhost:8100'})); However, I have noticed that for every route request, two requests are being made as shown in the image below ...

Managing large datasets effectively in NestJS using fast-csv

Currently leveraging NestJS v9, fast-csv v4, and BigQuery for my project. Controller (CSV Upload): @Post('upload') @ApiOperation({ description: 'Upload CSV File' }) @ApiConsumes('multipart/form-data') ... // Code shorten ...

Utilize Magnific Popup to target the parent iframe

I am working on a web page that contains several small iframes. I am trying to implement a feature where when a user clicks on a button inside one of the iframes, a large form with type: inline should open up in the parent page instead of within the ifra ...

Iterate over each item in the select and include a blank option if either of the elements is missing

Having trouble with 2 drop down menus, select1 and select2. I select item1 from select1 and then click the OK button. But when the selected index is 0 (first option), I want to loop through the items of both drop downs. If the elements at the same index ( ...

The color of the progress bar in JS is not displaying properly

My work involves using jQuery to manipulate progress bars. The issue I am facing is defining standard colors that should be displayed on the progress bar based on the value received. Here is my code: var defaultSegmentColors = ['#FF6363', &ap ...

The jQuery dynamic fields vanish mysteriously after being validated

I am facing an issue with my jQuery and validation. Below is the code snippet causing the problem: var fielddd = 1; $(document).on('click', '.btn.add-field', function() { fielddd++; $('#newfield').append('< ...

Performing complex joins in MongoDB using multiple sub documents

I am managing two unique collections, Users collection: { "userId": 1, "name": 'Alice', "profile": 'alice.png' }, { "userId": 5, "name": 'Bob', "profile": 'bob.png' }, { "userId": 10, ...

What is the best way to set up secure client routes?

Welcome to my College Dashboard Project! :) I am currently utilizing Next.js to create a comprehensive dashboard system for Teachers, Students, and Administrators. The Home page serves as the central hub for logging in or signing up as any of the mention ...

Step-by-step guide on transferring an HTML5 sqlite result set to a server using AJAX

Imagine I have a scenario where I receive a result set as shown below: db.transaction( function(transaction) { transaction.executeSql( 'SELECT col1, col2, col3 FROM table;', [],function(transaction, result){ //need to find a ...

Android phone experiencing issues with custom search engine functionality

Google custom search is functioning correctly in the browser as well as in the emulator within Phonegap. However, on an Android phone, it encounters a network error or displays a blank screen. Sometimes, the error message "file:///google.com/cse?q=.... can ...

Updating Firebase without altering the syntax can be achieved by following specific steps to

I'm feeling a bit lost on how to tackle this, as the project I've been handling is currently using firebase 7.14.0. Being a new developer, I've been struggling with this version due to the lack of documentation available. Is there a way for ...

Utilizing the synchronous approach to access the Facebook Messenger API

My current project involves creating a basic chatbot using the Facebook Messenger API. I am encountering an issue where the messages I send are not always displayed in the correct order. How can I utilize async/await functionality to ensure that the messag ...

Steps for removing an item from an array in MongoDB

Is it possible to remove an object from the mainList array? _id:ObjectId("5fafc5aec2b84c301845c55a"), username:"test", mainList:[ { _id:ObjectId("5fafdf1a5b49510c789af0ae"), n ...

Utilize vue.js input field to search for a specific username within a constantly updating list of users

I have created an input search functionality to filter a list of users using PHP. Now, I am attempting to implement the same filtering feature in Vue.js so that when a user searches for a name, the filtered user will be displayed in the list. Below is the ...