Rotating a sphere in Three.js around a designated point while maintaining a fixed tilted axis

My approach to simulating the sphere rotating around a point and its own axis simultaneously involved creating a pivot, an Object3D, and adding the sphere as its child. They were both supposed to rotate around their respective axes based on an idea I found on the web.

However, this method proved flawed when considering that the sphere represents the Earth, which has a fixed axial tilt. The axial tilt ended up changing based on the rotation around the pivot.

To illustrate the issue, I created some visual drawings:

INCORRECT:

https://i.sstatic.net/CBfVX.png

CORRECT:

https://i.sstatic.net/ECemL.png

The code snippet used is as follows:

index.php

<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
        <title></title>
        <?php include_once ('php/includes.php'); ?>
    </head>
    <body>
        <section id="container"></section>
        <script>
        $(document).ready(function () {
            new Space();
        });
        </script>
    </body>
</html>

includes.php

<script type="text/javascript" src="js/libs/jquery/jquery.js" ></script>

<script type="text/javascript" src="js/libs/three/three.js" ></script>
<script type="text/javascript" src="js/libs/orbitcontrols/orbitcontrols.js" ></script>

<script type="text/javascript" src="js/shape/Sphere.js" ></script>
<script type="text/javascript" src="js/shape/Plane.js" ></script>
<script type="text/javascript" src="js/Space.js" ></script>

Space.js

var Space = function() {
    this.init();
    this.animate();

    Space.instance = this;
};

Space.instance;

Space.prototype.getInstance = function() {
    return Space.instance;
};

Space.prototype.init = function() {
    // Code implementation details here
};

Space.prototype.resize = function() {
    // Code resize logic here
};

Space.prototype.animate = function() {
    // Animation logic goes here
};

If you're facing this problem, how can it be resolved?

Answer №1

To enhance your scene, consider incorporating a sphere (such as an earth) with a tilted axis into a THREE.Group() object named earth_container. Then, adjust the container's orientation by applying a directional vector to its position. Here is an example:

earth_container.position.x = -Math.cos(time) * 10;
earth_container.position.z = -Math.sin(time) * 10;
lookAtPos = earth_container.position.clone().add(new THREE.Vector3(0,0,1));
earth_container.lookAt(lookAtPos);

Check out this jsfiddle for a visual demonstration.

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

Split the *.GLB file into smaller portions using @react-three/fiber

Incorporating a 3D scene with React using @react-three/fiber is my current project goal. I want the user to interact with a 3D car model by selecting specific "car parts" like the hood or front door right with just a click. So far, I've successfully ...

The significance of using the Spread operator in React-Redux Reducers

Exploring the essence of the spread operator has been quite intriguing. Based on my interpretation of the documentation, it seems that the spread syntax essentially duplicates the existing object and then gets replaced by a new object when one is introduce ...

Two entities positioned on opposite extremes

Is there a way to design a div with two elements (text and image) positioned on opposite sides? The length of the text varies as it's a list of months for selection. Ideally, the text should appear on the left side of the div as a "p" element, while t ...

Trigger a popup alert when a Bootstrap select live search is clicked

<select class="selectpicker form-control" data-live-search="true" name = "name1" id ="id1"> <option>Option1</option> <option>Option1</option> <option>Option1</option> <option>Option1</option> ...

efficiency of a process during ng-repeat execution

Do you see a distinction in how ng-repeat is written in these two examples? <div ng-repeat="item in getItems()"> Versus this: <div ng-repeat="item in items"> Imagine getItems is structured like this: $scope.getItems = function() { return ...

What is the reason behind TypeScript's lack of support for exporting with decorators?

The issue regarding this problem was addressed on https://github.com/tc39/proposal-decorators/issues/69. Despite this discussion, TypeScript does not currently support it. The following code demonstrates the lack of support: export @deco() class a {}; H ...

How to include an array of data in an $http request using AngularJS

I am trying to store data in an array to the $http service in AngularJS. The way I am currently adding them to the service is as follows (and it is functioning correctly): var inputValueArray = new Array($scope.formdata); Currently, I am able to retriev ...

Display a distinct button on the webpage if the logged-in user has not clicked on it yet

Seeking a solution to emphasize buttons that the User has not visited in the event of changes to the content of the views that appear when these buttons are clicked. The answer must utilize the ASP.net MVC CSS framework. <head> <style type="text/ ...

Script execution is disabled on this system preventing the loading of content - ANGULAR V14

Every time I try to run my Angular project or any ng command, I keep encountering the following error message: ng : File C:\Users\achra\AppData\Roaming\npm\ng.ps1 cannot be loaded because running scripts is disabled on this ...

What is the correct procedure for utilizing variables in the parseJson function when working with string objects?

While working with the parseJson function, I have encountered a challenge where I need to incorporate a variable within three objects. Is there a way to merge a variable with the value of one object? Alternatively, can I utilize a third object to store t ...

Breaking Down URLs with JavaScript

I am looking to extract specific portions of a URL and here is my progress so far. <script type='text/javascript'> var query = window.location.pathname.split( '/' ); query = window.location.pathname.split( '.html' ); v ...

Sending a message to a specific client using socket.io

Currently delving into socket.io + node.js, I have mastered sending messages locally and broadcasting using the socket.broadcast.emit() function - where all connected clients receive the message. My next challenge is figuring out how to send a private mes ...

Using array.map() in JavaScript returns an array instead of an object

JavaScript is still new to me and I'm struggling with mapping an array. I'm not sure how to return an array with objects. Here is the original array: array1 = [{firstName: "Harry"}, {lastName: "Potter"}]; After using array1.map, it c ...

The legends on the Google chart are having trouble being displayed accurately

Take a look at the screenshot below to pinpoint the sample issue. While loading the graph UI with Google Charts, the legends data is showing up but not appearing correctly. This problem seems to occur more frequently on desktops than on laptops. Any advi ...

What kind of Shader is used by Three.JS for models imported through ColladaLoader?

Can anyone help me figure out the specific shader type used on materials of models imported with the Collada Loader? The end result looks incredibly superior compared to any material/shader combinations I have experimented with! ...

Displaying the index number for each vertex in a .obj file using Three.js

Is there a convenient method in THREE.js for displaying the vertex numbers of a mesh imported from an obj file? [Sample obj file] I'm currently working on setting up bones inside a mesh and need to position them between specific vertices, but I don&a ...

Can a props be retrieved and passed as an argument to a function?

My goal is to retrieve a prop from MapsStateToProps using react-redux's connect and then pass it to a child component. This prop serves as an argument for a function, which in turn returns something that becomes the state of the child component. Alth ...

Export your entire schedule to Excel and PDF formats for easy organization and sharing

I currently have a jQuery full calendar implemented and I am looking to find a way to export the calendar's HTML content to Excel and .pdf formats. The code snippet below shows my attempt at exporting to Excel: HTML: <div id='calendar'& ...

Adding an image within the body of text in a Django model, where both the text and image coexist

I am currently seeking a method to seamlessly insert an image within the text of my Django-powered blog. My goal is to achieve a layout similar to the one showcased in this example: https://i.stack.imgur.com/cFKgG.png The desired layout consists of two c ...

Calculating the number of days between two given dates, including both the start and end dates

I need to calculate the number of days between two dates, including both of the dates. My current method for this task is as follows: numDaysBetweenDates(startDate, endDate) { let millisecondsPerDay = 24 * 60 * 60 * 1000; return (endDate - startDate) ...