Adjusting the orientation of a vector worldwide using a quaternion in THREE.js

Is there a way to set the absolute global rotation of a vector using a quaternion?

Imagine a function called f(v, q) which rotates vector v to quaternion q.

While THREE.Vector3 has a .applyQuaternion function for applying rotations to vectors, this is a relative rotation. For instance, calling f(f(v, q), q) applies q twice instead of the desired result f(f(v, q), q) = f(v, q) where q represents the absolute rotation.

I am aware that I can calculate some

deltaQ = currentQ.premultiply(q.inverse())
and then use .applyQuaternion, but the challenge lies in retrieving the currentQ or the current rotation of the vector so that it can be reversed and updated with the new quaternion.

Your assistance is greatly appreciated!

UPDATE:

My goal is to rotate around a point specified in world coordinate space, hence the usage of object.worldToLocal and object.localToWorld functions. However, when performing these conversions, the rotating object seems to veer off course.

Answer №1

The most straightforward method to achieve this is by resetting the Vector3 back to its original state, and then applying the quaternion transformation to this reset vector. This effectively removes any previous rotation that may have been applied. For example, assuming the vector's default orientation is pointing in the direction of 'UP':

function transformVector(v, q) {
    v.set(0, 1, 0);
    v.applyQuaternion(q);
    return v;
}

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

When utilizing Express, only the index.html page is rendered, all additional pages

I've set up an express app specifically for serving static HTML files. let express = require('express'); let path = require('path'); let cookieParser = require('cookie-parser'); let logger = require('morgan'); ...

Transitioning from Three.js's CanvasRenderer to WebGLRenderer is a significant upgrade

Can a Three.js script created with CanvasRenderer be easily converted to use WebGLRenderer instead, and if yes, what is the process for doing so? ...

Unable to retrieve data from variables in ejs templates

I have created a basic application using mongodb and express. I am attempting to showcase an array within an ejs page, but only certain attributes from the objects in the array. However, I am running into issues where it either shows nothing at all or disp ...

Is it possible to set an onmousedown event to represent the value stored at a specific index in an array, rather than the entire array call?

Apologies if the question title is a bit unclear, but I'm struggling to articulate my issue. The challenge lies in this synchronous ajax call I have (designed to retrieve json file contents). $.ajax({ url: "/JsonControl/Events.json", dataTyp ...

How to Create a Speech Bubble in SVG Using SnapSVG

In the process of developing a chat program, I have animated figures moving across the screen engaging in conversations. One crucial aspect I am yet to implement is creating scalable speech bubbles for when users interact. Being relatively new to SVG and ...

Keeping track of both the search query and the results

I have stored the current search term in a state using e.target.value as searchField, but when I clear the input value, I can no longer use it. I want to display a message in the body informing the user that their specific searched term yielded no results, ...

What is the best way to implement lazy loading of images that have not been downloaded in a JavaFX WebView?

Currently, I am in the process of developing an email client application using JavaFX WebView to showcase email HTML files. In order to enhance its responsiveness and speed, my goal is to display inline images in emails as they are downloaded locally. Duri ...

What is the best way to retrieve the value from a textfield in one module and use it in a

How can I access the value of a textField in another module within React.js without importing the entire textfield component? What is the most effective approach to get access to the value variable in a different module? Below is a sample functional textF ...

Switch out bootstrap icons for angular material icons

I'm currently in the process of transitioning from using Bootstrap to Angular Material in an existing application. I need assistance with replacing the Bootstrap icons with Angular Material icons. Any help is greatly appreciated. <md-button class= ...

Developing a personalized data binding feature with AngularJS and utilizing ng-repeat

Looking to design a unique controller that can display multiple similar objects connected to a dataset structured like this: [{name: card1, values: {opt1: 9, opt2: 10}},{name: card1, values: {opt1: 9, opt2: 10}}] The goal is to showcase the name and one ...

What could be causing my Discord bot to remain offline even when I run the command node main.js?

After successfully installing node.js, I proceeded to type the command 'npm init' in the command prompt and then installed discord.js. However, upon installation of discord.js, a 'node_modules' folder was not added inside the project, w ...

Angular 2: Troubleshooting Issues with Observable Data Display

Looking to implement a RESTful call with Angular 2 that constantly updates whenever there are changes in the API. In my service, I've included an Observable to fetch data from the API: getData(): Observable<any[]> { return this.http.get(url) ...

"Utilize the canvas to crop and draw an image

Hello, I have an image with a size of 750x554. To load the image into an img tag, I use the following method: <input type="file" accept="image/*" onchange="document.getElementById('character').src = window.URL.createObjectURL(this.fi ...

Failure to pass parameters between different states

There is a situation where clicking on a link should change the route and send some parameters to another state. The problem arises when the parameters appear to be empty when logged in the other state. <div ng-repeat="items in vm.Items"> <a ...

Exploring Style Attribute Manipulation using vanilla JavaScript on Firefox

I searched for a similar question, but I couldn't find anything quite like it. I'm currently developing a JavaScript Slider plugin for various projects within our company. This requires me to manipulate styles on certain elements in the DOM. I&a ...

The PrimeNG FullCalendar feature seems to be malfunctioning and cannot be located

I've been working on integrating a FullCalendar module into my Angular 7 project. Despite following the steps provided in this link, I haven't had any luck: After executing this command: npm install <a href="/cdn-cgi/l/email-protection" clas ...

How can I determine if a variable is a primitive type and not an object?

Can a variable be tested to determine if it is a primitive data type? I've come across many inquiries about testing a variable to check if it is an object, but not specifically for a primitive type. This inquiry is purely academic, as I do not requi ...

What is the best method for accessing the value of material-ui's Autocomplete Select component?

Is there a way to retrieve the selected value from a drop-down menu? I have the following code snippet, but it's logging an unexpected message to the console: MUI: The getOptionLabel method of Autocomplete returned number (0) instead of a string for ...

"Utilize Regular Expressions to conceal part of a text string with a

Looking for a way to conceal part of a string using JavaScript? For example, wanting to mask the second and third segments of a credit card number like this using regex: 4567 6365 7987 3783 → 4567 **** **** 3783 3457 732837 82372 → 3457 ****** 82372 ...

Submit a set of form variables to PHP using AJAX

I am attempting to transmit a set of form parameters to a PHP script for processing. In the past, I have achieved this using $.post, but now my goal is to accomplish it exclusively with $.ajax. Below is the jQuery click event designed to send all variabl ...