# Vector confusion

1. Jul 10, 2006

### tony873004

I'm trying to compute Mean Anomoly. Mean Anomoly is an angle that describes where in an orbit an object is relative to its periapsis. The formula according to Wikipedia is

$$M = E - e \cdot \sin E$$
where e is eccentricity (which I know), and E is Eccentric Anomoly.

According to Wikipedia, Eccentric Anomoly is
$$E = \arccos \frac{{1 - \left| r \right|/a}}{e}$$
where a is Semi-Major Axis (which I know), e is eccentricity (which I know), and r is an orbiting body's position vector. If I solve for r, I'm home free.

According to Wikipedia, The orbital position vector r is a cartesian vector describing the position of the orbiting body. Wouldn't that mean that r would be express as something like 1.0i + 2.0j+3.0k? But I can't plug something like that into the formula for Eccentric Anomoly. I could use Pothagorean Theorum to solve for distance and use this number. But that turns the vector into a scalar, and I doubt that's the right way to do it. Direction is pretty important here.

I know the object's x, y, and z position wrt the reference frame. How do I turn r into something I can use in these formulas?

2. Jul 10, 2006

### neutrino

The formula involves only the modulus of the vector r, doesn't it?

3. Jul 10, 2006

### tony873004

Modulus = absolute value??

In my example with 1.0i + 2.0j + 3.0k, I could do r=sqrt(1^2+2^2+3^2). But there are two points on the orbit that would have this same value for r. So I wouldn't know which one I computed.

4. Jul 10, 2006

### neutrino

Yes.

IIRC, you are the author of an orbit simulation program, right? I'm a [exaggeration]novice[/exaggeration] when it comes at programming, so I don't understand the exact nature of your problem. Sorry.

Last edited: Jul 10, 2006
5. Jul 10, 2006

### tony873004

Yes . And if you use the program, you'll notice on the orbital elements box I leave out Mean Anomoly, simply because I don't get it right. I see many references that give the same formulas as Wikipedia for Mean Anomoly. And they all have the variable r in them. r is a vector, not a scalar, which is why I'm confused as to how to turn an x,y,& z position into a single number that I can assign to r that conveys both distance and direction. From physics classes, I remember that any answer that is a vector is stated as a scalar plus either an angle, or with the ijk-hat method. But of course any programming language doesn't want to see hats in the code. And E=Arcos((1-ABS(15, northwest)/a)/(e)) will generate a syntax error.

Thanks for your help thus far

6. Jul 10, 2006

### neutrino

I have used your program before, and had fun generating all those patterns. But to fully appreciate a program such as this, I think I will need a decent understanding of celestial mechancis (I know it's not a necessity, but still I prefer it that way :) ). Keep up the good work, and I hope you get this problem solved.

7. Jul 10, 2006

I could be wrong here, because I have no clue about oribtal mechanics (if that's what it's called )

But, maybe this will help:
So you are trying to calculuate $E$

http://en.wikipedia.org/wiki/Eccentric_anomaly" [Broken]by the following:

$$E = cos^{-1} \frac{1-\frac{| \vec r |}{a}}{e}$$

Looking up the definition of $r$ and $e$ we have:

http://en.wikipedia.org/wiki/Orbital_position_vector" [Broken]:
$\vec r$

Since you are taking the modulus of this, you will return a scaler:
ie) $$| \vec r | = \sqrt{x^2+y^2+z^2}$$

This is the length of the vector. So assuming my geometry is correct (I haven't really worked with ellipses), you will have at least two spots where $$| \vec r |$$ can be equal. For example if the ellipse was on 2d plane.

$$| \vec r_1 | = |\vec r_2 |$$
where:
$$\vec r_1 = (a,0,0)$$
$$\vec r_2 = (-a,0,0)$$

However, you are worried about a point on an ellipse, so you need some more information to make the angle unique (since $\vec r$ by itself is not doing it).

Now if we look at $e$,
"[URL [Broken]
Orbital Eccentricity[/URL] ($e$)

$$e = | \vec e |$$
where:

http://en.wikipedia.org/wiki/Eccentricity_vector" [Broken]($$\vec e$$)

$$\vec e = \frac{\vec v \times \vec h}{\vec \mu}-\frac{\vec r}{| \vec r |}$$
where:
$$\vec v =$$ orbital velocity vector
$$\vec h =$$ orbital angular momentum
$$\vec r =$$ orbital position vector
$$\vec \mu =$$ standard gravitational parameter

It would seem that at the point in question, $\vec v$ would be unique, thus causing $e = | \vec e |$ to be the unique quanitity that is dependent on position.

Like I said, I could be way off here.

EDIT: I don't know what's up with the LaTeX... I guess I have an error somewhere. I hope this is somewhat readable.

Last edited by a moderator: May 2, 2017
8. Jul 10, 2006

### tony873004

The LaTeX is fine. It doesn't work in preview mode though. Thanks. I think I'm getting a grip on it now. Using
$$| \vec r | = \sqrt{x^2+y^2+z^2}$$

I'm getting good results. But I would expect the angle to increase from 0 to 2pi over the course of an orbit. Instead, it increases from 0 to pi and then back to 0. If I subtract this angle from 2pi anytime the object is in the 3rd or 4th quadrant (negative y value), then all is well.

It just seems from the referenced formulas that this type of a piecewise answer is not necessary. But since taking the absolute value of the vector will yield the same answer for two different positions, I guess it is.

One silly mistake I was making was forgetting that the angle is measured from periapsis (closest point) rather than as a longitude (angle from a fixed direction, usually the Vernal equinox). But in a circular orbit, where the only hint of eccentricity comes 5 places to the right of the decimal, this point is not well defined and it drifts all over the place, causing Mean Anomoly to do the same. Once given a little eccentricity, things begin to work a lot better.