3

I have two vectors:

H = {1, 0, π/4};
EA = {1, 0, 0};

Which I want to be in {r, Phi, Theta} - which would should give an angle between the two vectors as π/4.

However, I get VectorAngle[N[EA], N[H]] = 0.66577 in Mathematica.

I'm not sure if there is an issue with the coordinate system, or .... ?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Joseph
  • 217
  • 1
  • 5
  • 1
    Mathematica doesn't know that your vectors are in spherical coordinates. It's assuming that you are using rectangular (Cartesian) coordinates. Convert to rectangular coordinates first and try again. – march Jan 29 '16 at 23:11
  • 1
    Apply[VectorAngle, #1 {Cos[#2] Sin[#3], Sin[#2] Sin[#3], Cos[#3]} & @@@ {EA, H}] – march Jan 29 '16 at 23:14
  • Worked perfectly, thank you! – Joseph Jan 29 '16 at 23:23
  • Also see this Q&A for a pathological case where VectorAngle becomes inaccurate. The three answers there provide different workarounds. – Jens Jan 30 '16 at 05:01

1 Answers1

2

In my opinion, this is not a problem that is easy to solve by reading the docs, because anything less than very thorough and careful reading of the docs on the subject of converting spherical to cartesian coordinates can easily lead the user astray.

A casual reading of the docs will lead one to think

map = CoordinateTransformData["Spherical" -> "Cartesian", "Mapping"];
u = {1, 0, π/4};
v = {1, 0, 0};
VectorAngle @@ map /@ {u, v}

will work, but it gives

0

The problem is caused by the user assuming that φ, the 2nd spherical coordinate, is latitude aka altitude, but it's not; it's declination aka polar angle. So one must use

VectorAngle @@ map /@ MapAt[π/2 - # &, {u, v}, {All, 2}]

π/4

m_goldberg
  • 107,779
  • 16
  • 103
  • 257