Jump to content

Pitch and Heading of Prograde vector


Recommended Posts

I am wanting to make a more advanced navball that I can run in a browser for my physical console project.

I am hoping to modify the navball code from https://github.com/creshal/telemachus-glass-cockpit which is built on data from telemachus.

It is able to draw the navball by reading rawPitch, rawHeading and rawRoll from telemachus (calculated with this code: https://github.com/richardbunt/Telemachus/blob/master/Telemachus/src/DataLinkHandlers.cs#L1123)

In order to render prograde, retrograde, maneuver, etc.., I need to modify telemachus to give me raw pitch and heading data for those vectors.

If I take

[COLOR=#333333]Vector3 prograde = this.vessel.GetObtVelocity();[/COLOR]

I get a vector in x,y,z space. That is about as far as I have gotten. I need to transform this into pitch and heading values relative to the current body in order to render them on the navball.

Can anyone point me in the right direction?

Link to comment
Share on other sites

Calculate prograde pitch by the angle between prograde and surface normal like this (substituting vessel.up (forward in KSP) for the prograde vector). Heading is a bit more complex, but you can also find the calculations required at that link

Edited by Crzyrndm
Link to comment
Share on other sites

Yeah, I'm having a bit of trouble with the pitch:

[FONT=Menlo][COLOR=#009695]var [/COLOR][COLOR=#333333]planetUp[/COLOR][COLOR=#333333]=[/COLOR][COLOR=#333333]([/COLOR][COLOR=#333333]thisVessel[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]rootPart[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]transform[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]position[/COLOR][COLOR=#333333]-[/COLOR][COLOR=#333333]thisVessel[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]mainBody[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]position[/COLOR][COLOR=#333333])[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]normalized[/COLOR][COLOR=#333333];[/COLOR]
[COLOR=#009695]var [/COLOR][COLOR=#333333]pitch[/COLOR][COLOR=#333333]=[/COLOR][COLOR=#3364a4]Vector3d[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]Angle[/COLOR][COLOR=#333333]([/COLOR][COLOR=#333333]planetUp[/COLOR][COLOR=#333333],[/COLOR][COLOR=#333333]thisVessel[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]obt_velocity[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]normalized[/COLOR][COLOR=#333333])[/COLOR][COLOR=#333333];[/COLOR]
[COLOR=#009695]return [/COLOR][COLOR=#333333]pitch[/COLOR][COLOR=#333333];[/COLOR][/FONT]

I would expect this to stay at or near 0 as I ascend pointing straight up. It starts at around 90 and shrinks gradually to around 11 or so degrees as I climb. This is obviously not correct. Thanks for your help. I got the heading working perfectly.

Link to comment
Share on other sites

pitch at launch would be zero relative to surface velocity, not orbital velocity (navball starts in surface mode). It starts at 90 degrees because the rotational velocity of the planet is perpendicular to the up vector, then shrinks as your vertical velocity increases.

Link to comment
Share on other sites

Ok, that actually makes a lot of sense. I got it pretty good using surface velocity under 36000 and orbit velocity above that.

Is there a table somewhere of altitudes for switching surface -> orbit mode for all bodies? Or even better a useful formula?

Thanks for all your help!

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