# How do I calculate $t$ in the general parametric equation of an ellipse when the point $(x,y)$ is known?

I have the general parametric equation of an ellipse.

\begin{align*}x&=c_x+a\cos{t}\cos{\alpha}-b\sin{t}\sin{\alpha} \\ y&=c_y+a\cos{t}\sin{\alpha}+b\sin{t}\cos{\alpha}\end{align*}

I need to find the value of $t$ when $x$ and $y$ are known. I tried solving the equation and ended up with

$$t = \arccos{\frac{(x-c_x)\cos{\alpha} + (y-c_y)\sin{\alpha}}{a}}$$

The first thing that bothers me about this equation is that it doesn't depend on $b$. The major issue is, it seems that the value of $t$ I get is more and more inaccurate with increasing $\alpha$.

-
I presume you want your $t$ to be within $[0,2\pi)$? –  Ｊ. Ｍ. Jul 29 '11 at 4:14
If the coordinates of the given point are known, undo the translation and rotation (in that order!) on the given point, and then you should be able to use something like the two-argument arctangent to determine $t$... –  Ｊ. Ｍ. Jul 29 '11 at 4:15
No reason to worry about lack of $b$. But I suggest you also do same sort of thing except eliminate $a$. Then you know $\cos t$ and $\sin t$. Careful about $\tan$, it doesn't distinguish between first quadrant and third, or second and fourth. Don't know about "inaccurate." Could be programming slip, or numerical instabilities. First is more likely than second, except when $t$ is near $0$. Near $0$, $\cos$ is very insensitive. –  André Nicolas Jul 29 '11 at 4:55
But the "two variable" $\arctan$ is OK, it pays attention to the two signs, not just their ratio. Undoing the rotation, as suggested by @J.M. is geometrically nicer, but from the point of view of arithmetic is not much different. Also be careful about $\arccos$, it doesn't distinguish between first and second quadrant, or third and fourth, so your formula is not correct, though you are very close. –  André Nicolas Jul 29 '11 at 5:13
@AppleGrew: Not exactly. Derive an equation for $\sin t$, by eliminating the part with $a$, same technique that got you $\cos t$. Now you know $\cos t$ and $\sin t$, and can use two variable $\arctan$, or just use $\arcsin$ or $\arccos$, but then adjust the quadrant of $t$ since you know the sign of both $\cos t$ and $\sin t$. Numerically, be careful when $\cos t$ is near $1$, there $\sin$ is more reliable. If you are working to double precision, there should be no problem whatever you do. –  André Nicolas Jul 29 '11 at 6:11

You are almost there. Eliminating the $b$-terms (by multiplying the first of the given equations with $\cos\alpha$, the second with $\sin\alpha$) you got the first of the following two equations; eliminating in the same way the $a$-terms you get the second: \eqalign{ (x-c_x)\cos\alpha +(y-c_y)\sin\alpha&=a\cos t\ , \cr -(x-c_x)\sin\alpha+(y-c_y)\cos\alpha&=b\sin t\ .\cr} As $\ t=\arg(\cos t,\sin t)$ (mod $2\pi$) we obtain $$t\ =\ \arg\Bigl({(x-c_x)\cos\alpha +(y-c_y)\sin\alpha\over a}\ ,\ {-(x-c_x)\sin\alpha+(y-c_y)\cos\alpha \over b}\Bigr)\ .$$
Can you please convert that to some other form, as Javascript has no $\arg{}$ function. Wikipedia says that it can be converted to $\arctan{}$ form, not sure how. Further more it seems $\arctan{}$ cannot handle scenarios where $x<0$ and $y=0$ –  AppleGrew Jul 29 '11 at 9:05
I don't know about Javascript, but I know that many "scientific" pocket calculators have the function "to polar" whose second output variable is arg (= "the polar angle" of $(x,y)$). If you don't believe in arg you have to distinguish cases: Whenever $(x,y)\ne(0,0)$ at least one of $x$, $y$, $-x$, $-y$ is positive. Depending on the case you will have to take the $\arctan$ of $y/x$ or $x/y$ and add suitable multiples of $\pi/2$. –  Christian Blatter Jul 29 '11 at 11:27
@AppleGrew: I don't know Javascript either. But you can presumably branch. For example use $\arccos$ if $\sin t \ge 0$ and $2\pi-\arccos$ if $\sin t <0$. –  André Nicolas Jul 29 '11 at 11:42
@AppleGrew: As already mentioned by André and me, you can use the two-argument arctangent which is essentially the same as Christian's $\arg(\cdot)$; note that JS's (and most other language's) argument convention for atan2() is the reverse; i.e. in JS, ordinate first and abscissa last. –  Ｊ. Ｍ. Jul 30 '11 at 2:38
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 1, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.9267921447753906, "perplexity": 393.7693495683128}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2014-52/segments/1418802770829.36/warc/CC-MAIN-20141217075250-00051-ip-10-231-17-201.ec2.internal.warc.gz"}