怎样用matlab将一个几何图形旋转,答对一定采纳
1.绕原点逆时针旋转任意角度θ
X=x*cos(θ)-y*sin(θ)
Y=x*sin(θ)+y*cos(θ)
2.绕任意点A(x0,y0)逆时针旋转任意角度θ
X=(x-x0)*cos(θ)-(y-y0)*sin(θ)+x0
Y=(x-x0)*sin(θ)+(y-y0)*cos(θ)+y0
示例:
x=[1 4 4 1 1];
y=[1 1 2 2 1];
plot(x,y,'b*-') %绘制一个矩阵
hold on
theta=pi/2;
x1=x*cos(theta)-y*sin(theta);
y1=x*sin(theta)+y*cos(theta);
plot(x1,y1,'r.:') %绕原点旋转90度
x2=(x-1)*cos(theta)-(y-1)*sin(theta)+1;
y2=(x-1)*sin(theta)+(y-1)*cos(theta)+1;
plot(x2,y2,'ko--') %绕(1,1)点旋转90度
axis equal
line([-5 5],[0 0],'linestyle',':','color','k')
line([0 0],[-5 5],'linestyle',':','color','k')
axis([-5 5 -5 5])