Applying a Vector Field Defined in Cylindrical Coordinates $(r, \phi, z)$ to Points in Cartesian Coordinates $(x, y, z)$

29 Views Asked by At

I have written a Python script that defines a meshgrid. The meshgrid represents a 3D grid in Cartesian (x, y, z) coordinates, and for each point, I want to apply a function. After applying the function to all points, I should obtain a vector field.

Firstly, I convert each given point to cylindrical coordinates using the following equations: $$r = \sqrt{x^2+y^2}$$ $$\phi = \arctan\left(\frac{y}{x}\right)$$ Since my func takes cylindrical coordinates and returns cylindrical coordinates: r, \phi, z = func(r, \phi, z)

I need to convert the coordinates back to Cartesian (x, y, z):

$$x = r\cos(\phi)$$ $$y = r\sin(\phi)$$

When I plot the points after running the script, the results are not as expected. I defined func to be the magnetic field:

$$func(r, \phi,z) = \hat{\phi}\left(\begin{cases} \frac{R^2}{3\cdot r}& R\leq r\\ \frac{r^2}{3\cdot R} &r < R\end{cases}\right)$$

and is seems the convertion of vector back to Cartesian, ignores the magnitude of the rotation effect the magnetic field does. the result plot looks like that: enter image description here

I achieve the expected result only after taking the return value of func as the new radius $(r)$ and defind the vectors with the following convertion: $(-r\cdot sin(t), r\cdot cos(t), 0)$: enter image description here