【问题标题】:how to apply transform to 2d points in matlab?如何将变换应用于matlab中的二维点?
【发布时间】:2016-08-15 05:52:43
【问题描述】:
使用 matlab,我想应用旋转的变换包含并转换为 2d 点。
例如我的观点是:
points.x=[1 5 7 100 52];
points.y=[42 96 71 3 17];
points.angle=[2 6 7 9 4];
the value of rotate is:30 degree
the value of x_translate is 5.
the value of y_translate is 54.
任何人都可以帮助我编写 matlab 代码以将此变换应用于我的点并计算变换后点的新坐标吗?
【问题讨论】:
标签:
matlab
matrix
transform
matlab-guide
【解决方案1】:
我不知道您所说的 points.angle 是什么意思,因为点相对于原点的角度(在三角学意义上)已由 atand2(y,x)
这是代码:
clear;clc
oldCoord = [1 5 7 100 52;42 96 71 3 17];
newCoord = zeros(size(oldCoord));
theta = 30 * pi/180;
T = @(theta) [cos(theta), -sin(theta); sin(theta) , cos(theta)];
trans = [5;54];
for m = 1:size(oldCoord,2)
newCoord(:,m) = T(theta) * oldCoord(:,m) + trans;
end
结果:
oldCoord =
1 5 7 100 52
42 96 71 3 17
newCoord =
-15.1340 -38.6699 -24.4378 90.1025 41.5333
90.8731 139.6384 118.9878 106.5981 94.7224