Background information first: Using Ampère's law we can find the magnetic field due to a current, I. We do this with a line integral around a closed path encompassing the current (e.g. long straight wire).
$\oint_c \vec B \cdot \vec dl$ = $\mu_0 I_{enc}$
If we choose a circle centered on the wire (like the images below) we greatly simplify things because the magnetic field (right-hand-rule) is perpendicular to the current flow. With the selected path (circle) the B field is colinear with the circle so the dot product between $\vec B$ and $\vec dl$ reduces to |B||dl| since cosine $0^\circ$ is 1. Right-hand figure of image below is looking down from above with wire in center of circle.
This choice of using a circle for the closed path around the current conveniently reduces the problem to that of finding the circumference of the circle, resulting in the following equation for the magnetic field.
$B = \frac{\mu_0 I_{enc}}{2\pi r}$
So, i wanted to see if i could derive an equation for B using an ellipse instead.
In this case, since the magnetic field is perpendicular to the flow of current the incremental length $\vec dl$ and $\vec B$ will only be colinear at 4 points (on the axes). EDIT - i redrew the right-hand image above to clarify the relationship between the direction of $\vec B$ and the direction of $\vec dl$ at a point on the ellipse. The dashed-red circle is just used to find the direction of $\vec B$ which is tangential to the circle.
However, we know the slope of the ellipse at each (x,y) is $\frac{-xb^2}{ya^2}$. We know that the slope of $\vec B$ at (x,y) is the slope of a circle that has the same origin as the ellipse and passes through (x,y). So, the slope of $\vec B$ is $\frac{-x}{y}$...and now we know the slope of both the ellipse and the $\vec B$ at (x,y).
For the dot product we need $\cos(θ)$. We know that $\tan(\theta) = \dfrac{m_2-m_1}{1+m_1m_2}$ so knowing the 2 slopes we have $\tan(\theta)$. Knowing that $\cos^2 = \frac{1}{1+\tan^2}$ we end up with the following:
$\cos^2(\theta) = \frac{1}{1+|\frac{-xya^2+xyb^2}{a^2y^2+x^2b^2}|^2}$
Knowing the circumference of the ellipse, P, I believe that Ampère's integral is now as follows.
$BP\oint_c \cos(\theta)$ = $\mu_0 I_{enc}$
which reduces to,
$B = \frac{\mu_0 I_{enc}}{P\oint_c \cos(\theta)}$
Does this appear correct to this point? How can i work this into a form that is comparable to the circle case, $B = \frac{\mu_0 I_{enc}}{2\pi r}$, but for an ellipse? The idea is to be able to calculate the B at any (x,y) around the wire. Since $r = \sqrt{x^2+y^2}$ this is easy with the formula derived from the circle. We also know that at any point (x,y) on the ellipse i should get the same value of B as from $B = \frac{\mu_0 I_{enc}}{2\pi \sqrt{x^2+y^2}}$.
Your help/input/corrections appreciated.
Addendum: This edit below made after reading Andreas and user's comments just to make few comments that i'll dwell on further (not sure if will be useful).
We know that $B = \frac{\mu_0 I_{enc}}{2\pi r}$ which is same as $B = \frac{\mu_0 I_{enc}}{2\pi \sqrt{x^2+y^2}}$.
So, $\oint_c \vec B \cdot \vec dl = \oint_c |\frac{\mu_0 I_{enc}}{2\pi \sqrt{x^2+y^2}}||dl|\cos(\theta)$, where $\theta$ is the angle between $\vec B$ and $\vec dl$ at each (x,y).
Knowing that $\oint_c dl = P$ (perimeter of ellipse) we can simplify the r.h.s,
$= P\frac{\mu_0 I_{enc}}{2\pi} \oint_c |\frac{1}{\sqrt{x^2+y^2}}|\cos(\theta)$
Which, since $\oint_c \vec B \cdot \vec dl$ = $\mu_0 I_{enc}$, we can now write
$\oint_c |\frac{1}{\sqrt{x^2+y^2}}|\cos(\theta) = \frac{2\pi}{P} $
Knowing formula for $\cos^2(\theta)$ this becomes,
$\oint_c |\frac{1}{\sqrt{x^2+y^2}}| \sqrt{\frac{1}{1+|\frac{-xya^2+xyb^2}{a^2y^2+x^2b^2}|^2}} = \frac{2\pi}{P} $