The built-in VectorAngle function sometimes returns complex output when the actual angle is very close to π. The imaginary component is large enough and can't be removed by Chop with default tolerance:
VectorAngle[{0.034429687500000083, 0}, {-0.03442968749999986, 0}]
%//Chop
3.141592653589793` - 2.1073424338879928`*^-8 I3.141592653589793
- 2.1073424338879928*^-8 I
For comparison, custom implementation works as expected:
vectorAngle[v1_, v2_] := ArcCos[v1.v2/(Norm[v1] Norm[v2])]
vectorAngle[{0.034429687500000083, 0}, {-0.03442968749999986, 0}]
3.141592653589793`
From where comes imaginary part in the output? Is it a bug?
ArcCosis greater than1. It may be because ofprecisionofVectorAngle. – Anjan Kumar Feb 18 '17 at 03:00(VectorAngle[{0.034429687500000083, 0}, {-0.03442968749999986, 0}]/ Pi // RootApproximant)*Pievaluates toPi– Bob Hanlon Feb 18 '17 at 04:48