making a transformation of an already moving image

3 次查看(过去 30 天)
I need to make it so that the leter k is transformed once per rotation as the letter moves and can't figure out how to do it. please help I have attached my script
% This script will move the letter K about the screen using
% homogeneous coordinate transformations common to computer graphics
p1=[0;0]; p2=[0.5;0]; p3=[0.5;4]; p4=[3;0]; p5=[3.5;0]; p6=[0.5;4]; p7=[3;8]; p8=[2.5;8]; p9=[0.5;4];p10=[0.5;8]; p11=[0;8];
D = [p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11]
fill(D(1,:),D(2,:),'r')
axis([-30 30 -30 30])
hold on
N = [D;ones(1,11)]
N1=N;
R = [cos(pi/18) -sin(pi/18) 0; sin(pi/18) cos(pi/18) 0; 0 0 1]
color = str2mat('y','m','c','r','g','b','k');
for i=0:5
Shift = [1 0 i; 0 1 i; 0 0 1];
N1 = Shift*N1;
for j=1:36
N1 = R*N1;
D1 = N1(1:2,:);
fill(D1(1,:),D1(2,:),color(rem(j,7)+1))
pause(0.15);
end
end
hold off

回答(1 个)

Prabhan Purwar
Prabhan Purwar 2021-3-19
编辑:Prabhan Purwar 2021-3-19
Hi,
To make the letter k transform once per rotation you will need to change from letter coordinate frame to global coordinate frame where the circular path is defined.
Kindly have a look at the following code:
p1=[0;0]; p2=[0.5;0]; p3=[0.5;4]; p4=[3;0]; p5=[3.5;0]; p6=[0.5;4]; p7=[3;8]; p8=[2.5;8]; p9=[0.5;4];p10=[0.5;8]; p11=[0;8];
D = [p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11];
fill(D(1,:),D(2,:),'r')
axis([-30 30 -30 30])
hold on
N = [D;ones(1,11)];
N1=N;
R = [cos(pi/18) -sin(pi/18) 0; sin(pi/18) cos(pi/18) 0; 0 0 1];
color = char('y','m','c','r','g','b','k');
for i=0:5
% Shift = [1 0 i; 0 1 i; 0 0 1];
% N1 = Shift*N1;
N1 = R*N1;
D1 = N1(1:2,:);
for j=1:36
x = (3*i+3)*cosd(10*j);
y = (3*i+3)*sind(10*j);
% Transform to global coordinate frame
fill(D1(1,:)+x,D1(2,:)+y,color(rem(j,7)+1))
pause(0.15);
end
end
hold off
Thanks

类别

Help CenterFile Exchange 中查找有关 Mathematics and Optimization 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by