The issue of Gimbal Lock in rotation within Three JS

It appears that the quaternion rotation in Three JS can still experience Gimbal Lock.

To replicate the issue, follow these steps:

1) Go to the Three JS Editor. 2) Add a Cylinder and set the z value to 1.57 (the middle text box for rotation). 3) Try changing the values in y or x radians (the left or right text boxes for rotation).

You'll notice that both x and y rotations produce the same result. Any suggestions on how to prevent this?

As far as I know, Three JS uses quaternions by default and Gimbal Lock typically occurs when using Euler angles.

Thank you!

Answer №1

When working with code in three.js, consider adjusting the quaternion property of an object rather than the rotation property. This approach can help prevent gimbal lock issues that may arise when using quaternions.

In most editors, editing is limited to euler angles. However, since multiple euler angle representations can map to the same quaternion, the resulting rotation can be ambiguous;

Answer №2

When you want to rotate a mesh object using quaternion, you can achieve this by setting the rotation with the desired quaternion values instead of Euler angles.

var custom_quaternion = new THREE.Quarternion();
custom_quaternion.setFromAxisAngle(new THREE.Vector(0,1,0), Math.PI/2);
mesh.rotation.setFromQuaternion(custom_quaternion, "XYZ", true);

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

Position the close icon of the bootstrap modal on top of the image

I have integrated a bootstrap modal in my webpage and I am looking to add a close icon over the image within the modal. Currently, I am using a button to close the modal. <div id="myModal" class="modal fade" role="dialog"> <div class="modal-d ...

retrieving a date from a different source and displaying it in a date

Is there a way to ensure that the date format in an input of type date always follows the dd/MM/yyyy Brazilian pattern, regardless of the computer or browser specifications? <div class="input-group input-group text-center in ...

The maximum property in a Mongoose schema does not have any impact or

const mongoose = require("mongoose"); const PostSchema = new mongoose.Schema( { user_id: { type: String, required: true, }, content: { type: String, max: 150, required: true, }, }, { timest ...

I'm trying to create a customer slider using the codes provided, but unfortunately, I'm encountering some issues

I'm having trouble creating a slider that pulls all slider data from the database. Here are my codes, but the output is looking strange. I've attached a screenshot of the slider as well. I've tried everything, but I can't seem to figure ...

Adding Zoom and Drag Functionality to an External SVG integrated with D3.js

I'm trying to load an existing SVG (in XML format) into D3 and everything seems to be working fine until I add Zoom + Drag Behavior to the SVG. However, once I add the behavior, I experience strange jumps or flickering when dragging the objects in the ...

Using node.js to import modules with relative paths

For my project structured following the MVC pattern, I have node.js modules in various directories. I need to use require to access modules located outside of the current directory. How can I achieve this? /app/controller/c1.js ... /app/model/m1.js ... ...

Database hosted on Heroku platform

Curious to know, if you utilize Heroku for hosting, what database do you prefer? Do you lean towards PostgreSql, MongoDB, or another option altogether? I initially developed a bot using sqlite3, but quickly discovered that Heroku does not support it and ...

display the map at its current location before transitioning to the new destination using mapbox within a react hooks environment

After numerous attempts, I still can't get my map to load in the correct location before moving to the user's chosen destination. I suspect there is an issue with the onChange function, but I haven't been able to pinpoint the solution. The ...

How can one obtain a distinct identifier retroactively?

One thing that I am working on is changing button images upon clicking, but this isn't the main issue at hand. Each button corresponds to unique information retrieved from the database, and when clicked, the button should change and send the appropria ...

Efficient method for preserving dependent dropdown selections with Select2 and Ajax

I'm currently working on a script that dynamically populates the state dropdown menu based on the selected country id. Everything seems to be functioning correctly, but I've encountered an issue where I can only save the country selection using h ...

Contrasting the use of creating a new Promise and using Promise.resolve

Looking to gain insight into how the NodeJS runtime manages things in the code snippet below: const billion = 1000000000; function longRunningTask(){ let i = 0; while (i <= billion) i++; console.log(`Billion loops done.`); } function lon ...

Validating Angular UI Route state with Protractor

I've been experimenting with the protractor framework to conduct tests on my angular application. Is it possible for me to verify the angular state during an end-to-end test? ...

Loading an OBJ file from a blob using three.js

I am currently attempting to load an OBJ file from a blob using Three.js. After referring to this resource and successfully loading STL files, I encountered an issue with loading OBJ files. The error message I received is as follows: TypeError: text.indexO ...

Eliminate spacing in MaterialUi grids

As I work on a React project, I am faced with the task of displaying multiple cards with content on them. To achieve this layout, I have opted to use MaterialUi cards within Material UI grids. However, there seems to be an issue with excessive padding in t ...

Addressing the delay of "Rasterize Paint" on mobile devices while implementing css3 opacity transitions

I'm currently working on a project that involves users navigating back and forth between modals. To achieve this, I decided to use CSS transitions to change the opacity from 0 to 1. However, I've encountered some issues with slow transitions. So ...

Navigating to a Different Page in React Based on Button Click and Meeting Specific Conditions

Within this particular component, I have implemented a button named Submit. When this button is clicked, it triggers a series of actions: first, it exports the drawing created by the user as a jpeg URL, then sends this image data to another API that genera ...

Leveraging $last in Angular for obtaining the final visible element with ng-show

My ng-repeat container div contains multiple images, each with a corresponding div next to it. Using $last, I can make sure only the div of the final image is visible after all images. However, I also have a filter button on the page that hides certain im ...

Why does a Drone CI job abruptly end before a Selenium-based npm script is completed?

I currently have a drone set up and my pipeline is configured to do the following: pipeline: test: image: node:8.3.0 commands: - npm install --only=dev - npm run automation The automation script in my package.json looks like this: ...

Safari Displaying Error Message "Unhandled Promise Rejection: [object DOMError]" While Playing MP4 Video

I am facing an issue with playing a group of MP4 videos on hover in a container. You can view a demonstration by clicking the link below: While this functionality works smoothly in Chrome, it seems to be causing problems in Safari. Upon hovering, the vide ...

Ways to unlock all the information windows in Google Maps

Is it possible to automatically display all info windows on the map when it is first opened, eliminating the need for users to click on markers? In other words, I would like all info windows for all markers to be shown by default when the map is opened. ...