I made X, Y coordinates and a triangle with zeros and ones on this plane.
I want to rotate this triangle 45 degrees. I tried rotz(), but I don't have idea to do this.
Thanks in advance.
clc; clear all; close all;
x = linspace(-10,10,49);
y = linspace(-10,10,44);
[X,Y] = meshgrid(x,-y);
Z = zeros(44,49);
Z = importdata('triangle_rotate.txt');
imagesc(Z)

 Akzeptierte Antwort

Chunru
Chunru am 15 Nov. 2021

0 Stimmen

clc; clear all; close all;
x = linspace(-10,10,49);
y = linspace(-10,10,44);
[X,Y] = meshgrid(x,-y);
Z = zeros(44,49);
Z = importdata('triangle_rotate.txt');
subplot(121); imagesc(Z); axis equal
Z1 = imrotate(Z, 45);
subplot(122); imagesc(Z1); axis equal

6 Kommentare

태신 김
태신 김 am 15 Nov. 2021
Bearbeitet: 태신 김 am 15 Nov. 2021
Thank you for your simple answer.
However, the matrix size or image size is changed according to the rotation angle.
Are there other methods to rotate it without changing size of matrix?
Thanks.
Chunru
Chunru am 16 Nov. 2021
You can either crop the image or resize the image (which may change the object size).
태신 김
태신 김 am 16 Nov. 2021
I mean I want to rotate the data without change of dimension and size.
Chunru
Chunru am 16 Nov. 2021
If you use a rectangle matrix (with one side along x-axis and another along y-axis) to represent image, you will get different size of rectangle (along x and y) to enclose the rotated image. So you cannot get the same dimension (except for some special case, eg. rotate by 180 deg) in this sense.
Matt J
Matt J am 16 Nov. 2021
You can use the crop option to keep the array the matrix the same size, but there is no guarantee the rotated object will fit inside the original borders:
Z = importdata('triangle_rotate.txt');
Z=imrotate(Z,45,'bicubic', 'crop');
태신 김
태신 김 am 17 Nov. 2021
Thank you for your helpful answers.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Gefragt:

am 15 Nov. 2021

Kommentiert:

am 17 Nov. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by