0
$\begingroup$

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$.

Please check the demo here.

  • 0
    I presume you want your $t$ to be within $[0,2\pi)$?2011-07-29
  • 1
    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$...2011-07-29
  • 0
    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.2011-07-29
  • 1
    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.2011-07-29
  • 0
    @J.M. Yes I need the value in $\[0, 2\pi\)$ range.2011-07-29
  • 0
    @André Do you suggest I derive another equation which has only $b$ then adding them to get the final $t$?2011-07-29
  • 0
    In that case, either @André's or my suggestions should help a great deal. (I'll write an answer unless André beats me to it if you get stuck.)2011-07-29
  • 1
    @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.2011-07-29
  • 0
    @J.M.: Please go ahead. I will produce an answer only if no one else seems to be doing it.2011-07-29

1 Answers 1

3

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)\ .$$

  • 0
    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$2011-07-29
  • 0
    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$.2011-07-29
  • 1
    @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$.2011-07-29
  • 0
    @André I will try your tip.2011-07-29
  • 0
    @AppleGrew: As already mentioned by André and me, you can use the [two-argument arctangent](http://www.w3schools.com/jsref/jsref_atan.asp) 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.2011-07-30
  • 0
    Well it seems André's above tip works best in my case.2011-07-30