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 CenterFile Exchange에서 Map Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by