I am doing an assignment for my course where I need to rotate a cube about a given axis. I can not use MATLAB functions, so I need to do it manually.
This is my attempt that is to no avail.
`
function [ CV ] = rotateCubeX( CV, degrees )
%CV = input vertices/Return val
%degrees = amount of degrees to rotate
alpha = degrees * pi/180;
rotate = zeros(3,3);
rotate(1,1) = 1;
rotate(2,2) = cos(alpha);
rotate(2,3) = -sin(alpha);
rotate(3,2) = sin(alpha);
rotate(3,3) = cos(alpha);
CV = CV * rotate;
end
Before:
25.2000 5.9000 2.5000
25.7000 5.9000 2.5000
25.7000 7.9000 2.5000
25.2000 7.9000 2.5000
25.2000 5.9000 2.8000
25.7000 5.9000 2.8000
25.7000 7.9000 2.8000
25.2000 7.9000 2.8000
After:
-10.3544 -23.7200 2.5000
-10.6536 -24.1205 2.5000
-9.0513 -25.3175 2.5000
-8.7521 -24.9169 2.5000
-10.3544 -23.7200 2.8000
-10.6536 -24.1205 2.8000
-9.0513 -25.3175 2.8000
-8.7521 -24.9169 2.8000
No change in image.
I am sure I am forgetting something silly.
What is the axis you expect to rotate about? How have you accounted for that in your code?
If you are trying to rotate about an arbitrary axis, then the general formula for rotation about an arbitrary axis is here. (look under Other Ways to Build a Rotation Matrix). Pay attention to handedness and whether you are using row-major or column major matrices!