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

4 Ansichten (letzte 30 Tage)
MSolano
MSolano am 7 Jun. 2021
Bearbeitet: MSolano am 9 Jun. 2021
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 Kommentare
Star Strider
Star Strider am 7 Jun. 2021
See the Wikipedia article on Hypocycloid.
MSolano
MSolano am 8 Jun. 2021
This is exactly what I needed, I changed the equations for the hypocycloid and it worked! Thank you!!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

darova
darova am 8 Jun. 2021
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

Weitere Antworten (0)

Kategorien

Mehr zu 3-D Scene Control finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by