How can I rotate a 3d figure with the rotation matrix without using functions?
조회 수: 6 (최근 30일)
이전 댓글 표시
I am very new to matlab and i have been trying to rotate a 3d cube around y axis with 45 degrees without using roty or other stuff.
This is the code
x=[2,0,0]
y=[0,0,0]
z=[0,0,2]
o=[0,0,0]
alfa=pi/4
plot3(x,y,z,Color='r')
axis 'equal'
grid
xlabel 'x'
ylabel 'y'
zlabel 'z'
axis 'equal'
t=[1,2];
A = [0 0 0];
B = [1 0 0];
C = [0 1 0];
D = [0 0 1];
E = [0 1 1];
F = [1 0 1];
G = [1 1 0];
H = [1 1 1];
P = [A;B;F;H;G;C;A;D;E;H;F;D;E;C;G;B];
Ry=[cos(alfa),0,sin(alfa);...
0,1,0;...
-sin(alfa),0,cos(alfa)];
G=Ry*P
plot3(G(:,1),G(:,2),G(:,3))
Now, as far as I know i cannot multiply different size matrixes but I dont know how to transform it to have equal sizes.
So how can I transform those matrixes to be equal sizes and would the code make a cube rotate?
댓글 수: 0
채택된 답변
Jan
2022년 10월 15일
In a matrix multiplication the length of the row of the first matrix must equal the length of the column of the second one.
In you case transposing the 2nd matrix is enough already:
A = [0 0 0];
B = [1 0 0];
C = [0 1 0];
D = [0 0 1];
E = [0 1 1];
F = [1 0 1];
G = [1 1 0];
H = [1 1 1];
P = [A;B;F;H;G;C;A;D;E;H;F;D;E;C;G;B];
alfa = 45 * pi / 180;
Ry = [cos(alfa),0,sin(alfa);...
0,1,0;...
-sin(alfa),0,cos(alfa)];
G = Ry * P.';
plot3(G(1, :), G(2, :), G(3, :)); % Not G(:, 1)
axis equal
댓글 수: 2
Jan
2022년 10월 15일
편집: Jan
2022년 10월 15일
If G is a matrix, G(1, :) replies the first row, while G(:, 1) replies the first column.
You can learn the basics of Matlab in the "Getting Started" chapters of the documentation and in the free online tutorial: https://www.mathworks.com/learn/tutorials/matlab-onramp.html
doc plot3
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!