How can I add a tilt to a sphere in Three.js?

I'm working on creating the moon - earth system in Three JS. For this, I want the moon sphere to have a tilt of 6.68 degrees and the earth sphere to be tilted at 23.5 degrees. Despite being new to Three JS, I couldn't find any information in the documentation regarding axis or tilt adjustments. Can someone guide me on how to achieve this?

I attempted using applyMatrix4 but haven't had success.

// Moon

const moonTexture = new THREE.TextureLoader().load('moon.jpg')
const normalTexture = new THREE.TextureLoader().load('normal.jpg')

const moon = new THREE.Mesh(
  new THREE.SphereGeometry(3,32,32),
  new THREE.MeshStandardMaterial({
    map: moonTexture,
    normalMap: normalTexture
  })
)
moon.position.x = -10
moon.position.y = 5
moon.position.z = -15
scene.add(moon)

EDIT:

It seems like the following code snippet is working:

new THREE.SphereGeometry(3,32,32).applyMatrix4( new THREE.Matrix4().makeRotationAxis( new THREE.Vector3( 1, 0, -1 ).normalize(), 6.68 ) ),

However, I am unsure about how to properly select a vector to use with the makeRotationAxis method.

Answer №1

To adjust the orientation of your "moon", a simple rotation of 6.68 degrees on the y-axis is recommended. Keep in mind that three.js operates with radians, so make sure to convert accordingly:

6.68deg => 0.12rad (approximately)

Next, implement this adjustment into your object:

moon.rotation.[axisOfRotation] = 0.12; //Radian-based rotations

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

Is there a way to dynamically create a property and assign a value to it on the fly?

When retrieving data from my API, I receive two arrays - one comprising column names and the other containing corresponding data. In order to utilize ag-grid effectively, it is necessary to map these columns to properties of a class. For instance, if ther ...

Evaluating string combinations in JavaScript using valid comparisons

After choosing values on the screen, two variables store their value. var uval = '100'; var eval = '5'; There are 2 combinations with values: let combination1= 'u:100;e:1,4,5,10' let combination2 = 'u:1000;e:120,400,500, ...

Master the art of animating ng-view transitions with AngularJS

I have 2 distinct HTML pages, namely welcome.html and login.html. These two pages are incorporated or "inserted" into a common page called index.html through the utilization of an exclusive attribute known as ngview, together with a router provider. This i ...

Searching for nested objects using dynamically generated property names

I am currently facing a challenge with accessing nested objects in MongoDb using the Node.js Driver, particularly when dealing with dynamic property names. Below is an example of my dilemma: //Although this code gives the desired results, it lacks dynamic ...

Using a straightforward approach with v-model in vue.js on an href element instead of a select

Is there a way to utilize an href-link instead of using <select> to switch languages with vue.i18n? <a @click="$i18n.locale = 'en'">EN</a> <a @click="$i18n.locale = 'da'">DA</a> ...

Tips for pinpointing parent elements within a group of various sub child elements

CSS - <div class="windows" id="window'+divCount+'"> <p id="windowName'+divCount+'"></p> <p id="para'+divCount+'">Source</p> </div> <div cla ...

Decoding mysterious Vue.js attributes ( Vue + Pug ): A comprehensive guide

Recently, while exploring some vue.js code on GitHub HERE, I stumbled upon the following snippet: menu-dropdown.task-dropdown( v-if="!isRunningYesterdailies", :right="task.type === 'reward'", ref="taskDropdown", v-b-tooltip.hover.top="$t ...

What is the best method for importing a single module within a monorepo project using JavaScript and NPM?

I've organized my codebase into a monorepo with the following structure: ➜ yw git:(master) tree . ├── package.json ├── packages │ ├── common │ │ ├── package.json │ │ ├── src │ │ │ ├─ ...

What is the best way to hand off slots to a descendant component in Vue 3?

Is it possible to have a component within a 'layout' component populate its slots? JS Fiddle <div id="app"> <layout> <page></page> </layout> </div> const app = Vue.createApp({}); ap ...

What is the best way to set a newly selected HTML option as the first choice?

I'm facing a simple problem in JavaScript that I can't seem to crack. Admittedly, I am new to working with JavaScript. My issue lies with sorting a dropdown list in alphabetical order while also keeping the selected value at the top. Whenever a ...

Is there a way to iterate over an array in Javascript, append a word to each element, and finally get back the modified array but without using the

Is there an alternative way to iterate through an array in Javascript, append a word, and then produce a new array (without utilizing map)? var addBabyPrefix = (array) => { for (var i =0; i < array.length; i++) { console.log('baby '+ ...

Problems arising from jQuery Mobile, NPM, and WebPack

After spending a considerable amount of time researching and experimenting, I am confident that I could piece something together to make it work. However, I would rather gain an understanding of the root cause of my issue. It is widely acknowledged that j ...

Dynamic styling with object notation in styled-components

It seems like the styled components documentation overlooks this scenario and I am struggling with understanding the syntax. Can you help me convert this styled component code snippet: const StyledButton = styled.button` color: red; ${props => pro ...

Select objects from an array that are contained within another array of objects

I am dealing with an array of objects that contain various attributes such as weakness, id, and type. [ { weakness: [ "Fire", "Flying", "Ice", "Psychic" ], id: 1, type: [ "grass", "poison" ] }, ...

Utilizing jQuery to send AJAX requests and display the results on separate lines within a textarea

My form includes a text area where users can enter keywords, one per line. I would like to implement the following functionality: upon clicking a button, an ajax request will be sent to the server to retrieve the result for each keyword entered. The resul ...

Tips on concealing confidential keys within a React.js application on the frontend aspect

Desperate times call for desperate measures - I am attempting to conceal a secret key within my React frontend application. While I understand the risks involved, I feel compelled to do so without any other viable options. The reason behind my actions is ...

What is the method for obtaining class constructor argument types in the form of an object?

Let's consider an example where we have a class called Summator: export default class Summator { constructor(private readonly firstArgument: number, private readonly secondArgument: number) {} get sum() { return this.firstArgument + this.s ...

How can I utilize the mapping function on a promise received from fetch and display it on the page using React

As I'm using fetch to return a promise, everything is working fine. However, I am facing an issue while trying to map over the fetched data. When I check my console log, it shows "undefined." const dataPromise = fetch('http://api.tvmaze.com/sche ...

Manipulating the DOM in AngularJS Directives without relying on jQuery's help

Let's dive right in. Imagine this as my specific instruction: appDirectives.directive('myDirective', function () { return{ restrict: 'A', templateUrl: 'directives/template.html', link: functio ...

Tips for loading various content types in Fancybox 3

I am utilizing Fancybox 3 for my gallery where I have disabled the opening/closing animation. Here is how I load my gallery: $(document).on('click', '[data-fancybox-var]', function(e) { e.preventDefault(); var links = $(' ...