Jump to content

Getting Angular Velocity relative to craft. (ΔPitch, ΔRoll, ΔHeading).


Recommended Posts

How do i orient a craft's angularVelocity vector to extract the ΔPitch, ΔRoll, ΔHeading? 

Mechjeb does this to orient the attitude vector to get the pitch roll and heading:

            Vector3d CoM, north, up;
            Quaternion rotationSurface;
            CoM = Vessel.CoM;
            up = (CoM - Vessel.mainBody.position).normalized;
            north = Vector3d.Exclude(up, (Vessel.mainBody.position + Vessel.mainBody.transform.up * (float)Vessel.mainBody.Radius) - CoM).normalized;

            rotationSurface = Quaternion.LookRotation(north, up);

            Vector3d attitude = Quaternion.Inverse(Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(Vessel.GetTransform().rotation) * rotationSurface).eulerAngles;

However doing something similar but replacing Vessel.GetTransform().rotation with Vessel.angularVelocity results in what seems like meaningless numbers.

Link to comment
Share on other sites

@c4ooo so the code Sarbin has provided is not really what you think it might be, which might be a direction. What that should give you is the offset (in degrees) from your "forward" (prograde) vector. If you're pointing prograde, I would expect it to be somewhere around <±180,±180,±180>, and pointing prograde, <0,0,0>.

You'll have to do some testing to figure out what "direction" each of the different numbers corresponds to in terms of the pitch, roll, and yaw (the vector should contain, if I am correct, each of those values from either [-90,90] or [0,180], probably the first one). 

If you'd like some more help with this, just post here with some of the output values and we can help you figure out what they might mean. 

Edited by Benjamin Kerman
Fixed vector ranges from 90->180
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...