开发者

Bank angle from up vector and look at vector?

开发者 https://www.devze.com 2023-01-03 03:57 出处:网络
I can\'t figure out the formula to compute the bank (roll) angle from the up and lookat vectors, though I feel this angle must be measured in tha plan normal to the lookat vector. Any hint appreciated

I can't figure out the formula to compute the bank (roll) angle from the up and lookat vectors, though I feel this angle must be measured in tha plan normal to the lookat vector. Any hint appreciated. FYI I use WPF.

I have posted another ques开发者_开发百科tion here, which is the same problem, but expressed only using math.


This is the final code to determine Bank. Note that I needed to determine the sign of the angle:

// project Y on plan perpendicular to look
Vector3D Yproj = new Vector3D(
    -(lookDirection.Y * lookDirection.X),
    1 - (lookDirection.Y * lookDirection.Y),
    -(lookDirection.Y * lookDirection.Z));
Yproj.Normalize();

// get absolute angle between Y projected and Up
double absAngle = Vector3D.AngleBetween(upDirection, Yproj);

// magic formula
Vector3D cross = Vector3D.CrossProduct(upDirection, Yproj);
double dot = Vector3D.DotProduct(lookDirection, cross);

// set actual signed angle
BDeg = (dot >= 0) ?  absAngle : -absAngle;
0

精彩评论

暂无评论...
验证码 换一张
取 消