Is it possible to translate Pan/Tilt angles to XYZ coordinates in Three.js using Quaternion?

I am currently in the process of converting a legacy flash project to Three.js, and I need assistance with converting the existing pan/tilt values into 3D coordinates (x,y,z).

For example, let's take a look at a hotspot:

        var bubble = {
        name : 'hotspot',
        pan : 31,
        tilt : 0,
        distance : 2000
        };

When placed in the scene, these coordinates approximately represent the correct position:

        text.position.x = -100;
        text.position.z = 200;
        text.position.y = 0;

I am trying to figure out how to convert these values. The distance of 2000 is equivalent to 512 in the Three.js version.

I have been attempting to manipulate the numbers using , but math is not my strong suit.

Any help will be greatly appreciated!

EDIT

I have made some progress with:

var quaternion = new THREE.Quaternion();
    quaternion.setFromAxisAngle( new THREE.Vector3( 0, 1, 0 ), Math.radians(bubble.tilt) );
    quaternion.setFromAxisAngle( new THREE.Vector3( 1, 0, 0 ), Math.radians(bubble.pan) );
    quaternion.setFromAxisAngle( new THREE.Vector3( 0, 0, 1 ), Math.radians(bubble.distance/2) );

    text.position.x = quaternion.x * 512;
    text.position.z = quaternion.z * 512;
    text.position.y = quaternion.y * 512;

However, I am still struggling to position them correctly...

Here is a test:

They should be arranged more like this:

Answer №1

Utilizing the Quaternion class for rotation in 3D space

var rotation = new THREE.Quaternion();
rotation.setFromAxisAngle( new THREE.Vector3( 0, 1, 0 ), tilt );
rotation.setFromAxisAngle( new THREE.Vector3( 1, 0, 0 ), pan );
object.position.x = rotation.x;
object.position.y = rotation.y;
object.position.z = rotation.z;

This is pseudo code and has not been tested.

Answer №2

The initial try was successful

        var space = sphere.space/4;
        var pr = Math.radians(-1 * sphere.swivel );
        var tr = Math.radians( sphere.angle );

        words.place.x = space * Math.cos(pr) * Math.cos(tr);
        words.place.y = space * Math.sin(tr);
        words.place.z = space * Math.sin(pr) * Math.cos(tr);

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 it possible to use Selenium IDE to navigate if a variable contains a specific string

Thank you for taking the time to review this. I have developed a script that scans a web page to verify if a specific text string is present. If it is not found, the script will loop. The issue I am facing is that I am required to input every single word ...

Is there a way to adjust the quantity of items in the shopping cart without the need to reload the webpage?

Currently, I am working on a test project using React & Redux. The project involves implementing a basket feature where I receive an array of products structured like this: products: [ { name: "Product one", count: 1, ...

Activate and deactivate form fields on Safari

I have been working on a script to enable and disable a field using Javascript. It functions correctly in Internet Explorer, but I am encountering issues with Safari. FIELD If "Yes" is selected, the free text field below should be enabled; otherwise, it s ...

The save() function is not triggering the callback on a mongoose schema instance

I am encountering an issue while trying to save a JSON object in my database. The save() function is not triggering, and the JSON object remains unsaved. I suspect there might be a connection problem with Mongoose. Below is the code snippet showcasing the ...

An error was encountered when trying to read property '0' of an undefined object in a for loop

Currently, I am working on a project to create a mastermind game. Everything is progressing smoothly, except for one issue that keeps popping up - I keep encountering the error: "uncaught typeerror cannot read property '0' of undefined." fun ...

Implementing a Twitch bot in node.js using tmi.js that returns an object of type [object,

I am currently developing a game for a Twitch bot using node.js and tmi.js. The game involves a dynamic array called votePlayers, which changes each round based on messages received in the Twitch chat. To keep track of how many times each item appears in t ...

Looking to have two separate modules on a single page in AngularJS, each with its own unique view

<!DOCTYPE html> <html> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js" ...

Streaming videos using Flask with a custom template

After successfully implementing the DWA path planning algorithm in C with Python bindings, I have decided to create a web application demo. The concept involves a "robot" following the mouse using DWA, while allowing users to draw walls for objects. My ini ...

Display or conceal a div element depending on the user's choice

I am looking to hide inactive divs, but whenever I reload the page, all tab contents merge into one. The screenshot below shows the issue I'm facing. Screenshot Below is the code snippet: $('.tab a').on('click', function ...

JavaScript code - Empty values in an array

I'm facing a unique challenge: I need to make an ajax request to another URL (URL2) while on a specific page (URL1), retrieve the data and create an array from it for later use. To achieve this, I have to run code in the console while on "URL1". Here ...

Rendering multiple components in an array with React

I am trying to utilize the React MUI AccordionDetails component to display each element from the targetTypeData array, which always has a fixed length of 6 elements. Each element in the array consists of a Typography component. While my current approach s ...

Unleashing the power of JavaScript: A guide to dynamically generating nested arrays

Can you take a look at the code below and help me find the mistake? function pair(str) { // Function to pair specific letters in a string for (var i = 0; i < str.length; i++) { // Check and pair letters based on certain conditions if (s ...

PHP Ajax file uploads can be tricky, as they often result in the frustrating "undefined

Encountering issues with submitting file through ajax. Despite following instructions from various sources, the formdata does not seem to contain the file resulting in an 'undefined index 'image'' error. <form enctype: 'multip ...

Moving the panel to follow the mouse cursor in Firefox Add-on SDK

Is there a way to show a panel on the screen at the exact position of the mouse? I'm finding it difficult to understand how to change the position of the panel in Firefox SDK, as the documentation lacks detailed information. ...

What is the best way to transfer a querystring received in Node.js to a page being shown through res.render?

I have a nodejs file where I am rendering a page named foo.html. Within foo.html, I am using ajax to retrieve variables from a querystring and load an appropriate xml document based on those variables. The issue arises when I run my nodejs server, which is ...

The Chrome debugger will pause execution at a function without needing a DOM break point

Greetings! I am currently working on an angular js application. One issue that I have encountered is when I run the application and open the debugger by hitting F12, I notice that for every page it continuously calls a certain function and seems to stop th ...

Harmonizing database with AJAX-powered webpage

When using ajax calls to update data on a web page, what is the most effective way to synchronize changes with a database? For example, if I have a comment form that needs to work asynchronously. I write JS code to submit the form data to the database, but ...

Retrieving selected item values in Angular 2 using ng2-completer

Recently, I decided to experiment with a new autocompleter tool that is unfamiliar to me: https://github.com/oferh/ng2-completer. I successfully imported it and it seems to be functioning properly. My current goal is to retrieve the values of the selecte ...

Issue encountered with the Selenium JavaScript Chrome WebDriver

When it comes to testing an application, I always rely on using Selenium chromewebdriver. For beginners like me, the starting point was following this insightful Tutorial: https://code.google.com/p/selenium/wiki/WebDriverJs#Getting_Started After download ...

The integration of RxJS into a Master/Worker workflow

My current program utilizing the cluster library is structured like this: if(cluster.isMaster) { // include Rx subscriptions and workflows for the Master here } else if (cluster.isWorker){ // include Rx subscriptions and workflows for a Worker here } ...