How to rotate this 2d matrix with some angle ?

조회 수: 106 (최근 30일)
shubham kumar gupta
shubham kumar gupta 2022년 11월 19일
댓글: Jan 2022년 11월 20일
I tried to make a mesh using this
z=peaks(100);
// Now z is a 100x100 matrix
Now I want to roatate this in some angle like 5 degress
I tried this for
z = peaks(2);
theta = 5;
R = [cosd(theta) -sind(theta); sind(theta) cosd(theta)];
z1=R*z;
but for z greater than 2x2 not working
this i want

채택된 답변

DGM
DGM 2022년 11월 19일
편집: DGM 2022년 11월 19일
You'll need more than zdata to rotate the plot. You'll need to define the x and y positions of the points.
If you just want to rotate the plot, you can just use rotate(). It's up to you to pick the view position you want.
[x y z] = peaks(20);
theta = 15;
hs = mesh(x,y,z);
axis equal
% pick some view vector
% [0 1 0] rotation vector is || to y-axis
% [-3 0 0] origin of rotation vector
rotate(hs,[0 1 0],-theta,[-3 0 0])
view([0 -1 0]) % set the view
axis equal
xlabel('x')
% get the rotated data
xr = hs.XData;
yr = hs.YData;
zr = hs.ZData;
  댓글 수: 3
DGM
DGM 2022년 11월 19일
You can access the XData, etc from the graphics object. I'll update the answer...
shubham kumar gupta
shubham kumar gupta 2022년 11월 19일
Thank you

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jan
Jan 2022년 11월 19일
편집: Jan 2022년 11월 19일
To define a rotation matrix, you need
  • one angle in 2D (rotation around the Z axis)
  • one angle and an axis of rotation in 3D
  • one angle and 2 vectors, which build the plane to rotate in in 4D and higher dimensions. Rotating "around an axis" is not uniquely defined in >= 4D.
  댓글 수: 2
shubham kumar gupta
shubham kumar gupta 2022년 11월 19일
편집: shubham kumar gupta 2022년 11월 19일
can you help how to apply value for u,v?
alpha i chose as 5 degree
z is matrix of 25x25
zRotated = RotMatrix(5,1,z);
not working
Jan
Jan 2022년 11월 20일
Please read the documentation of the provided command: help RotMatrix. The input (5,1,z) are not meaningful. The angle is provided in radians, not degrees. With 3 inputs, you ask for a rotation matrix in a higher dimensional case. Then the 2nd and 3rd argument are two vectors which span the plane to rotate in.
I cannot suggest values vor u and v as long as you do not define the plane to rotate in. But I think, you do not want to rotate in a 25-dimensional space, but still in 2D.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by