rotation meshgrid surface with the predefined angel(using rotation matrix)

Let's say:
x=1:0.2:1.8= [1 1.2 1.4 1.6 1.8];
y=2:0.2:3 = [2 2.2 2.4 2.6 2.8 3];
z=[2 5 2 2 2; 2.1 2.1 2.1 2.1 2.1; 2 2 2 2 2; 3 3 3 3 3; 1 1 1 1 1; 2.5 2.5 2.5 2.5 2.5]; %matrix 6-by-5
[X,Y] = meshgrid(x,y);
surf(X,Y,Z);% the plot show below
The question is: How can I rotate the plot data with the angel=10 (degree), counterclockwise about Z axis, & How can I plot the new meshgrid surface (using the new rotate data) as the below figure?
angel=10;
R=[cosd(angel) -sind(angel) 0;sind(angel) cosd(angel) 0;0 0 1];%the rotation matrix R

 採用された回答

ha ha
ha ha 2018 年 11 月 23 日
編集済み: ha ha 2018 年 11 月 23 日
clear;clc;x = 1:0.2:1.8;
y = 2:0.2:3;
z=[ 2 5 2 2 2;2.1 2.1 2.1 2.1 2.1;2 2 2 2 2;3 3 3 3 3;1 1 1 1 1;2.5 2.5 2.5 2.5 2.5];
[X,Y] = meshgrid(x,y);
xyc = [mean(x), mean(y)];% Rotate about the center
angel = 30;
R = [cosd(angel), -sind(angel); sind(angel), cosd(angel)];
XY = xyc' + R * ([X(:) Y(:)]-xyc)';
XR = reshape(XY(1,:),size(X));
YR = reshape(XY(2,:),size(Y));
surf(X,Y,z);
hold on;surf(XR,YR,z);

その他の回答 (1 件)

Jan
Jan 2018 年 11 月 23 日
編集済み: Jan 2018 年 11 月 23 日
A 2D rotation is sufficient, if you want to rotate the X and Y coordinates only.
x = 1:0.2:1.8; % [1 1.2 1.4 1.6 1.8];
y = 2:0.2:3; % [2 2.2 2.4 2.6 2.8 3];
Z = [2 , 5, 2, 2, 2; 2.1, 2.1, 2.1, 2.1, 2.1; 2, 2, 2, 2, 2; ...
3, 3, 3 3 3; 1 1 1 1 1; 2.5 2.5 2.5 2.5 2.5]; %matrix 6-by-5
[X, Y] = meshgrid(x,y);
subplot(1,2,1)
surf(X,Y,Z);
angel = 10;
R = [cosd(angel), -sind(angel); sind(angel), cosd(angel)];
XY = R * [X(:).'; Y(:).'];
XX = reshape(XY(1, :), size(X));
YY = reshape(XY(2, :), size(Y);
subplot(1,2,2)
surf(XX, YY, Z);

7 件のコメント

Matt J
Matt J 2018 年 11 月 23 日
See also Syntax 3 of this FEX file.
ha ha
ha ha 2018 年 11 月 23 日
編集済み: ha ha 2018 年 11 月 23 日
@Jan. I follow you recommend code, & plot the result. The surface is roatated about Z axis, 10degree. It's acceptable. But as you observed, the surface is rotated and also translate. It is NOT only rotate. I prefer that it will be rotated around the center only. Can you check it?
Matt J
Matt J 2018 年 11 月 23 日
The AxelRot.m file that I provided a link to will allow you to specify an axis of rotation.
Bruno Luong
Bruno Luong 2018 年 11 月 23 日
編集済み: Bruno Luong 2018 年 11 月 23 日
x = 1:0.2:1.8;
y = 2:0.2:3;
z=[ 2 5 2 2 2;
2.1 2.1 2.1 2.1 2.1;
2 2 2 2 2;
3 3 3 3 3;
1 1 1 1 1;
2.5 2.5 2.5 2.5 2.5];
[X,Y] = meshgrid(x,y);
% Rotate about the center
xyc = [mean(x), mean(y)];
theta = 30/180*pi;
R = [cos(theta) -sin(theta);
sin(theta) cos(theta)];
XY = xyc' + R * ([X(:) Y(:)]-xyc)';
XR = reshape(XY(1,:),size(X));
YR = reshape(XY(2,:),size(Y));
close all
surf(X,Y,z);
hold on
surf(XR,YR,z);
ha ha
ha ha 2018 年 11 月 23 日
編集済み: ha ha 2018 年 11 月 24 日
Thank so much @Bruno Luong
Thank so much @ Matt J
ha ha
ha ha 2018 年 11 月 24 日
@ Matt J @Bruno Luong @Jan . Can you help me this topic also? Thanks a lot.
https://www.mathworks.com/matlabcentral/answers/431656-rotate-the-3d-point-data-about-z-axis-and-ox-oy
Jan
Jan 2018 年 11 月 24 日
@haha: Please do not advertise another thread. Imagine the pollution of the forum, if all users would do this. Thanks.
"But as you observed, the surface is rotated and also translate. It is NOT only rotate." - My suggested code was a pure rotation around the origin of the corrdinate system. The modification by removing the mean of the points at first and add them after a rotation includes a translation in addition.

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

カテゴリ

ヘルプ センター および File ExchangeInteractions, Camera Views, and Lighting についてさらに検索

タグ

質問済み:

2018 年 11 月 23 日

コメント済み:

Jan
2018 年 11 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by