Compute 3D rotation matrix
No License
Given input:
r: angle to rotate, in rads
Axis: axis of rotation, defined as a 3point which connects to the origin.
Output:
3x3 Matrix R such that for an arbitrary point v, Rv is the point corresponding to v rotated around the Axis.
% example:
% rotate around a random direction a random amount and then back
% the result should be an Identity matrix
r = rand(4,1);
rotationmat3D(r(1),[r(2),r(3),r(4)]) * rotationmat3D(-r(1),[r(2),r(3),r(4)])
ans =
1.0000 0.0000 0.0000
0.0000 1.0000 0
0.0000 0 1.0000
%
% example2:
% rotate around z axis 45 degrees
Rtest = rotationmat3D(pi/4,[0 0 1])
Rtest =
0.7071 -0.7071 0
0.7071 0.7071 0
0 0 1.0000
Cite As
Stanley (2025). Compute 3D rotation matrix (https://www.mathworks.com/matlabcentral/fileexchange/23417-compute-3d-rotation-matrix), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- MATLAB > Mathematics > Computational Geometry >
- MATLAB > Graphics > Formatting and Annotation > 3-D Scene Control >
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |