How to preform simple Matrix Transmormations
3 次查看(过去 30 天)
显示 更早的评论
I can't figure out how to do translations, rotations and scaling by using matrices. Here is the code. We were told only to use matrices to achieve the effect.
Thanks in advance!
%%Initialize
clc
clear all
close all
%%Part a
shape=[0 1 0; 0 0 1];
Mshape=[0 1 0; 0 0 1;1 1 1];
DX =-3;
DY= 4;
dx =DX/100;
dy = DY/100;
steps = 100
Trans = [1 0 dx ; 0 1 dy; 0 0 1]
for n=1:steps
Mshape =Trans*Mshape
fill(Mshape(1,:),Mshape(2,:),'g')
axis([-8 8 -8 8])
drawnow
end
rev=720;
theta = 1;
Transto0 = [1 0 -DX ; 0 1 -DY; 0 0 1]
TransT = [1 0 DX ; 0 1 DY; 0 0 1]
for n=1:rev
thetaT = n*theta
R=[cosd(thetaT) sind(thetaT) 0 ; -sind(thetaT) cosd(thetaT) 0; 0 0 1]
Mshape = Trans*R*Transto0*Mshape
fill(Mshape(1,:),Mshape(2,:),'g')
axis([-8 8 -8 8])
Mshape
drawnow
end
S = 2
s =S/100;
steps = 100
Scale = [S 0 0 ; 0 S 0; 0 0 1]
for n=1:steps
Mshape =Scale*Mshape
fill(Mshape(1,:),Mshape(2,:),'g')
axis([-8 8 -8 8])
drawnow
end
0 个评论
回答(1 个)
Madhav Rajan
2015-8-4
编辑:Madhav Rajan
2015-8-4
I understand that you want to perform Matrix transformations such as rotation and scaling. Assuming that you want to scale or rotate a matrix M, you would have to first translate your matrix to the origin then perform the rotation or the scaling and then translate your matrix back to its original position. This is because scaling and rotation always happen with respect to the origin.
In the script attached, you can see the effect of applying scaling and rotation on a triangle which has not been translated to its origin and also the effect of first translating the object to the origin and then applying the transformations.
You can refer the following links for more information about scaling and rotations about the origin: http://www.willamette.edu/~gorr/classes/GeneralGraphics/Transforms/transforms2d.htm#Combining
You can also also refer the following documentation for 2d affine transformations in MATLAB: http://www.mathworks.com/help/images/performing-general-2-d-spatial-transformations.html
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 3-D Scene Control 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!