Artificial intelligent assistant

Divide a circle horizontally I'm in the midst of programming, and I'd like to know if this is possible. _Given a circle which we know three facts:_ 1. _The center point;_ 2. _The radius; and_ 3. _The Y coordinate of a line parallel to the X axis,_ _find the two X coordinates where the circle crosses said line._ I've attempted to mess about with the circle's equation, # $(x-h)²+(y-k)²=r²$ with the Circle center being $(h,k)$ and the radius $r$. In short, I'm dividing a circle horizontally. My attempts to get a functional formula (e.g. $x=fancyPants$) seem to be failing. I cannot math good. Is this possible or am I unwittingly jumping into ridiculously complex math that will blow up the program with trial and error? If possible, I would like a formula for an ellipsis as well. Cheers

Let the circle's center have coordinates $(h, k)$ and radius $r$. Then the points with $y$-coordinate $y_0$ (if there are any) have $x$-coordinates that satisfy the equation

$$ (x-h)^2 + (y_0-k)^2 = r^2 $$

The only unknown here is $x$, so we write

$$ (x-h)^2 = r^2-(y_0-k)^2 $$

and then

$$ x-h = \pm \sqrt{r^2-(y_0-k)^2} $$

Finally, we add $h$ to both sides to get

$$ x = h \pm \sqrt{r^2-(y_0-k)^2} $$

This will yield two (real) solutions when $r > |y_0-k|$, one solution when $r = |y_0-k|$, and no (real) solutions when $r < |y_0-k|$, where $|z|$ is the absolute value of $z$.

Pseudocode is


if (r < fabs(y0-k))
return {NaN};
else if (r == fabs(y_0-k))
return {h};
else {
d = sqrt(r^2-(y0-k)^2);
return {h-d, h+d};
}

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 938598a1fd0c1dc191f29a18cd28a6b7