How to rotate a figure around an origin that is rotating?

조회 수: 10 (최근 30일)
MSolano
MSolano 2021년 6월 7일
편집: MSolano 2021년 6월 9일
Hello, I'm trying to rotate a circle P(r1,theta1) around an origin given at coordinates (r,theta) that is rotating at the same time, the resulting trajectory of the point should look like the image in the right. I can make the circle P rotate around the origin (0,0) with the code below but I have no idea how to do it move as it should. As you can see in the gif it doesn't move following the red circle path, I would really appreciate any idea. Thanks!
close all, clc, clear
%% 1: Generating Data
ang = linspace(0,2*pi,50); % Angle from 0 to 2pi
% Data to draw black fixed circle
xp=5*cos(ang); % Coordinate to draw black circle
yp=5*sin(ang); % Coordinate to draw black circle
% Data to draw outter circles pattern
ra = 1; % Radius of inner circle
xb = ra*cos(ang); % Coordinate to draw inner circle
yb = ra*sin(ang); % Coordinate to draw inner circle
Nb=6; % Number of balls
rho1 = 4; % Radius of inner circle, polar coordinate
rmb = 0.1; % Radius of the ball mark
rxmb= rmb*cos(ang); % Coordinate to draw ball mark
rymb= rmb*sin(ang); % Coordinate to draw ball mark
%% 2: Draw/Render Scenario
for angle=1:360
%Clear the figure
clf
% PLOT FIXED INNER CIRCLE
plot(xp,yp, 'color', 'k');
hold on
% PLOT CIRCULAR PATTERN OF GRAY CIRCLES
for iter=1:Nb % Draw until Nb balls
theta1 = 2*pi*(Nb-iter)/Nb; % Angle of position inner circles, polar coordinate (same spacing)
[x,y] = pol2cart(theta1,rho1); % Transform polar to cartesian coordinates
cox=x+xb; % Coordinate to draw moving circles
coy=y+yb; % Coordinate to draw moving circles
balls = plot(cox,coy,'color','r'); % Plot circles
rotate(balls,[0 0 1],angle); % Rotate moving pattern of circles
end
% Drawing mark in the ball and rotating
Rhom = 3;
Thetam = 2*pi;
[x_mb1,y_mb1] = pol2cart(Thetam,Rhom);
fill_mark_ball = fill(x_mb1 + rxmb, y_mb1 + rymb,'r');
rotate(fill_mark_ball,[0 0 1],angle);
%% 3: Take Snapshot
drawnow
end
  댓글 수: 2
Star Strider
Star Strider 2021년 6월 7일
See the Wikipedia article on Hypocycloid.
MSolano
MSolano 2021년 6월 8일
This is exactly what I needed, I changed the equations for the hypocycloid and it worked! Thank you!!

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

채택된 답변

darova
darova 2021년 6월 8일
Try this
t = linspace(0,2*pi,20);
[x,y] = pol2cart(t,1);
n = 6; % number of small circles
h = zeros(1,n); % pre-allocation objects
plot(5*x,5*y)
h1 = line(0,0,'marker','.'); % dot
% draw smal circles
for i = 1:6
h(i) = line(x+4*cosd(i/n*360),y+4*sind(i/n*360));
end
for i = 1:20
% rotate dot using hypocycloid formulas
set(h1,'xdata',4*cosd(2*i)+cosd(5*i))
set(h1,'ydata',4*sind(2*i)-sind(5*i))
rotate(h,[0 0 1],2,[0 0 0]) % small circles
pause(1)
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by