How to rotate?

조회 수: 1 (최근 30일)
han han
han han 2020년 5월 30일
편집: han han 2020년 5월 30일
I want to modify the following program like the following figure.
a=0.5;
b=2;
m = 1000;
x = zeros(m,1);
y = zeros(m,1);
theta = linspace(0,2*pi,m);
for k = 1:m
x(k) = a * cos(theta(k));
y(k) = b * sin(theta(k));
end
for a=0:0.5:1
for xc = 1:-1:0
R = [cos(a) -sin(a); ...
sin(a) cos(a)];
rCoords = R*[x' ; y'];
xr = rCoords(1,:)';
yr = rCoords(2,:)';
yc = 1;
grid on;
axis equal;
end
hold on
plot(xr+xc,yr+yc,'b');
end
  댓글 수: 1
Ameer Hamza
Ameer Hamza 2020년 5월 30일
The pasted code in incomplete.

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

채택된 답변

Image Analyst
Image Analyst 2020년 5월 30일
han han, I have not heard back from you so I assume you had trouble adapting my demos. So I did the thing 100% for you to give you exactly what you showed:
% Demo to rotate an ellipse about a center that also rotates around a circle.
% By ImageAnalyst
clc; % Clear the command window.
clearvars;
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 14;
xCenter = 23.5;
yCenter = 0.5;
a = 2.0;
b = 0.5;
r = a;
% First get an ellipse centered at the origin of the proper size and shape.
hEllipse = imellipse(gca,[-a, -b, 2*a, 2*b]); % Second argument defines ellipse shape and position.
% Get (x,y) coordinates from the ellipse.
disp(hEllipse);
xy = hEllipse.getVertices();
% Clear original ellipse from axes.
axesHandlesToChildObjects = findobj(gca, 'Type', 'line');
if ~isempty(axesHandlesToChildObjects)
delete(axesHandlesToChildObjects);
end
x = xy(:,1);
y = xy(:,2);
% plot(x, y, 'r-');
xy = [x y];
% Now rotate the ellipse through other angles and centers.
angles = 0 : 22.5 : 360 - 22.5;
for k = 1 : length(angles)
theta = angles(k);
rotationArray = [cosd(theta) sind(theta); -sind(theta) cosd(theta)];
% Make a rotated ellipse about the origin.
rotated_xy = xy * rotationArray;
% Now shift its center.
xCenter2 = xCenter + (r - 0.25) * cosd(theta);
yCenter2 = yCenter + (r - 0.25) * sind(theta);
x = rotated_xy(:,1) + xCenter2;
y = rotated_xy(:,2) + yCenter2;
% Now plot the rotated ellipse.
plot(x, y, 'color', 'b', 'LineWidth', 2);
if k == 1
axis square;
grid on;
hold on;
end
end
title('Demo Specially Made for han han', 'FontSize', 30);
If this does what you want, can you Accept this answer (since it seems no one else is going to offer a different working solution). Thanks in advance.
  댓글 수: 1
han han
han han 2020년 5월 30일
편집: han han 2020년 5월 30일
wow.... it's a amazing
Thank U so much!!!

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

추가 답변 (1개)

Image Analyst
Image Analyst 2020년 5월 30일
See my attached demos.

카테고리

Help CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by