[Not sure if this information is completely what you're looking for, but it certainly is relevant. Please give a more specific problem statement or a simple worked example and I'll be happy to expand/refine my answer.]

The angle between vectors and is defined using the dot product like so: $$ \cos(\theta) = \frac{\vec{x}\cdot \vec{y}}{\|\vec{x}\| \ \|\vec{y}\|}$$ where the expression $\|\vec{a}\| = \sqrt{a_1^2 + a_2^2 + a_3^2}$ is the magnitude/norm of a vector. The magnitude of a vector in 3D space is just the square root of the sum of the squares of the components of that vector.

By using the inverse cosine function, you can determine the angle between the vectors. You'll have to pay attention to the sign of the dot product to determine if the resulting angle is acute (positive dot product), perpendicular (zero dot product), or obtuse (negative dot product).

Answer from Xoque55 on Stack Exchange
🌐
Omni Calculator
omnicalculator.com › math › angle-between-two-vectors
Angle Between Two Vectors Calculator. 2D and 3D Vectors
February 12, 2026 - Enter the second vector's values. Input ... The tool has found the angle between two 3D vectors the moment you fill out the last field.
🌐
MathWorks
mathworks.com › matlabcentral › answers › 2092961-how-to-calculate-the-angle-between-two-3d-vectors
How to calculate the angle between two 3D vectors? - MATLAB Answers - MATLAB Central
March 11, 2024 - I have two vectors that I want to calculate the angle between in 3D space, U and V. Vector U is calculated by subtracting where the first object was at Point 1 from where the object currently is at Point 2. Vector V is calculated by subtracting ...
Discussions

Angle between two 3D Vectors
Use the dot product formula and rearrange to solve for the angle. You can create two vectors originating from the intersection point that lie on the span of those two lines as inputs to your equation. More on reddit.com
🌐 r/gis
3
1
January 15, 2024
geometry - The X angle between two 3D vectors? - Stack Overflow
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 at... More on stackoverflow.com
🌐 stackoverflow.com
math - Signed angle between two 3D vectors with same origin within the same plane - Stack Overflow
What I need is a signed angle of rotation between two vectors Va and Vb lying within the same 3D plane and having the same origin knowing that: The plane contatining both vectors is an arbitrary an... More on stackoverflow.com
🌐 stackoverflow.com
Find the angle between two 3D-vectors - Mathematics Stack Exchange
In this picture (I'm using a $3D$ space, I draw it in $2D$ just to simplify), I have to find if the circumference $c$ intersecate the subtraction between $v2$ and $v1$, by checking the length of t... More on math.stackexchange.com
🌐 math.stackexchange.com
April 27, 2017
People also ask

How do I calculate the angle between two vectors in 3D?

To calculate the angle between two vectors in a 3D space:

  1. Find the dot product of the vectors.
  2. Divide the dot product by the magnitude of the first vector.
  3. Divide the resultant by the magnitude of the second vector.

Mathematically, angle α between two vectors [xa, ya, za] and [xb, yb, zb] can be written as:

α = arccos[(xa xb + ya yb + za zb) / (√(xa² + ya² + za²) × √(xb² + yb² + zb²) )].

🌐
omnicalculator.com
omnicalculator.com › math › angle-between-two-vectors
Angle Between Two Vectors Calculator. 2D and 3D Vectors
How do I calculate the angle between two vectors in 2D?

To calculate the angle between two vectors in a 2D space:

  1. Find the dot product of the vectors.
  2. Divide the dot product by the magnitude of the first vector.
  3. Divide the resultant by the magnitude of the second vector.

Mathematically, angle α between two vectors [xa, ya] and [xb, yb] can be written as:

α = arccos[(xa xb + ya yb) / (√(xa² + ya²) × √(xb² + yb²))].

🌐
omnicalculator.com
omnicalculator.com › math › angle-between-two-vectors
Angle Between Two Vectors Calculator. 2D and 3D Vectors
How to define the angle formed by two vectors?

The angle formed between two vectors is defined using the inverse cosine of the dot products of the two vectors and the product of their magnitudes.

🌐
omnicalculator.com
omnicalculator.com › math › angle-between-two-vectors
Angle Between Two Vectors Calculator. 2D and 3D Vectors
🌐
Reddit
reddit.com › r/gis › angle between two 3d vectors
r/gis on Reddit: Angle between two 3D Vectors
January 15, 2024 -

I am trying to find the angle between two, three-dimensional lines in ArcPro that meet at a point in 3D space. The two vector lines are known, and the point at which they meet is known.
Any advice on how to accomplish this?

Top answer
1 of 3
7
atan2(crossproduct.length,scalarproduct)

The reason for using atan2 instead of arccos or arcsin is accuracy. arccos behaves very badly close to 0 degrees. Small computation errors in argument will lead to disproportionally big errors in result. arcsin has same problem close to 90 degrees.

2 of 3
6

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.

Find elsewhere
Top answer
1 of 10
109

The solution I'm currently using seems to be missing here. Assuming that the plane normal is normalized (|Vn| == 1), the signed angle is simply:

For the right-handed rotation from Va to Vb:

atan2((Va x Vb) . Vn, Va . Vb)

For the left-handed rotation from Va to Vb:

atan2((Vb x Va) . Vn, Va . Vb)

which returns an angle in the range [-PI, +PI] (or whatever the available atan2 implementation returns).

. and x are the dot and cross product respectively.

No explicit branching and no division/vector length calculation is necessary.

Explanation for why this works: let alpha be the direct angle between the vectors (0° to 180°) and beta the angle we are looking for (0° to 360°) with beta == alpha or beta == 360° - alpha

Va . Vb == |Va| * |Vb| * cos(alpha)    (by definition) 
        == |Va| * |Vb| * cos(beta)     (cos(alpha) == cos(-alpha) == cos(360° - alpha)


Va x Vb == |Va| * |Vb| * sin(alpha) * n1  
    (by definition; n1 is a unit vector perpendicular to Va and Vb with 
     orientation matching the right-hand rule)

Therefore (again assuming Vn is normalized):
   n1 . Vn == 1 when beta < 180
   n1 . Vn == -1 when beta > 180

==>  (Va x Vb) . Vn == |Va| * |Vb| * sin(beta)

Finally

tan(beta) = sin(beta) / cos(beta) == ((Va x Vb) . Vn) / (Va . Vb)
2 of 10
83

Use cross product of the two vectors to get the normal of the plane formed by the two vectors. Then check the dotproduct between that and the original plane normal to see if they are facing the same direction.

angle = acos(dotProduct(Va.normalize(), Vb.normalize()));
cross = crossProduct(Va, Vb);
if (dotProduct(Vn, cross) < 0) { // Or > 0
  angle = -angle;
}
🌐
Jwwalker
jwwalker.com › pages › angle-between-vectors.html
Angle Between Vectors
Therefore the angle between \(\mathbf{u}\) and \(\mathbf{v}\) is \(2\,\operatorname{atan2}\left(\left\|\mathbf{u} - \mathbf{v}\right\|, \left\|\mathbf{u} + \mathbf{v}\right\|\right)\). To handle the more general case, we can scale \(\mathbf{u}\) and \(\mathbf{v}\) by each other's lengths to get vectors of the same length:
Top answer
1 of 2
3

Use inner product of vectors. The relation is with $norm(v)=|v|$.

Take and . The inner product is . The norm is .

So the angle becomes

Find components of each vector and substitute.

2 of 2
1

This is not an answer to the stated question, but more like an extended comment; specifically, that there is an even easier way to find out , the minimum distance between the line segment and point .

The question implies that OP is interested in whether a spherical shell, let's say of radius , centered at , intersects the line segment between and .

  1. If , and , then both points and are within the spherical shell. Because the shell is convex, the line segment between and is also completely inside the spherical shell (and therefore there is no intersection per se).

    In practice, the checks are better written as and , i.e. and

    Otherwise,

  2. If , then point is within the spherical shell. Because isn't, the line segment between and must pass through the spherical shell.

    Otherwise,

  3. If , then point is within the spherical shell. Because isn't, the line segment between and must pass through the spherical shell.

    Otherwise,

  4. Calculate the distance squared between point and the line that passes through points and (using e.g. Point-Line distance from Wolfram MathWorld) :

    i.e.

    Now, if , the entire line passing through and is outside the spherical shell, and there cannot be any intersection.

    Otherwise,

  5. Calculate the relative position of the point closest to on the line passing through and :

    If , then the closest point to on the line is between and , and it is either inside () or on () the spherical shell.

    This test can also be written as

    Otherwise, there is no intersection. (The line that passes through and does intersect the -radius spherical shell centered at , but the intersections do not occur in the segment between and .)

If I counted right, the maximum cost of the above tests, total, is 25 multiplications, one division, and 46 additions or subtractions (but much fewer multiplications and additions or subtractions if you use temporary variables so you don't do the same operations repeatedly). On a computer, that is roughly comparable to the work done to evaluate a single trigonometric function; so if you use that as the metric for "easy" (I do), this is definitely "easier".

🌐
Excel Forum
excelforum.com › excel-general › 1321988-angle-between-two-3d-vectors-new-post.html
Angle between two 3D Vectors
It's a bit of work and you have to be real careful with parentheses and such when you nest that much into a single cell formula, but it seems like it should not be too difficult: 1) cross product i term b*z-c*y, cross product j term a*z-c*x, cross product k term a*y-b*x 2) magnitude of a vector is SQRT(SUMSQ(vector elements)) so SQRT(SUMSQ(b*z-c*y,a*z-c*x,a*y-b*x)) 3) dot product is a simple SUMPRODUCT(vector elements a, vector elements b) SUMPRODUCT({a,b,c},{x,y,z}) or references to the ranges with those values.
🌐
MathWorks
la.mathworks.com › matlabcentral › answers › 1839323-angle-between-two-3d-vectors
Angle between two 3D vectors - MATLAB Answers
October 30, 2022 - View questions and answers from the MATLAB Central community. Find detailed answers to questions about coding, structures, functions, applications and libraries.
🌐
Wikipedia
en.wikipedia.org › wiki › Rotation_matrix
Rotation matrix - Wikipedia
1 week ago - This has the convenient implication for 2 × 2 and 3 × 3 rotation matrices that the trace reveals the angle of rotation, θ, in the two-dimensional space (or subspace). For a 2 × 2 matrix the trace is 2 cos θ, and for a 3 × 3 matrix it is 1 + 2 cos θ. In the three-dimensional case, the ...
🌐
Quora
quora.com › How-do-I-calculate-the-angle-between-two-vectors-in-3D-space-using-atan2
How to calculate the angle between two vectors in 3D space using atan2 - Quora
To compute the angle θ between two 3D vectors a and b robustly, use the atan2 form that combines cross-product magnitude and dot product. This avoids numerical instability near 0 and π that can occur when using acos.
🌐
Stack Exchange
math.stackexchange.com › questions › 1742107 › how-to-find-angle-between-a-2d-and-a-3d-vectors
How to find Angle between a 2D and a 3D Vectors - Mathematics Stack Exchange
April 14, 2016 - I know that to find the angle between two 2D vectors, you can use scalar multiplication which is: $u\times v = ||u||\times ||v||\times \cos\theta$ However I am confused as to how I am supposed to approach this when it is a 2D and 3D vector.
🌐
Cuemath
cuemath.com › geometry › angle-between-vectors
Angle Between Two Vectors - Formula, How to Find?
Let us consider an example to find the angle between two vectors in 3D. Let a = i + 2j + 3k and b = 3i - 2j + k.
🌐
VCalc
vcalc.com › wiki › angle-between-vectors
Angle between Vectors
February 21, 2024 - The Angle Between Vectors calculator computes the angle(α) separating two vectors (V and U) in three dimensional space.
🌐
Reddit
reddit.com › r › learnmath › comments › 5wz3ob › find_angle_between_two_3d_vectors
r/learnmath - Find angle between two 3D vectors.
March 1, 2017 -

Say I have two vectors:

V1 = { x: 5, y: 13, z: 32 } V2 = { x: 8, y: -14, z: 0 }

How can I figure out what angle v1 needs to be rotated to look directly at v2?

Put into English: say I knew exactly where I was in space, and exactly where another person was somewhere else in space.... Mathematically, how could I figure out what angles to put my finger at to point at them?

🌐
Website Files
cdn.prod.website-files.com › 66f3d7045c1006a95df3dd6c › 686a4210236965c317a0ab3b_junufemefuvas.pdf pdf
Angle between two vectors 3d
The final formula for calculating the angle between two vectors in 2D space is: α = arccos((x1⋅x2 + y1⋅y2) / (|x1||x2|)) In 3D space, the formula is: α = arccos((x1⋅x2 + y1⋅y2 + z1⋅z2) / (|x1||x2|)) These formulas can be used to calculate the angle between two vectors in any number ...