Can anyone see where I have gone wrong here?

This is just a problem I made up for myself and I almost got it to come out but not quite. According to Gauss's Law I should get $\displaystyle \frac{Q}{\epsilon_0} $

but it doesn't quite come out.

I have a charge q offset a distance a_x along the x axis inside a sphere of radius r (so r > a). The surface is parametrised according to (alpha, beta) where alpha is an angle in the x-y plane and beta is angle between x-y and z plane.

My sphere is parametrised as $\displaystyle \tilde{p} = (r \cos{\left (\alpha \right )} \cos{\left (\beta \right )})\mathbf{\hat{i}_{N}} + (r \sin{\left (\alpha \right )} \cos{\left (\beta \right )})\mathbf{\hat{j}_{N}} + (r \sin{\left (\beta \right )})\mathbf{\hat{k}_{N}}$

My offset from charge vector at point a is $\displaystyle \tilde{a} = (- a_{x} + r \cos{\left (\alpha \right )} \cos{\left (\beta \right )})\mathbf{\hat{i}_{N}} + (r \sin{\left (\alpha \right )} \cos{\left (\beta \right )})\mathbf{\hat{j}_{N}} + (r \sin{\left (\beta \right )})\mathbf{\hat{k}_{N}}$

I worked out the electric field is defined as:

$\displaystyle E(r, \alpha, \beta) = \frac{q }{4 \pi \epsilon_{0} \left(a_{x}^{2} - 2 a_{x} r \cos{\left (\alpha \right )} \cos{\left (\beta \right )} + r^{2}\right)} $

and the unit normal is defined as:

$\displaystyle \tilde{N} = (\cos{\left (\alpha \right )} \cos{\left (\beta \right )})\mathbf{\hat{i}_{N}} + (\sin{\left (\alpha \right )} \cos{\left (\beta \right )})\mathbf{\hat{j}_{N}} + (\sin{\left (\beta \right )})\mathbf{\hat{k}_{N}}$

I basically evaluated this as a double integral over alpha and beta.

$\displaystyle \int_{-\pi}^{\pi} \int_{0}^{2 \pi} \tilde{E}(\alpha, \beta) \cdot \tilde{N} d \alpha \space d \beta $

I seem to have got stuck just doing the first part of the integral. I did the following

**for x component of E**:

$\displaystyle \int_{0}^{2 \pi} E_x(\alpha, \beta) N_x d \alpha = \int_{0}^{2 \pi} \frac{q \cos{\left (\alpha \right )} \cos{\left (\beta \right )}}{4 \pi \epsilon_{0} \left(a_{x}^{2} - 2 a_{x} r \cos{\left (\alpha \right )} \cos{\left (\beta \right )} + r^{2}\right)} d \alpha $

which I then rewrote as:

$\displaystyle \int_{0}^{2 \pi} \frac{q \cos{\left (\alpha \right )} \cos{\left (\beta \right )}}{4 \pi \epsilon_{0} \left(a_{x}^{2} - 2 a_{x} r \cos{\left (\alpha \right )} \cos{\left (\beta \right )} + r^{2}\right)} d \alpha = c_1 \int_{0}^{2 \pi} \frac{\cos{\left (\alpha \right )} }{k

- \cos{\left (\alpha \right )}} d \alpha

$

where $\displaystyle k = \frac{ \left(a_{x}^{2} + r^{2} \right)}{ 2 a_{x} r \cos{\left (\beta \right )}}$ and $\displaystyle c_1 = \frac{q }{8 \pi \epsilon_0 a_{x} r \cos{\left (\beta \right )}} $ and seeing that none of these expressions contained alpha I concluded it was ok to call them constants.

Now wolfram alpha integrates this to $\displaystyle - \alpha - \frac{2 k}{\sqrt{- k^{2} + 1}} \operatorname{atanh}{\left (\frac{\left(k + 1\right) \tan{\left (\frac{\alpha}{2} \right )}}{\sqrt{- k^{2} + 1}} \right )}$ and after applying my limits of integration evaluates to $\displaystyle \int_{0}^{2 \pi} E_x N_x d \alpha = -2 \pi$.

**For the y component of E**
$\displaystyle \int_{0}^{2 \pi} E_y(\alpha, \beta) N_y d \alpha = \int_{0}^{2 \pi}\frac{q \sin{\left (\alpha \right )} \cos{\left (\beta \right )}}{4 \pi \epsilon_{0} \left(a_{x}^{2} - 2 a_{x} r \cos{\left (\alpha \right )} \cos{\left (\beta \right )} + r^{2}\right)} d \alpha = c_1 \int_0^{2 \pi} \frac{sin(\alpha)}{k-cos(\alpha)} d \alpha

$

Wolfram Alpha just evaluates this integral to zero between these limits.

**Finally with z component of E**
$\displaystyle \int_{0}^{2 \pi} E_z(\alpha, \beta) N_z d \alpha = \int_{0}^{2 \pi}\frac{q \sin{\left (\beta \right )}}{4 \pi \epsilon_{0} \left(a_{x}^{2} - 2 a_{x} r \cos{\left (\alpha \right )} \cos{\left (\beta \right )} + r^{2}\right)} d \alpha = c_2 \int_0^{2 \pi} \frac{1}{k-cos(\alpha)} d \alpha

$

where

$\displaystyle c_2 = \frac{q \space \tan {\left ( \beta \right) } }{8 \pi \epsilon_0 a_{x} r }$

Wolfram alpha evaluates this integral to zero also.

So the first integrals E_y and E_z both vanish and the only surviving term is the integral of E_x which evaluated to $\displaystyle -2 \pi c_1 = - \frac{q}{4 a_{x} \epsilon_{0} r \cos{\left (\beta \right )}} $ which doesn't look like I'm heading in the right direction.

If I evaluate $\displaystyle \int_{-\pi}^{\pi} - \frac{q}{4 a_{x} \epsilon_{0} r \cos{\left (\beta \right )}} d \beta $ I end up with zero which is clearly wrong.

Isn't it true that Gauss's Law doesn't/shouldn't care about how the surface around and enclosing the charge is drawn? So it shouldn't matter that the charge is not at the origin, right? Is there something wrong with any of my assumptions?

Edit: I notice we can almost get there if we define $\displaystyle a_x =k_a r$ and I suspect I lost my Jacobian and if I add in $\displaystyle J = r^2 \cos{\left (\beta \right )}$ then:

$\displaystyle \int_{-\pi}^{\pi} - \frac{q}{8 \pi k_{a} \epsilon_{0} r^2 \cos{\left (\beta \right )}} \mathbf{J} d \beta = \int_{-\pi}^{\pi} - \frac{q}{8 \pi k_{a} \epsilon_{0} } d \beta $ then we can almost get there but still have too many constants.