Created
May 4, 2011 19:55
-
-
Save jcchurch/955898 to your computer and use it in GitHub Desktop.
Perform the 3 axis rotation on a set of points.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function V = rotationMatrix(P, x, y, z) | |
% rotationMatrix performs the 3 axis rotation on a | |
% matrix P, which is a 3-by-p set of points, where | |
% d is equal to 3 and represents the dimensionality | |
% of the data and p represents the total number of | |
% observations. | |
% | |
% x represents the amount of rotation along the x axis in radians | |
% y represents the amount of rotation along the y axis in radians | |
% z represents the amount of rotation along the z axis in radians | |
% | |
[d n] = size(P); | |
V = zeros([d n]); | |
M = [cos(y)*cos(z) -cos(x)*sin(z)+sin(z)*sin(y)*cos(z) sin(x)*sin(z)+cos(x)*sin(y)*cos(z) ; | |
cos(y)*sin(z) cos(x)*cos(z)+sin(z)*sin(y)*sin(z) -sin(x)*cos(z)+cos(x)*sin(y)*sin(z) ; | |
-sin(y) sin(x)*cos(y) cos(x)*cos(y) ]; | |
if d == 3 | |
for i = 1:n | |
V(:, i) = M * P(:, i); | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment