Coordinates

The place to discuss creating, porting and modifying Celestia's source code.
Topic author
Rassilon
Posts: 1887
Joined: 29.01.2002
With us: 22 years 9 months
Location: Altair

Coordinates

Post #1by Rassilon » 22.10.2004, 01:41

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...
I'm trying to teach the cavemen how to play scrabble, its uphill work. The only word they know is Uhh and they dont know how to spell it!

Evil Dr Ganymede
Posts: 1386
Joined: 06.06.2003
With us: 21 years 5 months

Post #2by Evil Dr Ganymede » 22.10.2004, 02:24

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?

Apollonian
Posts: 52
Joined: 19.10.2004
With us: 20 years 1 month

Post #3by Apollonian » 22.10.2004, 15:48

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

Avatar
t00fri
Developer
Posts: 8772
Joined: 29.03.2002
Age: 22
With us: 22 years 7 months
Location: Hamburg, Germany

Post #4by t00fri » 22.10.2004, 19:19

Rassilon wrote:find distance between those points using pathagerius...


Ras',

you must be kidding
:D :lol:

Bye Fridger

Topic author
Rassilon
Posts: 1887
Joined: 29.01.2002
With us: 22 years 9 months
Location: Altair

Post #5by Rassilon » 23.10.2004, 00:58

Yeah well I didnt look it up to spell it...That much is obvious...

Thanks I think thats what I was looking for...
I'm trying to teach the cavemen how to play scrabble, its uphill work. The only word they know is Uhh and they dont know how to spell it!

Topic author
Rassilon
Posts: 1887
Joined: 29.01.2002
With us: 22 years 9 months
Location: Altair

Post #6by Rassilon » 15.11.2004, 14:34

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...
I'm trying to teach the cavemen how to play scrabble, its uphill work. The only word they know is Uhh and they dont know how to spell it!

Apollonian
Posts: 52
Joined: 19.10.2004
With us: 20 years 1 month

Post #7by Apollonian » 15.11.2004, 14:38

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

symaski62
Posts: 610
Joined: 01.05.2004
Age: 41
With us: 20 years 6 months
Location: france, divion

Post #8by symaski62 » 15.11.2004, 14:47

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
windows 10 directX 12 version
celestia 1.7.0 64 bits
with a general handicap of 80% and it makes much d' efforts for the community and s' expimer, thank you d' to be understanding.

Topic author
Rassilon
Posts: 1887
Joined: 29.01.2002
With us: 22 years 9 months
Location: Altair

Post #9by Rassilon » 15.11.2004, 15:14

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
I'm trying to teach the cavemen how to play scrabble, its uphill work. The only word they know is Uhh and they dont know how to spell it!

Apollonian
Posts: 52
Joined: 19.10.2004
With us: 20 years 1 month

Post #10by Apollonian » 15.11.2004, 18:30

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

Topic author
Rassilon
Posts: 1887
Joined: 29.01.2002
With us: 22 years 9 months
Location: Altair

Post #11by Rassilon » 15.11.2004, 19:16

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...
I'm trying to teach the cavemen how to play scrabble, its uphill work. The only word they know is Uhh and they dont know how to spell it!

Topic author
Rassilon
Posts: 1887
Joined: 29.01.2002
With us: 22 years 9 months
Location: Altair

Post #12by Rassilon » 15.11.2004, 20:34

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
I'm trying to teach the cavemen how to play scrabble, its uphill work. The only word they know is Uhh and they dont know how to spell it!

Spaceman Spiff
Posts: 420
Joined: 21.02.2002
With us: 22 years 9 months
Location: Darmstadt, Germany.

Post #13by Spaceman Spiff » 16.11.2004, 00:59

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.
Last edited by Spaceman Spiff on 21.01.2005, 17:03, edited 1 time in total.

dms

Post #14by dms » 16.11.2004, 01:18

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

Topic author
Rassilon
Posts: 1887
Joined: 29.01.2002
With us: 22 years 9 months
Location: Altair

Post #15by Rassilon » 16.11.2004, 03:29

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
I'm trying to teach the cavemen how to play scrabble, its uphill work. The only word they know is Uhh and they dont know how to spell it!

Spaceman Spiff
Posts: 420
Joined: 21.02.2002
With us: 22 years 9 months
Location: Darmstadt, Germany.

Post #16by Spaceman Spiff » 16.11.2004, 05:20

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.


Return to “Development”