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

news/2024/7/21 6:02:07 标签: 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;

代码获取

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


http://www.niftyadmin.cn/n/1371138.html

相关文章

DataGridView 若干问题

1. 只读: ReadOnly 2. 最后一行:dataGridView1.AllowUserToAddRows false; 3.背景色 : BackgroundColor

ArcGIS/ArcMap10.7界面初始化

在ArcMap关闭的情况下,使用Everything搜索Normal.mxt,将其删除即可。 重新打开ArcMap,可以发现界面已经恢复正常

c# List Sort 简单实现

vtTick.Sort((Comparison<CtpTick>)delegate(CtpTick a,CtpTick b){if (a.UpdateTime < b.UpdateTime)return -1;if (a.UpdateTime > b.UpdateTime)return 1;if (a.doneVolume < b.doneVolume)return -1;if (a.doneVolume > b.doneVolume)return 1;//下面是无…

【Java】JDK安装和环境变量配置

目录 1. 安装JDK 2. 配置环境变量 2.1 进入环境变量 2.2 编辑用户变量 2.3 编辑系统变量 2.4 保存设置 3. 验证Java环境 1. 安装JDK 这里我提供一个jdk11.0.264.msi&#xff0c;也可以自行去官网下载 https://download.csdn.net/download/qq_42276781/76644982https:/…

GeoServer-2.19.1部署

目录 1. GeoServer简介 2. GeoServer下载 3. GeoServer部署 1. GeoServer简介 GeoServer implements industry standard OGC protocols such as Web Feature Service (WFS), Web Map Service (WMS), and Web Coverage Service (WCS). Additional formats and publication op…

WPF App下无法多个窗口按序ShowDialog

原因如下: http://www.silverlightchina.net/html/study/WPF/2012/0226/14062.html 解决方法: http://stackoverflow.com/questions/4179758/how-to-detect-that-a-window-has-used-up-its-showdialog-call 最好是使用 Application.Current.ShutdownMode ShutdownMode.OnEx…

地理坐标系:GCJ02和BD09互转

地理坐标系介绍 主流地理坐标系、投影坐标系和投影方法的区别和联系_ 一只博客-CSDN博客https://blog.csdn.net/qq_42276781/article/details/122597363 关于坐标系的转换&#xff0c;可以参考如下两个开源项目gcoord和coordtransform GitHub - hujiulong/gcoord: 地理坐标系…

动态调用 , 卸载 Assembly

1.其实还是很麻烦的. 主要是使用起来麻烦, 你不能直接在本地调用,使用Remote Type . 2.初级资料: http://www.cnblogs.com/wayfarer/archive/2004/09/29/47896.html 3.完整的: http://blog.csdn.net/westfruit/article/details/5501409 http://www.cnblogs.com/yuxuanji/a…