Skip to content

How to get the roll angle for a spacecraft/plane #1579

Answered by jrouwe
adihodos asked this question in Q&A
Discussion options

You must be logged in to vote

Applying forces and torques should work just fine.

To calculate the roll angle you would take the normalized up vector of the ship (U) and the normalized forward vector of the ship (F), project the world up vector (W = Vec3(0, 1, 0)?) onto the right/up plane of the ship:

Vec3 w_projected = W - W.Dot(F) * F

Normalize the result:

w_projected= w_projected.NormalizedOr(Vec3::sZero())

And then use the dot product to get the roll angle:

float angle = ACos(w_projected.Dot(U))

This angle is always positive, so you must negate it depending on what you consider to be positive/negative roll.

This approach breaks down when the ship is flying straight up as roll is undefined in this case.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@adihodos
Comment options

@adihodos
Comment options

@jrouwe
Comment options

Answer selected by adihodos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants