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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:52:39+00:00 2026-06-10T17:52:39+00:00

I have two 3D vectors called A and B that both only have a

  • 0

I have two 3D vectors called A and B that both only have a 3D position. I know how to find the angle along the unit circle ranging from 0-360 degrees with the atan2 function by doing:

EDIT: (my atan2 function made no sense, now it should find the “y-angle” between 2 vectors):

toDegrees(atan2(A.x-B.x,A.z-B.z))+180

But that gives me the Y angle between the 2 vectors.
I need to find the X angle between them. It has to do with using the x, y and z position values. Not the x and z only, because that gives the Y angle between the two vectors.
I need the X angle, I know it sounds vague but I don’t know how to explain. Maybe for example you have a camera in 3D space, if you look up or down than you rotate the x-axis. But now I need to get the “up/down” angle between the 2 vectors. If I rotate that 3D camera along the y-axis, the x-axis doens’t change. So with the 2 vectors, no matter what the “y-angle” is between them, the x-angle between the 2 vectors wil stay the same if y-angle changes because it’s the “up/down” angle, like in the camara.

Please help? I just need a line of math/pseudocode, or explanation. 🙂

  • 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-10T17:52:41+00:00Added an answer on June 10, 2026 at 5:52 pm

    Computing the altitude angle

    OK, it might be I finally understood your comment below about the result being independent of the y angle, and about how it relates to the two vectors. It seems you are not really interested in two vectors and the angle between these two, but instead you’re interested in the difference vector and the angle that one forms against the horizontal plane. In a horizontal coordinate system (often used in astronomy), that angle would be called “altitude” or “elevation”, as opposed to the “azimuth” you compute with the formula in your (edited) question. “altitude” closely relates to the “tilt” of your camera, whereas “azimuth” relates to “panning”.

    We still have a 2D problem. One coordinate of the 2D vector is the y coordinate of the difference vector. The other coordinate is the length of the vector after projecting it on the horizontal plane, i.e. sqrt(x*x + z*z). The final solution would be

    x = A.x - B.x
    y = A.y - B.y
    z = A.z - B.z
    alt = toDegrees(atan2(y, sqrt(x*x + z*z)))
    az = toDegrees(atan2(-x, -z))
    

    The order (A - B as opposed to B - A) was chosen such that “A above B” yields a positive y and therefore a positive altitude, in accordance with your comment below. The minus signs in the azimuth computation above should replace the + 180 in the code from your question, except that the range now is [-180, 180] instead of your [0, 360]. Just to give you an alternative, choose whichever you prefer. In effect you compute the azimuth of B - A either way. The fact that you use a different order for these two angles might be somewhat confusing, so think about whether this really is what you want, or whether you want to reverse the sign of the altitude or change the azimuth by 180°.


    Orthogonal projection

    For reference, I’ll include my original answer below, for those who are actually looking for the angle of rotation around some fixed x axis, the way the original question suggested.

    If this x angle you mention in your question is indeed the angle of rotation around the x axis, as the camera example suggests, then you might want to think about it this way: set the x coordinate to zero, and you will end up with 2D vectors in the y-z plane. You can think of this as an orthogonal projection onto said plain. Now you are back to a 2D problem and can tackle it there.

    Personally I’d simply call atan2 twice, once for each vector, and subtract the resulting angles:

    toDegrees(atan2(A.z, A.y) - atan2(B.z, B.y))
    

    The x=0 is implicit in the above formula simply because I only operate on y and z.

    I haven’t fully understood the logic behind your single atan2 call yet, but the fact that I have to think about it this long indicates that I wouldn’t want to maintain it, at least not without a good explanatory comment.

    I hope I understood your question correctly, and this is the thing you’re looking for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two vectors, v1 and v2. I would like to find any of
I'd like to do the following. but don't know how: //have two vectors: vector1
Say I have two 2D vectors, one for an objects current position and one
Elementwise multiplication of two vectors is no problem if they both have the same
I have a program that find coordinates between two point with a predefined interval:
i have to event that should insert values in two vectors but when event
Assume I have a template (called ExampleTemplate) that takes two arguments: a container type
I have two vectors, v1 and v2 v1 <- c('one', 'two', 'three') v2 <-
I have two vectors, and I would like to fill the first one with
So I have two vectors of data points, and I would like to make

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.