Construct a 3D rotation matrix

4 ビュー (過去 30 日間)
David Musoke
David Musoke 2017 年 12 月 5 日
コメント済み: David Musoke 2017 年 12 月 6 日
Hi:
I have a 3D vector represented by two points in space (ax,ay,az) and (bx,by,bz). I need to construct a rotation matrix that will tilt this vector in the direction of (0;0;1). I've looked at examples here but they all require you to know the target rotation angle, which I don't have. Mathematica has a simple command for this called: RotationMatrix[{u,v}] ... that gives the matrix that rotates the vector u to the direction of the vector v in any dimension.
How can I do this in Matlab?

採用された回答

Roger Stafford
Roger Stafford 2017 年 12 月 5 日
If your vector to be rotated is
v = [bx,by,bz]-[ax,ay,az],
the required rotation angle to rotate to
w = [0,0,1]
is
angl = atan2(norm(cross(v,w)),dot(v,w)); (in radians)
  4 件のコメント
Roger Stafford
Roger Stafford 2017 年 12 月 6 日
As to the "origins" of the given atan2 formula, the atan2 function will yield as a result, the unique angle theta in radians, between -pi and +pi, such that the first input argument can be expressed as K*sin(theta) and the second argument as K*cos(theta) where K is the appropriate positive value. It is well-known that norm(cross(v,w)) is equal to norm(v)*norm(w)*sine of angle between v and w. It is also well-known that dot(v,w) can be expressed as norm(v)*norm(w)*cosine of the angle between u and w. Hence, your angle can be easily calculated using atan2, with the result theta being that angle between v and w, and where norm(v)*norm(w) plays the role of the above-mentioned K. It's perfect for the job.
David Musoke
David Musoke 2017 年 12 月 6 日
Thanks Roger, really appreciate your detailed and thorough response to my question.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMap Display についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by