Jump to content

I can't understand the coordinate system: why am I moving vertically when on ground?


Dunbaratu

Recommended Posts

I started using the KOS scriptable autopilot mod and it sometimes exposes bits of the underlying API to people who've never written mods and some of those bits are really confusing. Right now I'm trying to wrack my brain over why velocity vectors always seem to be quite a bit off from what the navball says.

I looked at the GitHub code and I think I might be able to get some help from other people who've coded mods before because I think the issue I'm having is with the entire coordinate system itself - I can't find documentation on how it's set up.

First here's everything I *DO* think I understand:

When you ask the mod to tell you the current orbital velocity, from reading through the mod's code on GitHub I get the impression that it just maps to returning this in underlying KSP mod API:

Vessel.obt_velocity

And this appears to be in a coordinate system in which its polar rather than rectangular, with the current main body at the center, in which X = upward (away from origin), Y = northward, and Z = eastward.

That all makes sense to me. I verified that it is in a polar coordinate system by simply time warping around Kerbin's daily rotation to see what the values were at different positions around the sphere and velocity is the same at all positions.

The ground speed due to Kerbin's daily rotation is 174.53 m/s so I'd expect to see a vector of 174.53 or close to it in magnitude if I sample my velocity while I'm just sitting on the ground not moving, and I do. I get this:

(-46.4125, 0.000258, 168.2678 )

Which with the Pythagorean theorem is VERY close to 174.53 in magnitude, so that's all sensible to me.

Now the part that I just don't get:

Yes the magnitude is about 174 m/s, BUT... why isn't it directly along one of the axes? Why isn't it something closer to this:

(0,0,174)

rather than

(-46,0,168)

What is the coordinate system the game uses here? On the one hand it behaves like a polar coordinate system centered on the planetary body, but then it doesn't because the direction of "up" doesn't seem to actually be straight up from the planet but is a bit canted off from Up.

Can someone help me understand why this is? Is there an "introduction to the coordinate system of KSP" somewhere? I googled a lot trying to find it but came up empty.

Edited by Steven Mading
Forgot to make it clear in the body that this is the velocity while sitting still on the ground.
Link to comment
Share on other sites

I'm not a mathematician. Now that that is out of the way. When you are asking for the magnitude of a vector3 you're going to get one number. And why do you get a number different from each axis value? I think it's much like the hypotenuse of a triangle. It takes all 3 floats of the vector and calculates them combined. If you want an accurate x y or z just pull the one value instead of pulling the whole vector3.magnitude. A vector3 junkie will likely chime in with a more accurate answer. :)

Link to comment
Share on other sites

I'm not a mathematician. Now that that is out of the way. When you are asking for the magnitude of a vector3 you're going to get one number. And why do you get a number different from each axis value? I think it's much like the hypotenuse of a triangle. It takes all 3 floats of the vector and calculates them combined. If you want an accurate x y or z just pull the one value instead of pulling the whole vector3.magnitude. A vector3 junkie will likely chime in with a more accurate answer. :)

You really didn't get what I was asking. The magnitude is FINE. It's correct. THAT isn't the problem.

The problem is that I don't understand the DIRECTION of the vector. The fact that the direction is NOT due east but is in fact east plus 14 degrees of downward pitch is what's confusing me. That seems to indicate that the coordinate system in use isn't the one I thought it was and has a frame of reference in which the origin is NOT the center of the planet. I'm trying to steer by these vectors and the fact that they're off from what I'd expect is really screwing me up.

Link to comment
Share on other sites

Well, idk what coord system kOS, but sounds like you get the vessels velocity in the world space (center of planet as origin, north pole as up) but want it in vessel space (center of vessel as origin, direction its facing as up). You don't care about the origin, so just rotate the vector accordingly and you should be fine.

Link to comment
Share on other sites

I think this is going to take multiple readings to figure out.

My first thought is that co-ordinate system in the game is actually a fixed box with the sun at the center and everything moving on those co-ordinates.

If so, when you get numbers in reference to Kerbin, those are just a calculation between Kerbin's center and your current position on the game-wide co-ordinate system.

Therefore the vector you got was your vector both for the surface of Kerbin turning, but also Kerbin's orbit around the sun. The vector you got was not actually related to Kerbin at all, beyond the fact that your point of reference happens to be on Kerbin's surface.

(I am guessing here, I don't actually know how the in-game co-ordinates work.)

Now, you said the readings you got were all very close to Kerbin's surface speed, if you plot them do they max out at Kerbin's surface speed + Orbital speed and at Kerbin's surface speed - Orbital speed?

If so, then your vector is relative to the game-wide co-ordinates of the solar system, not to anything on Kerbin.

(I think, beware of holes in my logic that I've not thought of yet.)

D.

Link to comment
Share on other sites

Well, idk what coord system kOS, but sounds like you get the vessels velocity in the world space (center of planet as origin, north pole as up) but want it in vessel space (center of vessel as origin, direction its facing as up). You don't care about the origin, so just rotate the vector accordingly and you should be fine.

The fact that I DON'T have center of planet as origin but ALMOST do is why it makes no sense. If it was a system with the center at the planet, then sitting still at the equator should be giving an answer with two of the numbers always zero or very close to zero with a bit of floating point wobble. THIS would make sense:

(0,0,174)

or this

(174,0,0)

or this

(0,174,0)

But what I get is this:

(-46,0,168)

Now, the thing is, that MIGHT make sense if it was a cartesian coordinate system with a grid of cubes, but only if it was a number that keeps changing as I rotate around the surface. If it was not polar coordinates, but rectangular, then I might get numbers that move over time as I rotate around the surface, like say,

(-46,0,168) now, and then

(-70,0,150) a little while later, and then

(-126,0,120) a little later,

and so on as I move around the circle.

BUT that is not what I get. I consistently get a number that is floating-point-close to (-46,0,168) no matter what time of day it is on Kerbin (no matter where I've rotated to on the surface relative to the rest of the solar system).

So it's neither centered at the planet center, NOR is it centered at the solar system.... so.... what is it? That's what I can't figure out.

Link to comment
Share on other sites

Now, you said the readings you got were all very close to Kerbin's surface speed, if you plot them do they max out at Kerbin's surface speed + Orbital speed and at Kerbin's surface speed - Orbital speed?

Neither. They remain fixed. At exactly 174.52 m/s magnitude, no matter when in the Kerbin day I look (no matter where I've rotated to on the Kerbin surface - on the side facing the sun, on the side facing away from the sun, it's the same), which proves it HAS to be a relative coord system relative to Kerbin somehow and not one global to the solar system. And yet... if it's relative to Kerbin, why isn't it relative to the CENTER of Kerbin? The direction of the X axis isn't straight up away from planet center. It's about 14 degrees off from that. And this remains consistent no matter the time of day.

It's behaving for all the world like it is a polar coordinate system, but one that instead of having an origin at the center of Kerbin it has one at a point that is inside Kerbin, but is about 14,000 miles away from Kerbin's center. That can't possibly be right. There'd be no reason to design the game that way, so I don't get what's going on.

Link to comment
Share on other sites

Hmm. I did find this:

<member name="T:Krakensbane">

<summary>

The physics simulation has problems if vessels move too fast relative to

the underlying reference frame used by the simulation, or get too far from

the origin of the coordinate system. Krakensbane shifts the reference frame

origin and velocity so that the active vessel is always near the origin of,

and moving slowly with respect to, the underlying coordinate system used by the

physics simulation.

</summary>

from Anatid's github documentation. There is a bunch of subclass stuff that looks like it might also apply.

Alternatively, what happens if you rotate in place? I'm thinking it might be relative to your current control part's facing.

If you face due east, does it move to something like -46,0,168?

I will admit to being stumped at this point.

D.

Edited by Diazo
Link to comment
Share on other sites

Hmm. I did find this:

from Anatid's github documentation. There is a bunch of subclass stuff that looks like it might also apply.

What happens if you rotate in place? (IE: Don't actually move, just change your facing.)

I will admit to being stumped at this point.

D.

I guess if the KOS plugin allowed me to obtain the position in the same coordinate system as the velocity, then I'd be able to see where the origin is relative to the vessel and then I'd know what's going on. But all I can get is the velocity.

Link to comment
Share on other sites

Sorry, edited my post about 3 times while you were posting.

What if it is relative to your current control part in a box co-ordinate system.

-46 for the motion down as Kerbin's rotation pulls you down, 0 because you are not moving north or south and 168 for the eastward motion of Kerbin's spin? so -46,0,168 that you are seeing.

So zero point is your current vessel on a typical X,Y,Z box.

D.

edit: If this is the case, rotating your craft to face east, instead of north, should give something like -46,168,0 I think?

Edited by Diazo
Link to comment
Share on other sites

Sorry, edited my post about 3 times while you were posting.

What if it is relative to your current control part in a box co-ordinate system.

-46 for the motion down as Kerbin's rotation pulls you down, 0 because you are not moving north or south and 168 for the eastward motion of Kerbin's spin? so -46,0,168 that you are seeing.

So zero point is your current vessel on a typical X,Y,Z box.

D.

edit: If this is the case, rotating your craft to face east, instead of north, should give something like -46,168,0 I think?

Rotation makes no difference.

Also, I don't understand your phrase "-46 for the motion down as Kerbin's rotation pulls you down". How does rotation pull you down? Did you mean gravity? If so, then that would make sense if this was a force vector but it's not. It's a velocity vector. A ship that's TRYING to move downward but is failing to because there's ground in the way is still moving zero downward just as much as a ship with no gravity acting on it.

Link to comment
Share on other sites

If rotation of your craft makes no different then I am out of ideas.

What I meant by the "-46 for the motion down as Kerbin's rotation pulls you down" was in my assumed method where it was box co-ordinates, you are 46 units lower then the horizon plane from your last position due to Kerbin's rotation.

As that has now been proven to not be what is being used, it does not apply regardless.

So I am stumped. Good luck with this but I can't be of any more help.

D.

Link to comment
Share on other sites

Could it be because in the X, Y, Z coordinate system for KSP that Y is vertical/height, instead of Z (like a normal cartesian system would be)?

Nope. It's because the XYZ system is tilted at a funny angle. Neither X, nor Y, nor Z is pointing straight up. X points up-ish, about 14 degrees off from up. What I'm trying to figure out is... why? And how do I convert from the coordinates I can see to this weird system?

Link to comment
Share on other sites

Now the part that I just don't get:

Yes the magnitude is about 174 m/s, BUT... why isn't it directly along one of the axes? Why isn't it something closer to this:

(0,0,174)

rather than

(-46,0,168)

Because you're not at the right place on the planet, and it's not a spherical coordinate system. There is one particular point on the equator where your velocity would be <0,0,174>. On the opposite side of the planet, your velocity would be <0,0,-174>, and at 90 degrees from those points you'd find <174,0,0> and <-174,0,0>. <0,0,174> always indicates a particular direction in universal space, which is the opposite of the direction you'd be moving while on the opposite side of the planet. The center number will always be zero since it indicates movement along the Y axis, which is identical to the planet's axis since all Kerbol's planets have no axial tilt. At the north pole, <0,1,0> would be moving straight up, whereas at the south pole, that'd be the direction of the ground. In other words, the same direction in universal space, just the opposite direction relative to the surface of the planet at those locations.

Edited by Gaius
Link to comment
Share on other sites

If rotation of your craft makes no different then I am out of ideas.

What I meant by the "-46 for the motion down as Kerbin's rotation pulls you down" was in my assumed method where it was box co-ordinates, you are 46 units lower then the horizon plane from your last position due to Kerbin's rotation.

If it was calculated by taking two sample positions over a delta time and looking at how far it moved during that time then such a larger error is in principle poissible... BUT.... to be 14 degrees off requires it to be a VERY slow sampling rate, because it's going to take 14 minutes to move that far off. (The fact that it's 14 minutes to move 14 degrees is purely a coincidental effect of the fact that a Kerbin day is 6 hours long. and 6 * 60 = 360, making it move one degree per minute.)

Link to comment
Share on other sites

Because you're not at the right place on the planet, and it's not a spherical coordinate system. There is one particular point on the equator where your velocity would be <0,0,174>. On the opposite side of the planet, your velocity would be <0,0,-174>, and at 90 degrees from those points you'd find <174,0,0> and <-174,0,0>. <0,0,174> always indicates a particular direction in universal space, which is the opposite of the direction you'd be moving while on the opposite side of the planet. The center number will always be zero since it indicates movement along the Y axis, which is identical to the planet's axis since all Kerbol's planets have no axial tilt. At the north pole, <0,1,0> would be moving straight up, whereas at the south pole, that'd be the direction of the ground.

This makes sense to me... I think. So I'm assuming that point would be Lat 0, Long 0? Or does it not rotate along with the planet? Hopefully it does... and hopefully it's a consistent point across all planets/moons so that conversion to something useful will be possible... otherwise velocity:surface is going to be a pain to work with.

Link to comment
Share on other sites

Because you're not at the right place on the planet, and it's not a spherical coordinate system. There is one particular point on the equator where your velocity would be <0,0,174>. On the opposite side of the planet, your velocity would be <0,0,-174>, and at 90 degrees from those points you'd find <174,0,0> and <-174,0,0>. <0,0,174> always indicates a particular direction in universal space, which is the opposite of the direction you'd be moving while on the opposite side of the planet. The center number will always be zero since it indicates movement along the Y axis, which is identical to the planet's axis since all Kerbol's planets have no axial tilt. At the north pole, <0,1,0> would be moving straight up, whereas at the south pole, that'd be the direction of the ground.

But that would require that the numbers CHANGE depending on the time of day. And They Don't.

For what you're saying to be the reason it would have to mean that as I rotate around the surface in a kerbin day, I'd be in all those different positions, and ''I already tested that before I posted here'', as I mentioned in my first post description. What you describe does not happen. My velocity is always <-46,0,168> no matter whether I take the sample at high noon (on the sunward-facing side of Kerbin) or at dusk (on the retrograde side of Kerbin's orbit of the sun or at midnight (on the side of Kerbin farthest from the sun) or at dawn (on the side of Kerbin facing Kerbin's prograde direction around the sun). Whatever the frame of reference happens to be, it is definitely moving with me as I rotate through a Kerbin day. That shoots down the universal space coordinate explanation. Besides, I'm certain the devs have said that they use a coordinate system centered on the body you are in the SOI of.

[Edit: Wait.. there is ONE way it would work now that I think of it and it's not exactly what you described, though. You describe a universal space coordinate system, and that can't be true given what I saw. Given what I'm seeing it does have to be centered on Kerbin... BUT.... just because it's centered on Kerbin doesn't have to mean it's polar. It could still be an orthogonal grid centered on Kerbin. that might be it... let me try some math to see if that's it.]

Edited by Steven Mading
Link to comment
Share on other sites

But that would require that the numbers CHANGE depending on the time of day. And They Don't.

No, nothing I said requires the numbers to change depending on the time of day. The system is relative to Kerbin, and rotates with it. But everything I posted is true nonetheless. If your velocity is <x, 0, z> at your current point on the surface, it'll be <-x, 0, -z> if you were 180 longitude degrees away. It's "universal" in that sense. <x, 0, z> is the same direction no matter where you are, which may make it the opposite direction relative to the surface at that point (i.e. if it's motion due east where you are, it'd be due west 180 degrees from where you are -- the same direction from a "universal" point of view, but opposite relative to the surface at that point).

I guess "universal" is not the best term to use here. Or it is, kinda, with the understanding that your current sphere of influence defines the "universe". The point being, the numbers don't change depending on where you are within the sphere of influence. At a given moment in time, everyone flying in the direction <x, y, z> will be flying parallel, heading towards the same star.

Edited by Gaius
Link to comment
Share on other sites

[Edit: Wait.. there is ONE way it would work now that I think of it and it's not exactly what you described, though. You describe a universal space coordinate system, and that can't be true given what I saw. Given what I'm seeing it does have to be centered on Kerbin... BUT.... just because it's centered on Kerbin doesn't have to mean it's polar. It could still be an orthogonal grid centered on Kerbin. that might be it... let me try some math to see if that's it.]

The Kerbal Space Center is at 76 degrees West longitude. Which is exactly 14 degrees off from 90 degrees. The amount by which the coordinates were angled from straight-up was exactly 14 degrees.

The coordinate system IS a grid and not polar, but it DOES rotate as your main body rotates For some reason I couldn't picture that. I kept tying together "it rotates with Kerbin" with "It is therefore polar coordinates" in my head.

Thanks for people helping by being a sounding board to bounce ideas off of. Finally solved.

The Grid looks like this:

X = Draw a ray from the center of the SOI body out through its 90 degree west longitude line on the equator. That's the X axis.

Y = Draw a ray from the center of the SOI body along its axis through its north pole. That's the Y axis.

Z = Draw a ray from the center of the SOI body out through its prime meridian (0 degree longitude) line on the equator. That's the Z axis.

I think.

And this grid rotates as the planet rotates.... but... wait... no...darn it. If that was the case then the orbital and the surface vectors would be the same.

Darn I thought I had it.

I was "this" close to figuring it out.

Link to comment
Share on other sites

But that would require that the numbers CHANGE depending on the time of day.

No. You know, in KSP physics are horrible complicated. As long as you are on the ground, the planet does not rotate and instead the entire universe including sun flies around the planet, just like Christians would have loved it^^

Afaik the reason is similar to the krakensbane... a moving ground + still standing (but for the physics sys also moving) obj can create problems for the physics engine so not rotating physics makes sense once your get close to the surface. The planet Kerbin actually starts "rotating" exactly at 100km.

But still, whats the problem? You need an "Up in the sky" vector? Well, the coordinates systems origin should be the center of the planet, so all you have to do is normalize your position vector and your fine. If your velocity is not pointing in the same direction that means your not going to space today :D

*edit*

"So why do i have a velocity if the plant is not rotating?" your asking? KSP does calculate the "what would it be actually"-velocity, so you can use only this one and do not have to consider such stuff... usually^^

Year, its soooo complicated and coooooool (to quote southpark)

Edited by Faark
Link to comment
Share on other sites

No, nothing I said requires the numbers to change depending on the time of day.

Well, I can't read your mind. That's true of what you *meant*, when clarified, but not what you *said*, which was that the coordinate system was universal space. It's not if it's centered on the SOI body.

Anyway, the one sticking point though is that if the coordinate space moves relative to kerbin, how can the surface-based velocity differ from the orbital one?

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...