Rotate the all center positions in the certain angle

1 回表示 (過去 30 日間)
Laura
Laura 2013 年 9 月 4 日
I have 4 data points with x and y coordinates and I want to rotate them at certain angle in counterclockwise or clockwise.
Assume (x1,y1), (x2,y2), (x3,y3) and (x4,y4).
Is there a way to rotate them and find the new positions after rotating?
Thanks

採用された回答

Anand
Anand 2013 年 9 月 4 日
If you have the Image Processing Toolbox, you can use the affine2d object to help you with this. Here's an example of how:
Let's say you're points are (1,1),(100,1),(1,100) and (100,100) and you want to rotate them by 45 degrees.
%these are the points to rotate
X = [ 1 1;...
100 1;...
1 100;...
100 100];
%define a transformation matrix for 45 degree rotation
theta = 45;
T = [cosd(theta) sind(theta) 0;sind(theta) -cosd(theta) 0;0 0 1];
%construct an affine2d object using this transformation matrix
tform = affine2d(T);
%transform the points in X to new co-ordinates U using the affine2d object
U = transformPointsForward(tform,X)
U =
1.4142 0
71.4178 70.0036
71.4178 -70.0036
141.4214 0
Hope this helps!
  3 件のコメント
Anand
Anand 2013 年 9 月 20 日
編集済み: Anand 2013 年 9 月 20 日
Yes there is a way to do it without an affine2d object:
%pad X with a column of 1's for z.
X = [X ones(size(X,1),1)];
%transform points in X to new co-ordinates
U = X*T;
%remove the z
U = U(:,1:2)
Laura
Laura 2013 年 9 月 20 日
It makes sense that (1,1) will go to (1.4 , 0) after 45 degree of rotating.
But if you replace (1,1) by (1,0), now the new position is (0.7, 0.7). It does not rotate in the same direction. One is clockwise and other is counterclockwise.

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2013 年 9 月 20 日

カテゴリ

Help Center および File Exchange3-D Scene Control についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by