# Magnetic field due to a straight current wire in 3D

How is magnetic field at a point due to current carrying wire calculated in 3D?

Let's say wire has current I placed along x-axis in direction x.

Would it just be $$\frac{\mu_0I}{2\pi y} \hat y + \frac{\mu_0I}{2\pi z} \hat z ?$$

I realized that this doesn't quite make sense as when there's a point in $$z = 0$$, this would give magnetic field of infinity. How could I get magnetic field in this case?

For an infinitely long and infinitely thin wire placed along the $$x$$ axis, the equation for the magnetic field is $$\mathbf{B} = \frac{\mu_0 I}{2\pi}\frac{1}{\sqrt{y^2+z^2}} \hat{\boldsymbol{\varphi}_{yz}},$$ where $$\hat{\boldsymbol{\varphi}_{yz}}$$ is the azimuthal direction in the $$yz$$ plane, defined as $$\hat{\boldsymbol{\varphi}_{yz}} = [-\sin(\arctan{\frac{z}{y}}) \hat{\mathbf{x}},\cos(\arctan{\frac{z}{y}}) \hat{\mathbf{y}},0].$$
and it is translationally invariant along the $$x$$ axis so any $$x$$ value would yield the same result. The magnitude of the vectors scale as the distance$$^{-1}$$ from the origin.
• you use the standard field from a wire: $\mathbf{B}(r) = \frac{\mu_0 I}{2\pi r} \hat{\boldsymbol{\phi}}$ that you get from Ampere's law. In this typical case, you assume the wire is oriented along the $z$ axis, so $r$ is the distance from the $z$ axis in cylindrical coordinates, $r = \sqrt{x^2+y^2}$. Here I just cast the formula for a wire aligned along the $x$ axis, so my "$r$" is the distance from the $x$ axis which is $\sqrt{y^2+z^2}$. Commented Apr 29, 2020 at 19:52