User:Cornince/circlediff

$$r^2 = x^2 + y^2 = (x + \Delta x)^2 + (y + \Delta y)^2\,$$

$$s^2 = \Delta x^2 + \Delta y^2\,$$

$$r > 0\,$$

$$0 < s \le 2r\,$$

$$x^2 + y^2 = x^2 + 2 x \Delta x + \Delta x^2 + y^2 + 2 y \Delta y + \Delta y^2\,$$

$$0 = 2 x \Delta x + \Delta x^2 + 2 y \Delta y + \Delta y^2\,$$

$$0 = 2 x \Delta x + 2 y \Delta y + s^2\,$$

$$0 = 2 x \Delta x + s^2 + 2 \sqrt{r^2 - x^2} \sqrt{s^2 - \Delta x^2}\,$$

$$2 x \Delta x + s^2 = -2 \sqrt{r^2 - x^2} \sqrt{s^2 - \Delta x^2}\,$$

$$4x^2 \Delta x^2 + 4x \Delta x s^2 + s^4 = 4r^2s^2 - 4r^2 \Delta x^2 - 4x^2s^2 + 4x^2 \Delta x^2\,$$

$$4s^2 x \Delta x + s^4 = 4r^2s^2 - 4r^2 \Delta x^2 - 4s^2x^2\,$$

solving for delta x

$$(4r^2) \Delta x^2 + (4xs^2) \Delta x + (s^4 + 4x^2s^2 - 4r^2s^2) = 0\,$$

$$\Delta x = \dfrac{ -(4xs^2) \pm \sqrt{(4xs^2)^2 - 4(4r^2)(s^4 + 4x^2s^2 - 4r^2s^2)} } {  2(4r^2)  }\,$$

$$\Delta x = \dfrac{ -4s^2x \pm \sqrt{16s^4x^2 - 16r^2s^4 - 64r^2s^2x^2 + 64r^4s^2} } {  8r^2  }\,$$

$$\Delta x = \dfrac{ -s^2x \pm \sqrt{s^4x^2 - r^2s^4 - 4r^2s^2x^2 + 4r^4s^2} } {  2r^2  }\,$$

by extension,

$$\Delta y = \dfrac{ -s^2y \mp \sqrt{s^4y^2 - r^2s^4 - 4r^2s^2y^2 + 4r^4s^2} } {  2r^2  }\,$$

So with an origin point of (x, y), a destination point is (see subpage circlediff/test1 for further proof):

$$\left (  x + \dfrac{  -s^2x \pm \sqrt{s^4x^2 - r^2s^4 - 4r^2s^2x^2 + 4r^4s^2} } {  2r^2  }, y + \dfrac{  -s^2y \mp \sqrt{s^4y^2 - r^2s^4 - 4r^2s^2y^2 + 4r^4s^2} } {  2r^2  }   \right ) \,$$

for our purposes, $$x = 0, y = r\,$$

$$\Delta x_1 = \dfrac{ -s^2(0) \pm \sqrt{s^4(0)^2 - r^2s^4 - 4r^2s^2(0)^2 + 4r^4s^2} } {  2r^2  }\,$$

$$\Delta x_1 = \dfrac{ \pm \sqrt{4r^4s^2 - r^2s^4}  } {  2r^2  }\,$$

$$\Delta x_1 = \pm \sqrt{ s^2 - \dfrac  {s^4}{4r^2}   }\,$$

(for positive sqrt)

$$\Delta x_2 = \dfrac{ -s^2 \left ( \sqrt{s^2 - \dfrac{s^4}{4r^2}} \right ) \pm \sqrt{s^4 \left ( \sqrt{s^2 - \dfrac{s^4}{4r^2}} \right ) ^2 - r^2s^4 - 4r^2s^2 \left ( \sqrt{s^2 - \dfrac{s^4}{4r^2}} \right ) ^2 + 4r^4s^2} } {  2r^2  }\,$$

$$\Delta x_2 = \dfrac{ -s^2 \left ( \sqrt{s^2 - \dfrac{s^4}{4r^2}} \right ) \pm \sqrt{s^4 \left ( s^2 - \dfrac{s^4}{4r^2} \right ) - r^2s^4 - 4r^2s^2 \left ( s^2 - \dfrac{s^4}{4r^2} \right ) + 4r^4s^2} } {  2r^2  }\,$$

$$\Delta x_2 = \dfrac{ -s^2 \left ( \sqrt{s^2 - \dfrac{s^4}{4r^2}} \right ) \pm \sqrt{s^6 - \dfrac{s^8}{4r^2} - r^2s^4 - 4r^2s^4 + s^6 + 4r^4s^2} } {  2r^2  }\,$$

$$\Delta x_2 = \dfrac{ -s^3 \left ( \sqrt{1 - \dfrac{s^2}{4r^2}} \right ) \pm \sqrt{2s^6 - \dfrac{s^8}{4r^2} - 5r^2s^4 + 4r^4s^2} } {  2r^2  }\,$$

(negative for our purposes)

$$\Delta x_2 = \dfrac{ -s^3 \left ( \sqrt{1 - \dfrac{s^2}{4r^2}} \right ) - \sqrt{2s^6 - \dfrac{s^8}{4r^2} - 5r^2s^4 + 4r^4s^2} } {  2r^2  }\,$$

the other one

$$\Delta y_1 = \dfrac{ -s^2(r) \pm \sqrt{s^4(r)^2 - r^2s^4 - 4r^2s^2(r)^2 + 4r^4s^2} } {  2r^2  }\,$$

$$\Delta y_1 = \dfrac{-rs^2}{2r^2} = \dfrac{-s^2}{2r}\,$$

$$\Delta y_2 = \dfrac{ -s^2 \left (r + \dfrac{-s^2}{2r} \right )  \pm \sqrt{s^4 \left (r + \dfrac{-s^2}{2r} \right )^2 - r^2s^4 - 4r^2s^2 \left (r + \dfrac{-s^2}{2r} \right )^2 + 4r^4s^2} } {  2r^2  }\,$$

$$\Delta y_2 = \dfrac{ -s^2 \left (r - \dfrac{s^2}{2r} \right )  \pm \sqrt{s^4 \left (r^2 - s^2 + \dfrac{s^4}{4r^2} \right ) - r^2s^4 - 4r^2s^2 \left (r^2 - s^2 + \dfrac{s^4}{4r^2} \right ) + 4r^4s^2} } {  2r^2  }\,$$

$$\Delta y_2 = \dfrac{ -rs^2 + \dfrac{s^4}{2r}  \pm \sqrt{r^2s^4 - s^6 + \dfrac{s^8}{4r^2} - r^2s^4 - 4r^4s^2 + 4r^2s^4 - s^6 + 4r^4s^2} } {  2r^2  }\,$$

solving for s

$$(1)s^4 + (4x \Delta x - 4r^2 + 4x^2)s^2 + (4r^2 \Delta x^2) = 0\,$$

$$s^2 = \dfrac{ -(4x \Delta x - 4r^2 + 4x^2) \pm \sqrt{(4x \Delta x - 4r^2 + 4x^2)^2 - 4(1)(4r^2 \Delta x^2)}  } {  2(1)  }\,$$

$$s^2 = -(2x \Delta x - 2r^2 + 2x^2) \pm \sqrt{(2x \Delta x - 2r^2 + 2x^2)^2 - 4r^2 \Delta x^2}\,$$