Construct a 3D rotation matrix
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
David Musoke
il 5 Dic 2017
Commentato: David Musoke
il 6 Dic 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 Commenti
Risposta accettata
Roger Stafford
il 5 Dic 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 Commenti
Roger Stafford
il 6 Dic 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Map Display in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!