Utilizing orbital mechanics for a celestial system visualization in Three.js with coordinates (x,y,z) for planetary bodies

Currently, I am developing a Solar System visualization in Three.js. While my planets currently have basic circular orbits, my goal is to create a realistic model. Despite researching information on wiki and other articles, the content is quite advanced for me.

I am not concerned with tracking the orbits over thousands or millions of years. Instead, I aim to achieve a model that closely resembles reality, showcasing:

  1. Accurate elliptical orbits
  2. Inclination
  3. Dynamically changing speed (faster at perihelion)

I am curious if there is a sufficiently complex method to calculate x,y,z coordinates for my planets at any given time t, with this time dynamically changing, possibly utilizing orbital elements.

I hope I have effectively communicated my concept. Thank you.

Answer №1

Consider exploring a two-dimensional projection of the orbital paths. By doing so, you can simplify by parameterizing the ellipse as a vector function denoted as ɣ(x(t), y(t)).

For a more physical approach, envision two centers of mass: the sun M and a specific planet μ. The force acting on the planet F can be calculated using F=GμM/|ɣ|², leading to acceleration determined by Newton's second law, a=GM/|ɣ|², always directed towards the larger mass, M.

To define the curve ɣ accurately, reference equations provided at http://en.wikipedia.org/wiki/Ellipse#Equations

Answer №2

If you are satisfied with a rough estimate to highlight key components, consider creating a lookup table for all planets over several years. For example, calculating the orbital period of Neptune which is 164 years can allow you to determine the positions of each planet every month within that timeframe to compile a manageable table size. To visualize the changes in orbital speed more accurately, finer resolution is necessary. Once the calculations are complete, constructing an animation to showcase the planetary positions is the next step.

The computations involved in this process are complex and detailed. Rather than going through each calculation here due to its length, you can find a comprehensive explanation here, along with a sample program coded in QBasic.

The fundamental steps include:

1. Determining the position of the planet in its orbit 2. Calculating the number of days since the elements' date 3. Finding the mean anomaly based on the Mean Longitude and daily motion 4. Obtaining the true anomaly using the Equation of Centre 5. Establishing the radius vector of the planet

After referencing this position to the Ecliptic, ascertain the heliocentric ecliptic coordinates of the planet.

Once you have the heliocentric coordinates, convert them to your specific frame of reference. The provided page demonstrates this transformation for geocentric coordinates, but you will need to adapt it accordingly for your needs. Incorporate these transformed coordinates into your table.

You may opt to run the calculations in real-time, offering more flexibility but potentially impacting the frame rate. It might be beneficial to conduct some trial and error experiments in this regard.

A special thanks to Keith Burnett (the author of the linked page) for providing the detailed information summarized above.

Answer №3

Check out this C++ code snippet for accomplishing a specific task. Although it doesn't involve taking a date as a parameter, you can achieve the desired outcome by replacing the i value appropriately. I personally used this code to illustrate the orbital path around the sun.

double x = distanceFromSun * orbitScaleFactor;
double y = sin(inclination) * distanceFromSun * orbitScaleFactor;
double z = semiMinorAxis * orbitScaleFactor;

for (double i = 0; i < 2.0 * PI; i += PI / 32.0) {
    x = cos(i) * x;
    y = cos(i + lonOfAscendingNode) * y;
    z = sin(i) * z;
}

P.S. Despite your query being related to JavaScript, I didn't hesitate to provide C++ code as I believe the formula is what truly matters in this case.

You can view the complete code on my GitHub repository: https://github.com/SyntaxRules/SolarSystemSimulation/blob/master/src/Planet.cpp

All variable information can also be found there. Enjoy! :)

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

Instructions on extracting a random element from an array and continue removing elements from the array until it is completely empty

I am attempting to utilize either jquery or javascript to remove a random item from an array until it is empty. Each time I remove an item, I want to log it to the console. My goal is to create elements with random images from the specified array until all ...

Tips for keeping your button fixed in place

I am encountering an issue where my button moves below the select dropdown list when I try to make a selection. Is there a way to keep the button in place even when the dropdown list from the select box is visible? For reference, here is the current outp ...

How can the Angular.js Service Factory module be configured to yield the inner code as a function?

I am completely new to working with angular.js. Recently, I wrote my first Service which takes a JSON object and updates the scope of the controller. However, I find myself a bit confused about some aspects of it. Specifically, I am unsure if I should wrap ...

Create an array populated with unclosed HTML tags that need to be rendered

I'm trying to display a simple list, but it seems like React is having trouble rendering unclosed HTML elements that are pushed onto the list. This results in an error: ReferenceError: el is not defined If I use single quotes (') bookingStat ...

Creating a new dynamic page can be achieved by clicking on a dynamically generated link. Would you like to learn how to do that?

Recently, I developed a custom API using Node.js to retrieve information about blogs from Medium.com. The API currently provides: The author/main picture of the article Title A link to the article on medium.com (redundant) The entire article text in the ...

Enhance precision with autofocus feature while utilizing Quasar's Q-Field validation

Currently, I am in the process of setting up a form using Quasar and implementing internal validation. The specific issue I am facing involves a group of checkboxes where the user must select at least one option. While I have successfully implemented the v ...

Is there a method available to identify browser compatibility problems within my JavaScript code?

Currently, I am working on a Javascript library and I am looking for a tool that can help me with the following: Detect any methods in my code that may be incompatible with certain browsers Show me which browsers are compatible with my code I have been s ...

Update the VueJS application by loading and replacing the existing JSON data with new information

Is there a way to dynamically re-render the entire v-for loop and DOM after fetching and loading new JSON data to replace the current one? I want to be able to click on different options and have the products updated. Vue.use(VueResource); var produ ...

Creating internal utility functions in Angular without exporting them as part of the module can be achieved by following a

Currently, I'm in the process of creating an angular module called MyModule. This module includes several sub-modules. angular.module('MyModule', [ 'MyModule.SubModule1', 'MyModule.SubModule2', 'MyModule.SubMo ...

Exploring History Navigation with AngularJS: Leveraging $routeParams and $location

I have been diligently working on developing a question bank and have successfully coded most of the elements. However, I would like to enhance the user experience by implementing browser history for easy navigation through the questions. If you want to c ...

What is the best approach for writing an asynchronous function while utilizing $rootScope.broadcast within a continuous loop?

At least 10 times a second, I have a function that is called. Each time, there are approximately 100 records with variations in LastSeenTime and ReadCount. In this simulation scenario, I understand the behavior; however, in real-time, the number of records ...

Cursor-hugging tooltip

My tooltip creation works when hovering over an icon, but there's a slight issue - it doesn't always follow the cursor and can get stuck at times. To see a demo of this in action, click here: fiddle Here's the code I'm using: HTML & ...

Leveraging ajax and jQuery for the implementation of PHP functionalities

UPDATE: Issue resolved. It turned out to be a simple mistake. The PHP file required one of those "?field=value" parameters in the URL, and that's what needed to be included in the data section. I needed to pass the input field value to the PHP file be ...

Navigating with nodeJS

Currently, I am in the process of learning how to create a Node.js project. My latest endeavor involved following a tutorial to develop a chat application. However, it seems like there is an issue with the routing between the server side and client side. ...

Tips on viewing class object values within the `useEffect` hook

App.js import React, { useRef, useEffect } from "react"; import Token from "./Token"; export default function App() { const tokenRef = useRef(new Token()); useEffect(() => { console.log("current index of token: ", ...

Fresh Regular Expression created from a readable string

I can't figure out why rg = new RegExp(`/${a}.*${b}/`) isn't functioning properly here, while rg = /\(.*\)/ is working fine. let a = '\('; let b = '\)'; let rg; //rg = new RegExp(`/${a}.*${b}/`); // doesn&a ...

What could be causing the lack of updates to my component in this todo list?

Based on my understanding, invoking an action in MobX should trigger a rerender for the observer. However, when I call the handleSubmit method in my AddTask component, it doesn't cause the TaskList observer to rerender. Should I also wrap AddTask in a ...

Should we designate the array index as the unique identifier for React components?

I have an array filled with different strings that I need to map through and display in a React component. React raises concerns when encountering identical strings within the array. My query is this: Can I assign the position of each element in the array ...

dc.js bar graph bars blending together

This datetime barChart is causing me some trouble. Interestingly, when I try to replicate the issue in a fiddle (check here), everything functions as expected. Please note that the data takes about 30 seconds to load from github. Below is the code for the ...

Can you explain the distinction between the controls and get methods used with the FormGroup object?

I have encountered an interesting issue with 2 lines of code that essentially achieve the same outcome: this.data.affiliateLinkUrl = this.bookLinkForm.controls['affiliateLinkUrl'].value; this.data.affiliateLinkUrl = this.bookLinkForm.get(' ...