开发者

3D Math: Calculate Bank (Roll) angle from Look and Up orthogonal vectors

I hope this is the proper location to ask this question which is the same as this one, but expressed as pure math instead of graphically (at least I hope I translated the problem to math correctly).

Considering:

  • two vectors that are orthogonal: Up (ux, uy, uz) and Look (lx, ly, lz)
  • a plane P which is perpendicular to Look (hence including Up)
  • Y1 which is the projection of Y (vertical axis) along Look onto P

Question: what is the value of the angle between Y1 and开发者_如何学Python Up?

As mathematicians will agree, this is a very basic question, but I've been scratching my head for at least two weeks without being able to visualize how to project Y onto P... maybe now too old for finding solutions to school exercises.

I'm looking for the trigonometric solution, not a solution using a matrix. Thanks.

Edit: I found that I needed to determine the sign of the angle, relative to a rotation axis which had to be Look. I posted the final code on my linked question (see link above). Thanks to those who helped. I appreciate your time.


I'm just doing this on paper. I hope it's right.

Let's assume Up and Look are normalized, that is, length 1. Let's say that plane P contains the origin, and L is its normal. Y is (0, 1, 0)

To project Y onto P, find its distance to P...

d = Y dot L = ly

...and then scale the normal by -d to get the Y1 (that is, the projection of Y on P)

Y1 = (lx * ly, ly * ly, lz * ly)

Now normalize Y1, that is, scale it by (1 / length). If its length was 0 then you're out of luck.

The dot product of Y1 and Up = the cosine of the angle. So

angle = acos(Y1 dot Up)


  • two vectors that are orthogonal: Up (ux, uy, uz) and Look (lx, ly, lz)
  • a plane P which is perpendicular to Look (hence including Up)
  • Y1 which is the projection of Y (vertical axis) along Look onto P

I'll assume Up and Look are unit vectors. Let Y=(0,1,0).
Let's find Y1.

Y1 = Y - (Y*Look) * Look Y1 = Y - ly * Look Y1 = ( -lylx, 1 - lyly, -ly*lz )

Note that Y1 will be (0,0,0) when Look is (0,1,0) or (0,-1,0).

Like Detmar said, find the angle between Y1 and Up by normalizing Y1 and finding the arccos of Y1*Up (where * is dot product)


This is a relatively simple problem using vector math. Use the equation for vector projection to get Y1, then the trigonometric equation for the dot product to get the angle between Y1 and Up.

This equations would be pretty easy to implement yourself in just about any language, but if you're asking this sort of question you may be intending to do more heavy-duty vector math, in which case I'd suggest trying to find a third-party library.


You need to know about vectors in 3D space. I think that a fundamental understanding of those, especially dot and cross products, will sort you out. Seek out an elementary vectors textbook.

two vectors that are orthogonal: Up (ux, uy, uz) and Look (lx, ly, lz)

Orthogonal vectors have a zero dot product.

a plane P which is perpendicular to Look (hence including Up)

If you take the cross product of Look into Up, you'll get the third vector that, along with Up, defines the plane perpendicular to Look.

Y1 which is the projection of Y (vertical axis) along Look onto P

I don't know what you're getting at here, but the dot product of any vector with Look gives you the magnitude of its component in the Look direction.


If Y = (0,1,0) Then

Y1 = (-lylx, 1 - lyly, -ly*lz)

|Y1| = sqrt(Y1x^2 + Y1y^2 + Y1z^2)

|Up| = sqrt(Upx^2 + Upy^2 + Upz^2)

Bank Angle = (Y1xUpx + Y1yUpy + Y1zUpz)/(|Y1||Up|)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜