Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9113673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:01:03+00:00 2026-06-17T04:01:03+00:00

Newbie stackoverflow participant, newbie 3D programmer, and far from a math wiz… so I’ll

  • 0

Newbie stackoverflow participant, newbie 3D programmer, and far from a math wiz… so I’ll try to frame this question as clearly as I can, hoping it makes sense, and hoping for an answer that’s not a mile over my head.

I’ve written a very cool app using three.js that lets the user fly through 3D space and explore a solar system. The flight model is loosely based on the Fly.Controller example/extension in the three.js package which taught me to use quaternions for keeping all the axis rotations sensible relative to each other. The flying part all works great.

Here’s my dilemma: When using quaternions, how do I deduce the “normal” (I don’t know what else to call it) rotation values to determine which direction I am facing? When using quaternions, the “rotation” structure inside the camera object stays at 0,0,0. So, while I can freely fly through space at any angle, I can’t figure out how to determine what direction I’m actually facing. Is there a built in three.js function, or other easy way to convert this?

I’ve found some similar, confusing, pointers on the web, but nothing I can decipher and put to use in three.js. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:01:04+00:00Added an answer on June 17, 2026 at 4:01 am

    Thanks for the quick response – it wasn’t exactly what I was looking for, but I probably didn’t know how to ask the question clearly. My specific use-case was that I wanted to draw a 2D map the represented the relative positions of all the objects in my 3D scene, but I wanted to rotate the objects in the map based on the yaw of the camera in the 3D scene – so I needed to know the “angle” that the quaternion-based camera was facing so that I could offset the rotations of the 2D objects on the map accordingly. Seems to work pretty well. I just wish there didn’t have to be so many calculations, but at least Javascript is fast.

    // Pass the obj.quaternion that you want to convert here:
    //*********************************************************
    function quatToEuler (q1) {
        var pitchYawRoll = new THREE.Vector3();
         sqw = q1.w*q1.w;
         sqx = q1.x*q1.x;
         sqy = q1.y*q1.y;
         sqz = q1.z*q1.z;
         unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
         test = q1.x*q1.y + q1.z*q1.w;
        if (test > 0.499*unit) { // singularity at north pole
            heading = 2 * Math.atan2(q1.x,q1.w);
            attitude = Math.PI/2;
            bank = 0;
            return;
        }
        if (test < -0.499*unit) { // singularity at south pole
            heading = -2 * Math.atan2(q1.x,q1.w);
            attitude = -Math.PI/2;
            bank = 0;
            return;
        }
        else {
            heading = Math.atan2(2*q1.y*q1.w-2*q1.x*q1.z , sqx - sqy - sqz + sqw);
            attitude = Math.asin(2*test/unit);
            bank = Math.atan2(2*q1.x*q1.w-2*q1.y*q1.z , -sqx + sqy - sqz + sqw)
        }
        pitchYawRoll.z = Math.floor(attitude * 1000) / 1000;
        pitchYawRoll.y = Math.floor(heading * 1000) / 1000;
        pitchYawRoll.x = Math.floor(bank * 1000) / 1000;
    
        return pitchYawRoll;
    }        
    
    // Then, if I want the specific yaw (rotation around y), I pass the results of
    // pitchYawRoll.y into the following to get back the angle in radians which is
    // what can be set to the object's rotation.
    
    //*********************************************************
    function eulerToAngle(rot) {
        var ca = 0;
        if (rot > 0)
            { ca = (Math.PI*2) - rot; } 
        else 
            { ca = -rot }
    
        return (ca / ((Math.PI*2)/360));  // camera angle radians converted to degrees
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi, I'm a Rails newbie and this is my first stackoverflow question. I'm currently
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
This is my first question here on StackOverflow, and quite frankly I'm fairly new
I am a newbie in django (and stackoverflow also) but i try to set
this is going to be a total newbie question but I can't really do
Guys, I opened this question (I hope could help some others) but reading stackoverflow
I seem to have similar problem as this guy: Django newbie deployment question -
This is my first post here in StackOverflow. I am not a newbie to
I'm absolutely sure this will be a trivial, newbie question, but hey - what's
Newbie question... The objective: I intend to have an HTML text input field as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.