Conversion U/V coordinate system to cartesian system

112 Views Asked by At

I'm developing a tool in Matlab which uses four matrix that describe the electric field in a U/V coordinate system in the theta/phi component ($E_\theta, E_\phi$) and I want to plot a specific point of this field in a XY coordinate system. Right now this is the path that my tool is following:

I build a U/V grid in Matlab using meshgrid and then I convert it to theta/phi coordinate system using the relation:

$u=sin\theta cos\phi$
$v=sin\theta sin\phi$

which means $\theta=\sqrt{u^2+v^2}$; $\phi=atan(v/u)$
This means that I should have a new grid in theta/phi coordinate system. I just converted the grid and I think (and hope) that I don't need to touch the field values (right? Do I need to convert also the field?)
At this point I have a matrix E taken from the original file, the matrix $\theta$ and the matrix $\phi$.
I convert the field in its XY component using the relationship $\hat{\theta}=\hat{x}cos\theta cos\phi+\hat{y}cos\theta sin\phi-\hat{z}sin\theta$
$\hat{\phi}=-\hat{x}sin\phi+\hat{y}cos\phi$
For $\hat{\theta}$ I'm not interested in the $\hat{z}$ direction so I forget it. Then the new field should be the sum of the two component $E=E_x+E_Y$

To see the result I do 2 thing: the first is combine these new four E matrices with a single element of a 4x4 constant matrix that I can control, then I try to plot it inside a window in the theta/phi coordinate system making this conversion
$\theta_H=atan(tan(\theta)cos(\phi))$
$\theta_V=atan(tan(\theta)sin(\phi))$
that I extracted by trigonometric way using this image as reference

IMAGE

The problem is that the result of the plot has a small phase shift comming I don't know from where, but if I try to plot it at the begin of this chain there is not any phase shift. Am I doing something wrong? Or might be some sort of approximation errors that Matlab make? Otherwise, how can I convert a U/V coordinate system directly to my $\theta_H$/$\theta_V$ coordinate system?

The result should be two matrices the combination of the four matrices gives me two new matrices that should have: one 0 in the central column and the other 0 in the central row, exactly the same of $\theta_H$/$\theta_V$. The problem is that these two matrices don't have the zero where I but is a little bit rotated. Graphically means that the axis of symmetry of the plot is rotated while it should not be. Any help?