({{, (RefLink[VectorAngle, paclet:ref/VectorAngle])[u,v] 
gives the angle between the vectors u and v.}})

OpenersNotesSection(Spacer1)Details

(RefLink[VectorAngle, paclet:ref/VectorAngle]) gives an angle in radians.

For nonzero real vectors the vector angle θ satisfies cos θ==((u.v)/(‖u‖ ‖v‖)).

For complex vectors the numerator is u.(v^*).

OpenersPrimaryExamplesSection(Spacer1)Examples  (15)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

The angle between two vectors in 2D:

VectorAngle[{1,0},{1,1}]

Graphics[{Arrow[{{0,0},{1,0}}],Arrow[{{0,0},{1,1}}]}]

The angle between two vectors in 3D:

VectorAngle[{1,0,0},{1,1,1}]

Graphics3D[{Thick,Line[{{0,0,0},{1,0,0}}],Line[{{0,0,0},{1,1,1}}]}]

The angle between orthogonal vectors:

VectorAngle[{1,0},{0,1}]

VectorAngle[{1,0,1},{0,1,0}]

VectorAngle[UnitVector[10,1],UnitVector[10,2]]

OpenersExampleSection1(Spacer1)Scope  (2)

Use exact arithmetic to compute the vector angle:

u={1,2,3};v={1,1,1};

VectorAngle[u,v]

Use machine arithmetic:

VectorAngle[N[u],N[v]]

Use 47-digit precision arithmetic:

VectorAngle[N[u,47],N[v,47]]

Use symbolic vectors:

VectorAngle[{a,b},{x,y}]

Plot3D[VectorAngle[{1,0},{x,y}],{x,-1,1},{y,-1,1}]

RegionPlot[VectorAngle[{1,0},{x,y}]<Pi/3,{x,-1,1},{y,-1,1}]

OpenersExampleSection2(Spacer1)Generalizations & Extensions  (1)

For complex vectors, the angle returned may be complex:

VectorAngle[{1.,2.I},{3.I,4.}]

OpenersExampleSection4(Spacer1)Applications  (3)

Find when two vectors have the same direction:

samedirection[u_?VectorQ,v_?VectorQ]:=PossibleZeroQ[VectorAngle[u,v]]

samedirection[{1,2},{.1,.2}]

samedirection[{1,2},{-.1,-.2}]

Find the area of the triangle, with u and v as two sides:

tarea[u_?VectorQ,v_?VectorQ]:=(1/2)Norm[u]Norm[v]Sin[VectorAngle[u,v]]

tarea[{1,0},{0,1}]

Plot the area in the triangle formed by the x axis and a unit vector in the first quadrant:

Plot[tarea[{1,0},{Cos[θ],Sin[θ]}],{θ,0,Pi/2}]

Distribution of angles between random vectors with positive entries in 2, 3, 5, and 10 dimensions:

n = 10^5;
Table[
v = RandomReal[1, {n, 2, d}];
angles = Apply[VectorAngle, v, {1}]/Degree;
bins = BinCounts[angles, {0,90}]/n;
ListPlot[bins, DataRange->{0,90}],
{d, {2,3,5,10}}]

OpenersExampleSection5(Spacer1)Properties & Relations  (6)

The vector angle θ satisfies cos(θ)==((u.v)/(‖u‖ ‖v‖)):

u=RandomReal[1,{5}];
v=RandomReal[1,{5}];

θ=VectorAngle[u,v]

Cos[θ]==((u.v)/(Norm[u] Norm[v]))

The generalization to complex vectors satisfies cos(θ)==(1/(‖u‖ ‖v‖))u.(v^*):

u=RandomComplex[1+I,{5}];
v=RandomComplex[1+2I,{5}];

θ=VectorAngle[u,v]

Cos[θ]==((u.Conjugate[v])/(Norm[u] Norm[v]))

If you rotate a vector u in a plane that includes u, then the vector angle is the rotation angle:

u={1,0,-1};

v=RotationTransform[Pi/3,{1,1,1}][u]

VectorAngle[u,v]

If you rotate it in a plane that does not include u, then the angles differ:

v=RotationTransform[Pi/3,{0,0,1}][u]

VectorAngle[u,v]

The vector angle θ is related to the cross product through ‖u×v‖==|sin(θ)| ‖u‖ ‖v‖:

{u,v}=RandomReal[1,{2,3}]

θ=VectorAngle[u,v]

Norm[Cross[u,v]]==Abs[Sin[θ]]Norm[u]Norm[v]

(RefLink[ArcTan, paclet:ref/ArcTan]) of two arguments gives the signed vector angle between the x axis and the vector:

{x,y}={1,2};

ArcTan[x,y]

VectorAngle[{1,0},{x,y}]

FullSimplify[%%-%]

(RefLink[Eigenvectors, paclet:ref/Eigenvectors]) are the vectors for which the angle between m.x and x is 0:

m = {{1, 1/2},{1/2,1/3}};

f[t_] := Module[{x = {Cos[t], Sin[t]}},VectorAngle[m.x,x]]

Plot[f[t],{t,0, Pi}]

Quiet[FindMinimum[f[t],{t,.5}]]

{Cos[t], Sin[t]} /. %[[2]]

Eigenvectors[N[m]]

OpenersExampleSection6(Spacer1)Possible Issues  (1)

The angle between the zero vector and any other vector is indeterminate:

VectorAngle[{a,b},{0,0}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[PlanarAngle, paclet:ref/PlanarAngle])  ▪  (RefLink[PolygonAngle, paclet:ref/PolygonAngle])  ▪  (RefLink[Dot, paclet:ref/Dot])  ▪  (RefLink[Projection, paclet:ref/Projection])  ▪  (RefLink[ArcCos, paclet:ref/ArcCos])  ▪  (RefLink[Cross, paclet:ref/Cross])  ▪  (RefLink[Degree, paclet:ref/Degree])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Operations on Vectors, paclet:guide/OperationsOnVectors])}, {▪(RefLinkPlain[Angles and Polar Coordinates, paclet:guide/AnglesAndPolarCoordinates])}, {▪(RefLinkPlain[Region Properties and Measures, paclet:guide/GeometricPropertiesAndMeasures])}})}})