Page 1 of 1

Coordinates

Posted: 22.10.2004, 01:41
by Rassilon
Another wonderful math question....Now when I go about plotting a coordinate system in any graphics enviroment its easy when you plot X Y znd Z and find distance between those points using pathagerius...i suppose theres better...now what about plotting points in a radius...say a radius of 100 how would I plot those points? its sort of how would I plot a planet x distance from the sun...It would be easy to say if the planet is 1000 from the sun to make x or z 1000 or y even but in this case y is up and most planets orbit in a plane so y isnt needed in this case...So if I plotted x and z as 1000 my distance would be more than 1000 from the sun because most planets travel in a circle not a square around an object...so...what I am looking for is something like this

X = sin(x) ?
Z = sin(z) ? to give me the correct coordinates? I think Im just not sure which direction to go in this case is all...I suppose if I had the angle and got X and Z from that would be easier...

Any help would be appricated...

Posted: 22.10.2004, 02:24
by Evil Dr Ganymede
Let me see if I've followed you here... do you want to know how to express the location of a planet travelling in a given orbit as x/y/z co-ordinates with the sun at the origin?

Posted: 22.10.2004, 15:48
by Apollonian
If I understand your question right, it sounds like you want either cylindrical or spherical coordinates. The general idea would be to simplify your algorithm using a friendly coordinate system and then converting to cartesian at the end...?

Cylindrical is essentially polar coordinates with the elevation above (or below) the ecliptic added as a third element.

The conversion between cylindrical and cartesian is simply:

x = r * cos(theta)
y = r * sin(theta)
z = z

Where 'r' is the distance from the orbital focus, 'theta' is the "true anomaly" or angular distance around the orbit, and z is the elevation.
This sort of coordinate system is often used in celestial mechanics instead of cartesian to describe orbits.

However, if you are trying to represent an orbit from Keplerian elements there are simple ways to map the Keplerian coordinates (with independent variables of radius and true anomaly) to cartesian coordinates. I'm sure one of us here can help you figure this out if this is what you are doing.

If you want to describe multiple orbits which are inclined with respect to each other, you may want spherical coordinates with an angle representing the angle between the object and the ecliptic instead of 'z'.

More detailed information on these kind of conversions and coordinate systems can be found at the Wolfram Mathworld site:

http://mathworld.wolfram.com/

cylindrical
http://mathworld.wolfram.com/Cylindrica ... nates.html

spherical
http://mathworld.wolfram.com/SphericalCoordinates.html

Posted: 22.10.2004, 19:19
by t00fri
Rassilon wrote:find distance between those points using pathagerius...


Ras',

you must be kidding
:D :lol:

Bye Fridger

Posted: 23.10.2004, 00:58
by Rassilon
Yeah well I didnt look it up to spell it...That much is obvious...

Thanks I think thats what I was looking for...

Posted: 15.11.2004, 14:34
by Rassilon
Well in an attempt to try SPherical Coordinates Ive come to a brick wall...For some odd reason I cannot tilt the orbit any more or less no matter what I put in for inc. The orbit resides on a constant vertical plane...I suppose my sums are wrong...

inline double XcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * sin(anomaly) * sin(inc));}
inline double YcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * cos(anomaly));}
inline double ZcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * sin(anomaly) * cos(inc));}

Any help would be greatly appreciated...

Posted: 15.11.2004, 14:38
by Apollonian
Which "anomaly" are you using? True anomaly?

If so, then you should note that true anomaly is measured positive from the argument of periapse and may not correspond directly to spherical coordinates. In this case, you might try using the angle measure: true_anomaly+arg_of_periapse

Posted: 15.11.2004, 14:47
by symaski62
Apollonian wrote:Which "anomaly" are you using? True anomaly?

If so, then you should note that true anomaly is measured positive from the argument of periapse and may not correspond directly to spherical coordinates. In this case, you might try using the angle measure: true_anomaly+arg_of_periapse


http://en.wikipedia.org/wiki/Anomaly

http://en.wikipedia.org/wiki/True_anomaly


:wink: Apollonian

Posted: 15.11.2004, 15:14
by Rassilon
Its actually just degrees between 0-360 I just call it anomaly....Same with Inclination...The problem I am having is just as soon as I add the inclination to the picture nothing comes out right...I take it out and everything is fine....I now have:

inline double XcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * cos(anomaly) * sin(inc));}
inline double YcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * cos(anomaly));}
inline double ZcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * sin(anomaly) * sin(inc));}

One of my problems was I forgot that one component needs to be 2PI and the other just PI...I figure anomaly is 2PI...

Ok to clarify if in 2D we would use:

x = r * cos(theta)
y = r * sin(theta)
z = z

What would I need to do for 3D? what would z be and what would I add to x and y?

EDIT: I think I am closer with this:

inline double XcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * sin(inc) * cos(anomaly));}
inline double YcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * cos(inc));}
inline double ZcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * sin(inc) * sin(anomaly));}

And where I plot the coordinates:

void setOrbit(int num, double major_axis, double anomaly, double inc, int planet_num = 0) {
planet_pos[num][0] = planet_pos[planet_num][0] + XcoordFromAnomaly(major_axis,(anomaly*PI/180.0), (inc*PI/360.0));
planet_pos[num][1] = planet_pos[planet_num][0] + YcoordFromAnomaly(major_axis,(anomaly*PI/180.0), (inc*PI/360.0));
planet_pos[num][2] = planet_pos[planet_num][2] + ZcoordFromAnomaly(major_axis,(anomaly*PI/180.0), (inc*PI/360.0));
}

I now have a level orbital plane with no inclination...It just raises the orbit along the Y axis instead of tilting it...

Here is a capture:
http://celestialvisions.net/pics/orbits.jpg

Posted: 15.11.2004, 18:30
by Apollonian
Rassilon wrote:inline double XcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * cos(anomaly) * sin(inc));}
inline double YcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * cos(anomaly));}
inline double ZcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * sin(anomaly) * sin(inc));}


Wait a second. I think you have y and z switched. It should be:

inline double XcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * cos(anomaly) * sin(inc));}
inline double YcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * sin(anomaly) * sin(inc));}
inline double ZcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * sin(inc));}

Assuming circular orbits, of course. For elliptical orbits, substitute the following for major_axis:

r = semi_major_axis*(1-e^2)/(1+e*cos(true_anomaly));

where "e" is the eccentricity

Posted: 15.11.2004, 19:16
by Rassilon
Not exactly...My Y in this case is my up vector...X and Z in 2D will allow me to plot the orbit fine...but I will give it a try anyways...

Posted: 15.11.2004, 20:34
by Rassilon
Yeah that didnt work...I got the same as before just facing the Z direction as up instead...

I guess Im just going to have to wing it as nothing on the net or in the forums Ive searched has come close to what I currently have:

inline double XcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * cos(anomaly));}
inline double YcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * cos(inc) * sin(anomaly));}
inline double ZcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * sin(anomaly));}

This gives me an elipse instead of a perfect circle so I am going to have to figure out how to compensate for the depth factor of Y to complete a perfect circle...

http://celestialvisions.net/pics/orbit2.jpg

Posted: 16.11.2004, 00:59
by Spaceman Spiff
Hello Rassilon,

I see you are struggling with the knickers-in-a-twist problem of co-ordinate systems. I've been there, too ;-).

First, from your screen shots, I'm assuming you have a wonderful graphics package where you draw orbits as series of short lines from one X, Y, Z to the next as your variable 'anomaly' increments from 0 to 360??? in small steps? Also, you can set your perspective and viewing angle of the system (hence H 328 V 140)?

If you want your 'ecliptic' to be in the X-Z plane (thus an orbit's plane is inclined to the ecliptic by your variable 'inc', AND you want the orbit to tilt around the X axis, then try these equations:

inline double XcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * cos(anomaly));}
inline double YcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * sin(inc) * sin(anomaly));}
inline double ZcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * cos(inc) * sin(anomaly));}

... and call your 'major_axis' variable 'semi_major_axis' to fit in with general parlance ;-) ).

With this, you can only incline an orbit plane about the X axis, because so far your equations lack the sophistication to account for 'ascending node'. You haven't even started on eccentricity, argument of periwotsit, true anomaly from mean anomaly, or epoch ... If/when you do, the maths gets about 10 times harder...

I could help, but I'm rather busy tomorrow...

Instead, try buying/borrowing this book: "Practical Astronomy with your Calculator", by Peter Duffet-Smith (I mentioned it on the forum some time ago).

By the way, I note you wrote:

Rassilon wrote:
And where I plot the coordinates:

void setOrbit(int num, double major_axis, double anomaly, double inc, int planet_num = 0) {
planet_pos[num][0] = planet_pos[planet_num][0] + XcoordFromAnomaly(major_axis,(anomaly*PI/180.0), (inc*PI/360.0));
planet_pos[num][1] = planet_pos[planet_num][0] + YcoordFromAnomaly(major_axis,(anomaly*PI/180.0), (inc*PI/360.0));
planet_pos[num][2] = planet_pos[planet_num][2] + ZcoordFromAnomaly(major_axis,(anomaly*PI/180.0), (inc*PI/360.0));
}


The bold 0: I think you want a 1 there.

The bold PI/360.0: you convert degrees to radians by multiplying by either pi/180 or 2*pi/360, so you should change that PI/360 to PI/180. Else, you'll be puzzled as to why orbit inclination moves half as much as you asked for...

By the way, I'm convinced your C++ programming is way more advanced than mine, I started an online tutorial, and ran out of time :-).

Spiff.

Posted: 16.11.2004, 01:18
by dms
To make sure the planet is always the same distance from the origin, you need to ensure that x^2 + y^2 + z^2 = r^2


For example:

Rassilon wrote: EDIT: I think I am closer with this:

inline double XcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * sin(inc) * cos(anomaly));}
inline double YcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * cos(inc));}
inline double ZcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * sin(inc) * sin(anomaly));}


x^2 + y^2 + z^2
= (major_axis * sin(inc) * cos(anomaly))^2 + (major_axis * cos(inc))^2 + (major_axis * sin(inc) * sin(anomaly))^2
= major_axis^2 * ( sin^2(inc) * cos^2(anomaly) + cos^2(inc) + sin^2(inc) * sin^2(anomaly) )
= major_axis^2 * ( sin^2(inc) * (cos^2(anomaly) + sin^2(anomaly)) + cos^2(inc) )
= major_axis^2 * ( sin^2(inc) + cos^2(inc) )
= major_axis^2

Posted: 16.11.2004, 03:29
by Rassilon
Spaceman Spiff wrote:Hello Rassilon,

I see you are struggling with the knickers-in-a-twist problem of co-ordinate systems. I've been there, too ;-).

First, from your screen shots, I'm assuming you have a wonderful graphics package where you draw orbits as series of short lines from one X, Y, Z to the next as your variable 'anomaly' increments from 0 to 360° in small steps? Also, you can set your perspective and viewing angle of the system (hence H 328 V 140)?

If you want your 'ecliptic' to be in the X-Z plane (thus an orbit's plane is inclined to the ecliptic by your variable 'inc', AND you want the orbit to tilt around the X axis, then try these equations:

inline double XcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * cos(anomaly));}
inline double YcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * sin(inc) * sin(anomaly));}
inline double ZcoordFromAnomaly(double major_axis, double anomaly, double inc) { return (major_axis * cos(inc) * sin(anomaly));}

... and call your 'major_axis' variable 'semi_major_axis' to fit in with general parlance ;-) ).

With this, you can only incline an orbit plane about the X axis, because so far your equations lack the sophistication to account for 'ascending node'. You haven't even started on eccentricity, argument of periwotsit, true anomaly from mean anomaly, or epoch ... If/when you do, the maths gets about 10 times harder...

I could help, but I'm rather busy driving across Canada tomorrow...

Instead, try buying/borrowing this book: "Practical Astronomy with your Calculator", by Peter Duffet-Smith (I mentioned it on the forum some time ago).

By the way, I note you wrote:

Rassilon wrote:
And where I plot the coordinates:

void setOrbit(int num, double major_axis, double anomaly, double inc, int planet_num = 0) {
planet_pos[num][0] = planet_pos[planet_num][0] + XcoordFromAnomaly(major_axis,(anomaly*PI/180.0), (inc*PI/360.0));
planet_pos[num][1] = planet_pos[planet_num][0] + YcoordFromAnomaly(major_axis,(anomaly*PI/180.0), (inc*PI/360.0));
planet_pos[num][2] = planet_pos[planet_num][2] + ZcoordFromAnomaly(major_axis,(anomaly*PI/180.0), (inc*PI/360.0));
}

The bold 0: I think you want a 1 there.

The bold PI/360.0: you convert degrees to radians by multiplying by either pi/180 or 2*pi/360, so you should change that PI/360 to PI/180. Else, you'll be puzzled as to why orbit inclination moves half as much as you asked for...

By the way, I'm convinced your C++ programming is way more advanced than mine, I started an online tutorial, and ran out of time :-).

Spiff.


Absolutely brilliant....Cheers!

It works perfectly...I will probably add 'ascending node' eccentricity, and epoch ... later maybe in a later version...This is already more real than 90% of your space sims but is again just a game/simulator so it will have some of the realism of Celestia...but Chris is by far a superior C programmer than I...I have a long (one single galaxy in length) before I reach the level of Celestia....By then I suppose I will be a programming/OpenGL god...probably a tad better than Zeus but not quite as burly as Hercules and not quite as hairy :P

Posted: 16.11.2004, 05:20
by Spaceman Spiff
Hi Rassilon,

Rassilon wrote:Absolutely brilliant....Cheers!

Oh goody...!

Rassilon wrote:It works perfectly...I will probably add 'ascending node' eccentricity, and epoch ... later maybe in a later version.


I may have time to help later, but can't promise... You'll need a 3D rotation matrix in the maths. Check that book out.

Spiff.