Generating magnetic field lines for a spherical object (e.g. earth) using three.js

I am currently experimenting with physics simulations in three.js and I am looking to create magnetic field lines around a sphere. While researching, I came across bezier curves but I am unsure how to incorporate them into my project. What I am aiming for is similar to the following examples:

Examples of what I want

Although the examples are in 2D, I am interested in creating a 3D version of the same concept.

Answer №1

If you possess the necessary mathematical knowledge to calculate points, you have the ability to utilize a spline in order to visually represent magnetic lines. Here is an example of how this can be achieved:

// Utilize your mathematical calculations to create an array of THREE.Vector3 points
var points = [ v1, v2, v3, v4, and so on ];

var curve = new THREE.SplineCurve3( points );
var geometry = new THREE.Geometry();

// Adjust the segment count to influence the smoothness of the line.
geometry.vertices = curve.getPoints( 50 );

var material = new THREE.LineBasicMaterial( { color : 0xff0000 } );

// Construct the final Object3d to incorporate into the scene
var splineObject = new THREE.Line( geometry, material );

This information is sourced directly from the documentation and can be accessed here


You may also find MathBox intriguing, as mentioned in this answer here.

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

Utilize the power of AJAX for efficiently sorting search results retrieved from MySQL

I'm in the process of designing a flight search page. The initial page contains a form, and when the submit button is clicked, the search results are displayed on the second page. Here's the link to the first page: To test it out, please follow ...

Ways to solely cache spa.html using networkfirst or ways to set up offline mode with server-side rendering (SSR)

I am facing an issue with my application that has server-side rendering. It seems like the page always displays correctly when there is an internet connection. However, I am unsure how to make Workbox serve spa.html only when there is no network available. ...

Getting to the values within a JSON object that contains multiple arrays

Is there a way to retrieve array data from the json object data? const [data, setData] = useState([]) const getData = () => { axiosInstance .get(url + slug) .then(result => setData(result.data)) } useEffect(() = ...

I am encountering a problem with IE11 where I am unable to enter any text into my

When using Firefox, I can input text in the fields without any issues in the following code. However, this is not the case when using IE11. <li class="gridster-form" aria-labeledby="Gridster Layout Form" alt="Tile Display Input column Input Row ...

Exploring the process of setting up a datasource for Select2 in October CMS using the integrated Ajax Framework

Looking to utilize the extensive AJAX framework provided by October CMS to populate a Select2 box with data. The process of using a remote dataset in Select2 involves the following steps: $(".js-data-example-ajax").select2({ ajax: { url: "https://a ...

Counting the number of times a form is submitted using a submit button and storing the data

After researching for a few hours, I've gathered information on different techniques for storing data related to a submit button counter in a text file. <form action="/enquiry.php" method="post" name="form"> <label>Name *</label> &l ...

Find the variance between the sums of columns 3 and 5 using Angular

Is there a method to calculate the variance between column 3 and the last one in a table? <body ng-app="Test"> <section style="margin-top:80px"> <h3>Plastic Calculator Form Version 2.0</h3> <div ng-controller="TestCo ...

Is there a way to set the content to be hidden by default in Jquery?

Can anyone advise on how to modify the provided code snippet, sourced from (http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_hide_show), so that the element remains hidden by default? <!DOCTYPE html> <html> <head> <scrip ...

Invoke a JavaScript file within the MongoDB shell

Running a JS file directly from the Mongo shell using the query mongo localhost:27017/west createSumCollection.js has resulted in an error: "uncaught exception: SyntaxError: unexpected token: identifier : @(shell):1:6" The content of CreateSu ...

Incompatibility between Angular JS and IE 8 leads to view not rendering

When using Internet Explorer 8, I'm encountering compatibility issues with Angular.js in my contact form. Despite trying emulation mode in IE 11, the view isn't rendering properly, and the console isn't showing any errors. Could there be som ...

Ember's structured format featuring objects as rows and column names as properties

I am currently working on developing a modular tabular form that requires an input of two arrays: one containing objects (representing the rows) and another containing property names of those objects (representing the columns). The goal is to be able to mo ...

What is the maximum number of JavaScript functions allowed in a single HTML file?

My HTML5 file includes JavaScript (created from CoffeeScript) directly within the HTML file, as I prefer this approach for my HTML/JavaScript programming. The code consists of four JavaScript functions that convert one temperature unit to another. Strang ...

Attempting to configure a webhook eventsub through the Twitch API by utilizing ngrok as the intermediary

After triggering a test event using the Twitch CLI, an error response was received indicating: Post "https://1562-5-182-32-19.ngrok.io/api/twitch/eventsub/": context deadline exceeded (Client.Timeout exceeded while awaiting headers). The notification even ...

Using a button to dynamically fill a container with data, and then incorporating that data into a function triggered by a click event - JavaScript

Currently, I have a text box where I can enter a letter and click a button to run a JavaScript function. Here is the existing code: <div id="enterlettertext"> Enter the letter:&nbsp; <input type="text" id="myletter ...

The addScript feature seems to be experiencing difficulties upon the initial website load

Currently, I am utilizing the jquery.flexslider plugin and it is performing well. However, I have a specific requirement where I do not want to load the plugin for screens that are smaller than 600px. After experimenting with various scripts, I have final ...

Variable in Javascript file causing return value to be 'undefined'

I have encountered an issue with my JavaScript file. It is extracting data from a SharePoint list and displaying it on an HTML page, but one of the fields appears as 'undefined' even though I defined it initially. The problematic variable is &ap ...

Creating randomized sample information within a defined timeframe using JavaScript

I'm looking to create mock data following a specific structure. Criteria: The time interval for start and end times should be either 30 minutes or 1 hour. Need to generate 2-3 mock entries for the same day with varying time intervals. [{ Id: ...

What is the best way to eliminate all text that appears after the final appearance of a character in JavaScript?

Suppose we have a specific string that looks like this: "A - B - C asdas K - A,B,C" Assume the character delimiter is "-" The goal is to extract everything before the last occurrence of "-", which in this case would be &quo ...

Concealing table row information when checkbox is marked

I'm currently facing a challenge with toggling the visibility of content on my website. The content consists of servers that are either online or offline. Due to the long list, I want to hide all servers marked as "LIVE" while keeping the ones labeled ...

Enhance the interoperability of Babel with Express.js by steering clear of relative

My current approach to imports is as follows: import router from '../../app/routes' Is there a way to avoid using ../../, for example: import router from 'app/routes'? In typescript, I can achieve this with the following configuratio ...