Construct a 3D rotation matrix
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
David Musoke
el 5 de Dic. de 2017
Comentada: David Musoke
el 6 de Dic. de 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 comentarios
Respuesta aceptada
Roger Stafford
el 5 de Dic. de 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 comentarios
Roger Stafford
el 6 de Dic. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Map Display en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!