Inclination of an Ellipse's Major Axis ... in Three Dimensions?Date: 01/11/2011 at 14:58:41 From: Rui Subject: Ellipse given n minimum points and knowing one of the focus Dear Sir, I want to build an ellipse given the minimum n points, and knowing that one of the foci has the coordinates (0,0). The other one can be elsewhere. My questions are: 1) How many points are needed? Uniquely determining an ellipse requires a minimum of five points. But in this case, I know one of the foci. 2) How do I calculate the formula of that ellipse? Is the polar form a better way? 3) How do I calculate the inclination of the major axis regarding the x-axis? This is the goal. So far, I'm a little confused because the ellipse must be unique and has an inclination regarding the x-axis. Please give me the complete solutions, if possible. Kind regards, and thanks, Rui Miguel Fernandes P.S. I would like to add that this question is, in fact, an astronomy question. By solving it, you'll be helping a very useful project: the public DLL of our website! Date: 01/11/2011 at 16:16:53 From: Doctor George Subject: Re: Ellipse given n minimum points and knowing one of the focus Hello Rui, Thanks for writing to Doctor Math. This problem is not at all simple to solve in closed form, as you have found. It would be difficult to even write the closed form solution in plain text. Since you are writing a computer program, can we instead develop a procedure that you can turn into code? I think I could walk you through it that way. - Doctor George, The Math Forum http://mathforum.org/dr.math/ Date: 01/11/2011 at 17:17:22 From: Rui Subject: Ellipse given n minimum points and knowing one of the focus Dear Sir, Thank you very much for your reply. Yes, a piece of C/C++ code would be perfect. I would adapt it to the DLL, which is based in the same language. Thank you very much for your time and kindness. Kind regards, Rui Miguel Fernandes Date: 01/11/2011 at 22:10:42 From: Doctor George Subject: Re: Ellipse given n minimum points and knowing one of the focus Dear Rui, There is a lot to do. I assume that you already know quite a bit about ellipses, so I will focus on the main flow of the development. If you need me to fill in details, please let me know where you need more input. Let's call the other focus (xf, yf) and the major axis length 2a. From the definition of an ellipse, a point (x,y) is on the ellipse if it satisfies the following equation: sqrt(x^2 + y^2) + sqrt[(x - xf)^2 + (y - yf)^2] = 2a (1) There are 3 unknowns in the equation: (xf,yf,a). To find the unknowns, we need three (x,y) points to give us a system of three equations to solve. For clarity, I will use "a" in quotes where needed. But first, let's rearrange the equation by moving the first radical to the right hand side, and then square both sides. (x - xf)^2 + (y - yf)^2 = [2a - sqrt(x^2 + y^2)]^2 (2) Do you see that we can think of this equation as a circle centered at (x,y) with "a" constant? Each possible (xf,yf) is a point on the circle. Now substitute (x,y) in (2) with (x1,y1), (x2,y2), and (x3,y3) to create three circles that form the system of equations to solve. Let's call these equations 2.1, 2.2, and 2.3. For the correct value of "a," the three circles will intersect at a common point. Now do this: 1. Expand the squares on both sides of 2.1 and 2.2. 2. Subtract each side of 2.2 from 2.1. 3. Simplify. The result should look like this: (x2 - x1)xf + (y2 - y1)yf = 2a[sqrt(x1^2 + y1^2) - sqrt(x2^2 + y2^2)] (3.1) If we do the same with 2.1 and 2.3, we get the following: (x3 - x1)xf + (y3 - y1)yf = 2a[sqrt(x1^2 + y1^2) - sqrt(x3^2 + y3^2)] (3.2) Equations 3.1 and 3.2 are a linear system that can be solved for xf and yf in terms of "a." The intersections of the first two circles must be on 3.1, and the intersections of the first and third circles must be on 3.2. The intersection of these lines will be the intersection of all three circles. Think of the result like this, using c1, c2, c3 and c4 as constants: xf = c1 + c2*a (4.1) yf = c3 + c4*a (4.2) Now substitute these expressions for xf and yf back into the expanded form of 2.1. The result is an equation that can be solved to find "a." (I expect that the equation will be quadratic, and the root of interest will be positive.) Geometrically, we are finding the value of "a" so that the 3 circles share a common point. Once we have the value of "a," we get (xf,yf) from 4.1 and 4.2. We now know everything about the ellipse. The rotation angle will be found from tan(angle) = yf/xf The only remaining issue is how else you may need to express the information in your application. Does this make sense? Let me know where I can be of more help. - Doctor George, The Math Forum http://mathforum.org/dr.math/ Date: 01/12/2011 at 04:51:01 From: Rui Subject: Ellipse given n minimum points and knowing one of the focus Dear Sir, Thank you very much for your time. In my opinion, what you show makes perfect sense. No more inputs and outputs are needed. What I would like to ask -- if in reason -- is if it's possible for you to provide the C code. That would decrease the chance of errors. I've read your reply 3 times, and the method seems perfect to me. Kind regards, Rui Miguel Fernandes Date: 01/12/2011 at 15:50:12 From: Doctor George Subject: Re: Ellipse given n minimum points and knowing one of the focus Dear Rui, I write for Ask Dr. Math as a volunteer, so I have to squeeze things like this in around my regular employment. Having the code for you by the end of this week seems reasonable. If it is urgent, please let me know. - Doctor George, The Math Forum http://mathforum.org/dr.math/ Date: 01/12/2011 at 15:58:02 From: Rui Subject: Ellipse given n minimum points and knowing one of the focus Dear Sir, What you are doing is already fantastic and extraordinarily generous. Take the time you need; I don't dare to ask for more. Thank you very much for your kindness. I would like to ask -- only if you want -- your full name to place in the "thanks" page of Cosmos as an important contributor. Kind regards, Rui Miguel Fernandes Date: 01/13/2011 at 21:32:12 From: Doctor George Subject: Re: Ellipse given n minimum points and knowing one of the focus Dear Rui, There are two small additions to make to the problem analysis. First, equations 4.1 and 4.2 can be written more simply. xf = c1*a (4.1) yf = c2*a (4.2) Second, when we substitute these expression for xf and yf back into the expanded form of 2.1, we do indeed get a quadratic equation in "a." The form of the quadratic is d1*a^2 + d2*a = 0 One of the roots is zero. This is a spurious root that was created by squaring equation 2. The other root is the value that we want. I will be sending you code that computes the solution in another message. I am glad that this is helpful to you. - Doctor George, The Math Forum http://mathforum.org/dr.math/ Date: 01/14/2011 at 06:14:12 From: Rui Subject: Ellipse given n minimum points and knowing one of the focus Dear Sir, Thank you very much for your help. I would like to ask, if possible, one last question: if the points are in a 3 dimensional plane and the focus is at (0,0,0), what should I do? Project only the x and y values into the x-y plane? That would get the inclination of the major axis regarding the x-y plane. Or must I project one by one according to its z-value through the x-axis? The plane intercepts the x-y plane at the line y = mx, which I've already calculated. Kind regards, Rui Miguel Fernandes Date: 01/14/2011 at 09:52:32 From: Rui Subject: Ellipse given n minimum points and knowing one of the focus Dear Sir, I think I might have made a terrible mistake in not generalizing my first question to three dimensions. The transformations in my last note cause big problems with the calculations. I ask for your advice and counseling. And I really hope that the solution isn't the 3D generalization -- although I'm convinced that it is; in this case, I'm very sorry. The 2D solution is used in most of the cases; but in this case, I'm afraid that the 3D might be needed. I'll wait for your advice. Kind regards, Rui Miguel Fernandes Date: 01/14/2011 at 10:26:38 From: Doctor George Subject: Re: Ellipse given n minimum points and knowing one of the focus Dear Rui, There is a potential complication in 3D. If there is measurement error, then the 3 points and the origin may not be in a common plane. If that is the case, then a best fit plane may be needed. But let's ignore this issue for now. The projection of the major axis into the x-y plane is not in general the major axis of the projected ellipse. To see this, take an ellipse in standard position and tip it close to 90 degrees about the minor axis. The major axis of the projected ellipse is the minor axis of the original ellipse. I am assuming that what you need is the projection of the major axis into the x-y plane. A good solution is to set up a secondary u-v-w coordinate system with the origin still at (0,0,0) such that the u-v plane contains the ellipse. The choice of u is not unique. Here is one way to define the new coordinate system, with X representing the cross product: u = (x1,y1,z1) - (0,0,0) / sqrt(x1*x1 + y1*y1 + z1*z1) v = (w X u) / |w X u| w = unit normal vector of the plane in x-y-z coordinates Each point P from the x-y-z system has these coordinates in the u-v system. (P.u, P.v) (To avoid confusion, let's switch to using . rather than * for the dot product.) Now find the other focus in the u-v plane as in the 2D problem. Let's call it (uf,vf). We get that focus in x-y-z coordinates, F, as follows: F = uf*u + vf*v To get the projection into the x-y plane, just ignore the z coordinate. Finally, get the x-y inclination angle from the projection of F. Is this what you are looking for? - Doctor George, The Math Forum http://mathforum.org/dr.math/ Date: 01/14/2011 at 10:57:38 From: Rui Subject: Ellipse given n minimum points and knowing one of the focus Dear Sir, Ultimately, I think that is what I'm looking for. But to be sincere, I don't understand how to do it -- I'm very sorry. And I've lost the value of "a." The main thing is to know the projection of the second focus in the x-y plane -- that's for sure. Is this a better way than the 3D generalization? I'm terribly sorry to bother you again. Kind regards, Rui Miguel Fernandes Date: 01/14/2011 at 16:10:45 From: Doctor George Subject: Re: Ellipse given n minimum points and knowing one of the focus Dear Rui, The 3D ellipse and the projected ellipse will in general have different major semi-axis lengths. I think that is what you are saying. But we can compute them both. I will send you code to find the focus and major semi-axis length for 3D data. - Doctor George, The Math Forum http://mathforum.org/dr.math/ Date: 01/17/2011 at 07:12:58 From: Rui Subject: Ellipse given n minimum points and knowing one of the focus Dear Sir, Thank you very much for your trouble. I'm very sorry to have bother you again, but I have a question regarding the code. How do you compute (wx, wy, wz)? Are they the components of the plane Ax + By + Cz = 0 of the ellipse determined by the following equations? wx = A/sqrt(A*A + B*B + C*C) wy = B/sqrt(A*A + B*B + C*C) wz = C/sqrt(A*A + B*B + C*C) Kind regards, Rui Miguel Fernandes Date: 01/18/2011 at 08:19:00 From: Doctor George Subject: Re: Ellipse given n minimum points and knowing one of the focus Dear Rui, That is correct. The vector should be normalized as you have done. Write again if you need more help. - Doctor George, The Math Forum http://mathforum.org/dr.math/ Date: 01/20/2011 at 12:09:07 From: Rui Subject: Ellipse given n minimum points and knowing one of the focus Dear Sir, I would like to ask you one more clarification, if I may. The rotation around the x, y, or z axes is given by simple formulas. But I've searched the Internet and found different formulas -- which led me to different results. For example: z-axis rotation x' = x*cos q - y*sin q y' = x*sin q + y*cos q z' = z x-axis rotation y' = y*cos q - z*sin q z' = y*sin q + z*cos q x' = x y-axis rotation z' = z*cos q - x*sin q x' = z*sin q + x*cos q y' = y Can you please tell me the correct formulas, if possible? It's connected with the same problem, which is almost solved. Kind regards, Rui Miguel Fernandes Date: 01/21/2011 at 09:02:14 From: Doctor George Subject: Re: Ellipse given n minimum points and knowing one of the focus Dear Rui, There is no unique method for performing rotations. There are simply different conventions for the order of rotations and which direction is considered a positive angle. Take a look at these articles. http://mathworld.wolfram.com/EulerAngles.html http://en.wikipedia.org/wiki/Euler_angles In the test case that I sent, it only mattered that I used the same method when rotating the two ellipse points, the focus, and the unit normal vector. I could have used any rotation convention to produce a useful test. Now if you have input angles that have been defined with a particular convention, then that convention must be applied to get the correct final orientation. Does that help? Please send additional details if you need more explanation. - Doctor George, The Math Forum http://mathforum.org/dr.math/ Date: 01/21/2011 at 12:53:56 From: Rui Subject: Ellipse given n minimum points and knowing one of the focus Dear Sir, Yes, that helps. Thank you. Actually the problem is this: the previous routine solved a major problem that must be tested now. I don't know if you're familiar with the elements of an elliptic orbit. But I've got the position of one point, the focus (0,0,0), the semi-axis "a," the longitude of the ascending node, the inclination of the orbit, and the longitude of the perigee measured within the plane -- not the one measured in the x-y plane. What I need to find is this last value, that is, the longitude of the perigee in the x-y plane. If I add this longitude to the ascending node, I won't get a real value, since the longitude of the perigee is in the orbit plane. The inclination isn't necessarily perpendicular to the longitude of the ascending node also. Do you have any ideas? Kind regards, Rui Miguel Fernandes Date: 01/21/2011 at 22:29:50 From: Rui Subject: Ellipse given n minimum points and knowing one of the focus Dear Sir, To simplify things, I just need to know how to rotate a plane ax + bx + cx = 0 over the Z axis; rotating (a,b,c) as if it was a point is the right thing? Or is this method the correct one? http://www.physicsforums.com/showthread.php?t=389373 a' = a cos(alpha) - b sin(alpha) b' = a sin(alpha) + b cos(alpha) c' = c Kind regards, Rui Miguel Fernandes Date: 01/22/2011 at 05:41:49 From: Rui Subject: Ellipse given n minimum points and knowing one of the focus Dear Sir, I've wrote a piece of JavaScript to test my values, but something is wrong. Here's the code: // argument of perigee in xy axis aop = 246.9845807; // argument of perigee ai = 5.2855334; // inclination of orbit lan = 261.5156997; // longitude of ascending node aop = aop * DEG_TO_RAD; ai = ai * DEG_TO_RAD; lan = lan * DEG_TO_RAD; // create a plane that passes through the point (x,y,z) and the node // and the center (0,0,0), and rotate it by the lan ax = x; ay = y; az = z; bx = 400000 * Math.cos(lan); by = 400000 * Math.sin(lan); bz = 0; if (az != 0){ a = ay*bz-az*by; b = az*bx-ax*bz; c = ax*by-ay*bx; alpha = -lan; al = a * Math.cos(alpha) - b * Math.sin(alpha); bl = a * Math.sin(alpha) + b * Math.cos(alpha); cl = c; // calculate a point with the aop angle and rotate by the true inclination x = Math.cos(aop); y = Math.sin(aop); z = -(al * x + bl * y) / cl; inc = Math.atan(z/y); q = inc; yl = y*Math.cos(q) + z*Math.sin(q); zl = z*Math.cos(q) - y*Math.sin(q); xl = x; angle = Math.atan2(xl,yl) * RAD_TO_DEG; if (angle<0){ angle += 360.0;} angle = angle + lan * RAD_TO_DEG; if (angle>360){ angle -= 360.0;} document.form.argumento_perielio_xy.value = Math.floor (angle*1000000)/1000000; } else { document.form.argumento_perielio_xy.value = "---"; } What do you think might be wrong? Sorry to bother you. Kind regards, Rui Miguel Fernandes Date: 01/22/2011 at 09:02:30 From: Rui Subject: Ellipse given n minimum points and knowing one of the focus Hi, I think the first correction is that: x = Math.cos(aop); y = Math.sin(aop) * Math.cos(ai); //z = -(al * x + bl * y) / cl; z = Math.sin(aop) * Math.sin(ai); Something's wrong with the rotation of the angles and planes -- I think ... Kind regards, Rui Miguel Fernandes Date: 01/22/2011 at 10:04:38 From: Rui Subject: Ellipse given n minimum points and knowing one of the focus Hi, I think I've got it... // argument of perigee in xy axis aop = 246.9845807; ai = 5.2855334; lan = 261.5156997; aop = aop * DEG_TO_RAD; ai = ai * DEG_TO_RAD; lan = lan * DEG_TO_RAD; if (z != 0){ x = Math.cos(aop); y = Math.sin(aop) * Math.cos(ai); z = Math.sin(aop) * Math.sin(ai); angle = Math.atan2(y,x) * RAD_TO_DEG; if (angle<0){ angle += 360.0;} angle = angle + lan * RAD_TO_DEG; if (angle>360){ angle -= 360.0;} document.form.argumento_perielio_xy.value = Math.floor (angle*1000000)/1000000; } else { document.form.argumento_perielio_xy.value = "---"; } I was trying to make useless rotations. And atan2 in Javascript works the other way around. What do you think? Sorry to bother you. Kind regards, Rui Miguel Fernandes Date: 01/23/2011 at 15:18:14 From: Doctor George Subject: Re: Ellipse given n minimum points and knowing one of the focus Hi Rui, It sounds like you are making progress. You are correct that some of this terminology is outside of my knowledge base. I would need some precise definitions, and maybe some pictures to translate the terms to pure math. Going back through your updates: 1. Your rotation about the z axis looks right. 2. I wrote my test code using separate rotations for each axis without matrices, but using rotation matrices could make the code much more compact. 3. Rotating a vector that has an endpoint at the origin is the same as rotating a point. 4. There is variation among programs in the atan2 arguments, so you are probably right on that one. What is your status now? Do you think you have everything? If you need more help, I would refer you to one of the other math doctors, who has expertise in celestial geometry. - Doctor George, The Math Forum http://mathforum.org/dr.math/ Date: 01/24/2011 at 05:05:25 From: Rui Subject: Ellipse given n minimum points and knowing one of the focus Hi, The results are consistent to others -- but our method has failed, as it's an approximation. Maybe you could ask your friend if there's a way of calculating the longitude of the perigee given 3 points and the focus (0,0,0), knowing the ascending node and inclination of the orbit, but NOT knowing the velocities? Once again, thank you very much for your help and kindness. You're one of the best contributors Cosmos has ever had -- and I hope you continue that way, if you want. Kind regards, Rui Date: 01/24/2011 at 08:30:56 From: Doctor George Subject: Re: Ellipse given n minimum points and knowing one of the focus Hi Rui, The best way for you to get help from another math doctor would be to frame your question as a new submission to Dr. Math. If you make the subject "Celestial Geometry," I will look for it and mark it for a math doctor who knows this subject. He is the busiest of the math doctors, but I am hopeful that he can at least point you in the right direction. I too have an interest in astronomy, but have not had the opportunity to study it formally. It has been fun to help. - Doctor George, The Math Forum http://mathforum.org/dr.math/ Date: 01/24/2011 at 13:30:59 From: Rui Subject: Ellipse given n minimum points and knowing one of the focus Hi, Thank you very much for your help. I have the feeling we'll be in touch again soon -- if you're available and if you want, of course. Any ideas of math applications for our website are welcome!!! I submitted a new question, as you suggested, named "Celestial Geometry." I've already shared my ideas; I hope your friend can give me some of his. Kind regards, Rui Miguel Fernandes |
Search the Dr. Math Library: |
[Privacy Policy] [Terms of Use]
Ask Dr. Math^{TM}
© 1994- The Math Forum at NCTM. All rights reserved.
http://mathforum.org/dr.math/