Construct a 3D rotation matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
David Musoke
am 5 Dez. 2017
Kommentiert: David Musoke
am 6 Dez. 2017
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?
0 Kommentare
Akzeptierte Antwort
Roger Stafford
am 5 Dez. 2017
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 Kommentare
Roger Stafford
am 6 Dez. 2017
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Mathematics and Optimization finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!