Look at picture below :
Q: I wonder what's the equation to find $L$ (the red line on {x',y'}, which x' will always be $0$), assuming if you don't know about the ellipse size.
Btw, I want to use the equation to programatically move the red line, on Y axis (bot->top), while also updating it's length ($L$) to match the ellipse on current Y position. Unfortunately, I'm not a math guy, so... Hahaha.
Thank you very much!

We assume that the ellipse is placed symmetrically about the $x$-axis. We can without loss of generality assume that it is also symmetrical about the $y$-axis. Then the equation of the ellipse is $$\frac{x^2}{r^2}+\frac{y^2}{R^2}=1.$$ It follows that at height $y$ above the $x$-axis, we have $$L=2r\sqrt{1-\frac{y^2}{R^2}}.$$ You may prefer the equivalent $$L=\frac{2r}{R}\sqrt{R^2-y^2}.$$