简体   繁体   English

如何将变换应用于Matlab中的2d点?

[英]how to apply transform to 2d points in matlab?

Using matlab, I want to apply transform contain of rotate and translate to 2d points. 使用matlab,我想应用包含旋转的变换并转换为2d点。 for example my points are: 例如,我的观点是:

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.  

can any body help me to write matlab code for apply this transform to my points and calculate new coordinate of points after transform? 有谁可以帮助我编写matlab代码以将该变换应用于我的点并在变换后计算点的新坐标?

I don't know what you mean by points.angle since the angle of the points with respect to origin (in a trigonometric sense) is already defined by atand2(y,x) 我不知道points.angle是什么意思,因为这些点相对于原点的角度(在三角意义上)已经由atand2(y,x)定义
Here is the code: 这是代码:

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

Result: 结果:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM