Jump to content

Will the real longitude please stand up.


Recommended Posts

Both are right (and represent the same value). If you want it all to be in the [0, 360] range, do x % 360. If you want it in the [-180, 180] range do (x % 360) - 180.

The KSP APIs aren't necessarily consistent - if I remember correctly you can sometimes see stuff outside those ranges as well.

Link to comment
Share on other sites

Both are right (and represent the same value). If you want it all to be in the [0, 360] range, do x % 360. If you want it in the [-180, 180] range do (x % 360) - 180.

The KSP APIs aren't necessarily consistent - if I remember correctly you can sometimes see stuff outside those ranges as well.

Thank you! I now know what the modulus operator in C# is.

But would it not be

Math.Round(((FlightGlobals.ActiveVessel.longitude) % 180) - 180, 2) = -74

instead of

Math.Round(((FlightGlobals.ActiveVessel.longitude) % 360) - 180, 2) = 105

- - - Updated - - -

Well they add up to 360 (with a one degree difference due to rounding errors, one would assume). Unless I'm missing something -75 and +285 are the same position, just different ways of expressing it.

EDIT: Ninja'd!

They are but it seems most prefer the -180 to 180 longitude (kerbalmaps, hyperedit) so I'm just trying to be 'compatible' with everyone else. Unfortunately, it means when I use something like kerbalmaps to enter a long, I'll have to convert it back to the 360 degree method in order to do calculations on it.

Link to comment
Share on other sites

I think for the -180°â€â€+180° range you want ((x + 180) % 360) - 180

But I'm too lazy to test in code. And pre-emptively if you're using any atan calculations in your code, check out atan2.

Now that I'm on the right track, I'll do some testing to find out. For now I don't think I'll be doing much trig but not positive. Basically, I'm trying to get the distance and angle from the vessel to 3 different longitudes and latitudes that are in the -180 to 180 format.

But thanks for the quick answers.

Edit:

You are correct. It is x + 180) % 360) - 180.

Edited by Fengist
Link to comment
Share on other sites

Now that I'm on the right track, I'll do some testing to find out. For now I don't think I'll be doing much trig but not positive. Basically, I'm trying to get the distance and angle from the vessel to 3 different longitudes and latitudes that are in the -180 to 180 format.

But thanks for the quick answers.

Yup indeed - I did that last one without thinking. Thanks for the right answer, Kerbart!

Link to comment
Share on other sites

Don't forget to watch out for latitude values outside of the normal range too. :huh:

I have occasionally seen values like -97oS x 10oE pop up. In non-stupid terms that would be -83oS x -170oW.

If you’re using a Mac I can’t help you, but a neater (and quicker) way of entering degree symbols (instead of a superscripted lowercase o) is to hold down the alt key and enter 0176 on the numeric keypad. You'll get something like this: 76° instead of this: 76o.

And while you’re at it; Alt+0215 is the magic entry for multiplication; × instead of x.

Don't get me wrong; I'm not criticizing your efforts to write something that looks aesthetically pleasing; I've seen to many 3.1415E17's on this forum (instead of 3.1415×1017) to complain about that; just trying to make what you write even more awesome. :)

Edited by Kerbart
Link to comment
Share on other sites

Don't forget to watch out for latitude values outside of the normal range too. :huh:

I have occasionally seen values like -97oS x 10oE pop up. In non-stupid terms that would be -83oS x -170oW.

Thanks. I'll double check the lats but for now they seem to be fine without the math. As for strange ones, that might actually be to my benefit. For what I'm doing, an occasional monkey wrench in the clockwork would be a good thing.

Link to comment
Share on other sites

  • 3 weeks later...

Don't get me wrong; I'm not criticizing your efforts to write something that looks aesthetically pleasing; I've seen to many 3.1415E17's on this forum (instead of 3.1415×1017) to complain about that; just trying to make what you write even more awesome. :)

I take a bit of exception to that; you can paste 3.1415E17 into C-derived languages* as a floating point literal, whereas 3.1415×1017 is definitely incompatible with just about anything outside of vBulletin. The E notation isn't as stylish, but it's more useful.

If you write it as 3.1415e17, it's not only compatible with C-derived languages, but also Windows Vista/7's calculator (and possibly others too). You can throw in a + there (3.1415e+17) and make the visual gap bigger if so desired (I do think it looks better that way, and it's compatible with gcalctool that way) and retain all the above compatibility.

* - I've only ever really worked with C (and the vast majority of C things work in C++), perl, java, and C#/mono, but I'd expect most of the rest of the C-styled languages to support these notations. Also I've noticed that all three formats work with LibreOffice Calc..

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...