0

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

David
  • 161
  • 1
    It sounds like the function returns not a point in $\mathbb R^3$ but components of a vector field. I once ran into similar problems until I learned once and for all that components of vector fields transform differently from the points in $\mathbb R^3,.$ – Kurt G. Mar 07 '24 at 13:18
  • What is $\hat \phi ?$ – Digitallis Mar 07 '24 at 13:54
  • if your function returns polar cooardinates for the direction of the vector then of course you need to convert them back before plotting. btw: i noticed you used arctan. you might want to use arctan2 which takes 2 arguments and works in all 4 quadrants and does not have an issue at 0 – mond Mar 07 '24 at 18:09
  • @KurtG, after following the link you provided, if I take the return value from the func function as $f_{\phi}$, then I need to solve this system of equations: $$\begin{cases} V_{x}\cdot\cos(t)+V_{y}\cdot\sin(t)=0\ -V_{x}\cdot\sin(t)+V_{y}\cdot\cos(t)=f_{\phi}\ V_{z}=0\end{cases}$$ I then plot the vector $\vec{V}=V_{x}\hat{x} + V_{y}\hat{y} +V_{z}\hat{z}$ which works perfectly! However, in the link you provided, it seems the second equation should be: $$\frac{-V_{x}\cdot\sin(t)+V_{y}\cdot\cos(t)}{r}=f_{\phi}$$ In that case, I get a different plot. What is the reason for that? – David Mar 07 '24 at 19:07
  • The reason for that division by $r$ is normalization to unit length of the angular basis vector $\hat{\phi},.$ By convention, that $\hat{\phi}$ has unit length and is $\frac1r\partial_\phi,.$ This answer gets to the bottom of it. – Kurt G. Mar 07 '24 at 19:10

0 Answers0