Matlab实现平面几何图形的平移、旋转和缩放

相关文章

有英语基础的同学可以看一下我之前的博客

基于Matlab的二维变换 C307 Lab-2:2D Geometric Transforms_ 一只博客-CSDN博客https://blog.csdn.net/qq_42276781/article/details/104144931

理论基础


平移变换

demo_translation.m

clear, close all 
%% 绘制变换前的图形
points = [2 2 3 3 2;
          2 3 3 2 2];
points = [points; ones(1,5)];
figure
plot(points(1,:), points(2,:), 'b*-');
%% 设置平移矩阵
tx = 1; % x方向位移
ty = 2; % y方向位移
translation = [1  0  tx;
               0  1  ty;
               0  0   1];
%% 平移变换
translated = translation * points;
%% 绘制变换后的图形
hold on
plot(translated(1,:), translated(2,:), 'ro--');
legend('原图形','变换后')
axis equal;


旋转变换

demo_rotation.m

clear, close all
%% 绘制变换前的图形
points = [2 2 3 3 2;
          2 3 3 2 2];
points = [points; ones(1,5)];
figure
plot(points(1,:), points(2,:), 'b*-');
%% 设置旋转矩阵
xita = pi/3; % 绕原点(0,0)顺时针旋转角度
rotation = [cos(xita) sin(xita)  0;
           -sin(xita) cos(xita)  0;
                0         0      1];
%% 旋转变换
rotated = rotation * points;
%% 绘制变换后的图形
hold on
plot(rotated(1,:), rotated(2,:), 'ro--');
legend('原图形','变换后')
axis equal;


缩放变换

demo_scaling.m

clear, close all
%% 绘制变换前的图形
points = [2 2 3 3 2;2 3 3 2 2];
points = [points; ones(1,5)];
figure
plot(points(1,:), points(2,:), 'b*-');
%% 设置缩放矩阵 
sx = 1; % 横坐标缩放尺度
sy = 2; % 纵坐标缩放尺度
scaling = [sx   0   1;
            0  sy   1;
            0   0   1];
%% 缩放变换
scaled = scaling * points;
%% 绘制变换后的图形
hold on
plot(scaled(1,:), scaled(2,:), 'ro--');
legend('原图形','变换后')
axis equal;

代码获取

关注公众号,回复“数字图像处理”即可获得完整代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Toblerone_Wind

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值