# Field Lines of a Bar Magnet

I'm trying to plot magnetic field lines for a rectangular bar magnet in 3 dimensional space. The position of the magnet is known and we wish to produce a plot such as the one shown below.

Can something like the Biot Savart law be modified for an exact or approximate solution to this to enable plotting You can model a bar magnet by a rectangular box with a constant magnetization in one direction. Let's take the box $$[0,a]\times[0,b]\times[0,c]$$, with a constant magnetization $$\mathbf M(\mathbf x) = M_0 \ \hat{\mathbf k}$$, where $$\hat{\mathbf k}$$ is the unit vector in the $$z$$ direction. The bound volume and surface current densities are: $$\mathbf J_b(\mathbf x) = \boldsymbol{\nabla}\times\mathbf M(\mathbf x)$$ $$\mathbf K_b(\mathbf x) = \mathbf M(\mathbf x) \times \hat {\mathbf n}$$ The volume current density is zero because $$\mathbf M$$ is constant. For the surface current density, the top and bottom faces don't contribute since $$M_0 \hat{\mathbf k}\times\hat {\mathbf k}=0$$. For the other four faces we have: $$\mathrm{x=0 \ face:} \ \mathbf K_1 = M_0 \ \hat{\mathbf k}\times (-\hat{\mathbf i}) = -M_0 \ \hat{\mathbf j}$$ $$\mathrm{x=a \ face:} \ \mathbf K_2 = M_0 \ \hat{\mathbf k}\times \hat{\mathbf i} = M_0 \ \hat{\mathbf j}$$ $$\mathrm{y=0 \ face:} \ \mathbf K_3 = M_0 \ \hat{\mathbf k}\times (-\hat{\mathbf j}) = M_0 \ \hat{\mathbf i}$$ $$\mathrm{y=b \ face:} \ \mathbf K_4 = M_0 \ \hat{\mathbf k}\times \hat{\mathbf j} = -M_0 \ \hat{\mathbf i}$$ Now that you know the bound current distribution, you can simply use the Biot-Savart law to calculate the magnetic field: $$\mathbf B(\mathbf x) = \frac{\mu_0}{4\pi}\int_{\mathbb S}d\mathbf a' \ \mathbf K(\mathbf x') \times \frac{\mathbf{x-x'}}{|\mathbf{x-x'}|^3}$$ I believe you can take it from here.