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 3284190
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:07:36+00:00 2026-05-17T20:07:36+00:00

I need to calculate the 2 angles (yaw and pitch) for a 3D object

  • 0

I need to calculate the 2 angles (yaw and pitch) for a 3D object to face an arbitrary 3D point. These rotations are known as “Euler” rotations simply because after the first rotation, (lets say Z, based on the picture below) the Y axis also rotates with the object.

This is the code I’m using but its not working fully. When on the ground plane (Y = 0) the object correctly rotates to face the point, but as soon as I move the point upwards in Y, the rotations don’t look correct.

// x, y, z represent a fractional value between -[1] and [1]
// a "unit vector" of the point I need to rotate towards

yaw = Math.atan2( y, x )
pitch = Math.atan2( z, Math.sqrt( x * x + y * y ) )

Do you know how to calculate the 2 Euler angles given a point?


The picture below shows the way I rotate. These are the angles I need to calculate.
(The only difference is I’m rotating the object in the order X,Y,Z and not Z,Y,X)

pic

enter image description here


This is my system.

  • coordinate system is x = to the right, y = downwards, z = further back
  • an object is by default at (0,0,1) which is facing backward
  • rotations are in the order X, Y, Z where rotation upon X is pitch, Y is yaw and Z is roll

my system

  • 1 1 Answer
  • 1 View
  • 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-05-17T20:07:37+00:00Added an answer on May 17, 2026 at 8:07 pm

    Here are my working assumptions:

    • The coordinate system (x,y,z) is such that positive x is to the right, positive y is down, and z is the remaining direction. In particular, y=0 is the ground plane.
    • An object at (0,0,0) currently facing towards (0,0,1) is being turned to face towards (x,y,z).
    • In order to accomplish this, there will be a rotation about the x-axis followed by one around the y-axis. Finally, there is a rotation about the z-axis in order to have things upright.

    (The terminology yaw, pitch, and roll can be confusing, so I’d like to avoid using it, but roughly speaking the correspondence is x=pitch, y=yaw, z=roll.)

    Here is my attempt to solve your problem given this setup:

    rotx = Math.atan2( y, z )
    roty = Math.atan2( x * Math.cos(rotx), z )
    rotz = Math.atan2( Math.cos(rotx), Math.sin(rotx) * Math.sin(roty) )
    

    Hopefully this is correct up to signs. I think the easiest way to fix the signs is by trial and error. Indeed, you appear to have gotten the signs on rotx and roty correct — including a subtle issue with regards to z — so you only need to fix the sign on rotz.

    I expect this to be nontrivial (possibly depending on which octant you’re in), but please try a few possibilities before saying it’s wrong. Good luck!


    Here is the code that finally worked for me.

    I noticed a “flip” effect that occurred when the object moved from any front quadrant (positive Z) to any back quadrant. In the front quadrants the front of the object would always face the point. In the back quadrants the back of the object always faces the point.

    This code corrects the flip effect so the front of the object always faces the point. I encountered it through trial-and-error so I don’t really know what’s happening!

     rotx = Math.atan2( y, z );
     if (z >= 0) {
        roty = -Math.atan2( x * Math.cos(rotx), z );
     }else{
        roty = Math.atan2( x * Math.cos(rotx), -z );
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some face normals and I need to calculate the angle between the
I'm making analog clock in Java Swing. To calculate clock pointer angles I need:
I need to calculate one side of a triangle. I have the angles and
I need to calculate the angle in degrees between two points for my own
I need to calculate the time till Christmas in milliseconds. I'm using joda time
I need to calculate the total of an invoice. This invoice is created with
I need to calculate (in R) the number of positive and negative runs in
I need to calculate the net total of a column-- sounds simple. The problem
I need to calculate the number of FULL month in SQL, i.e. 2009-04-16 to
I need to calculate the distance (in meters and miles) between two coordinates given

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.