Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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.

share|improve this question
    
I presume you want your $t$ to be within $[0,2\pi)$? –  J. M. Jul 29 '11 at 4:14
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$... –  J. M. 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
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. –  André Nicolas Jul 29 '11 at 5:13
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. –  André Nicolas Jul 29 '11 at 6:11

1 Answer 1

up vote 3 down vote accepted

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

share|improve this answer
    
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
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$. –  André Nicolas Jul 29 '11 at 11:42
    
@André I will try your tip. –  AppleGrew Jul 29 '11 at 13:01
    
@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. –  J. M. Jul 30 '11 at 2:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.