I would like to rotate a circle inside another rotating circle.
Show older comments
I am unable to figure out how to update the centres for smaller circle. The graph should look as shown in image below the code.
r1 = 0.7; % radius of core circle
r2 = 0.7; % radius of inner circle
r3 = r2/3; % radius of smaller circle
r4 = 0.05;
R = r1 + r2*2 ; % radius of bigger circle
LL = 5;
n = 1000; % no. of points to be traced
t = linspace(0,2*pi,n); % running variable
c = [0 0];
t1 = linspace(0,LL,n); % for cycloid
% points to outer create circle
x = c(1) + R*sin(t);
y = c(2) + R*cos(t);
% points to create core circle
xc = c(1) + r1*sin(t);
yc = c(2) + r1*cos(t);
% points to create inner circle
c1 = [r1+r2 0];
xi = c1(1) + r1*sin(t);
yi = c1(2) + r1*cos(t);
% points to create smaller inner circle
c11 = [R-r3 0];
xi1 = c11(1) + r3*sin(t);
yi1 = c11(2) + r3*cos(t);
% tracing point
c123 = [R 0];
x123 = c123(1) + r4*sin(t);
y123 = c123(2) + r4*cos(t);
% equations of motions for inner circle hypocycloid
xh = (R - r2) * cos(t) + r2 * cos((R - r2) * t / r2);
yh = (R - r2) * sin(t) - r2 * sin((R - r2) * t / r2);
% equations of motions for smaller circle hypocycloid
xh1 = (R - r3) * cos(t) + r3 * cos((R - r3) * t / r3);
yh1 = (R - r3) * sin(t) - r3 * sin((R - r3) * t / r3);
% centerX = c(1)+(R - r2) * cos(t); % x-center of rolling circle
% centerY = c(2)+(R - r2) * sin(t); % y-centre of rolling circle
% centerX1 = c1(1)+(r2 - r3) * cos(t); % x-center of smaller rolling circle
% centerY1 = c1(2)+(r2 - r3) * sin(t); % y-centre of smaller rolling circle
plot(x,y,'r') %plotting outer circle
hold on
plot(xc,yc,'g') %plotting core circle
hold on
h = plot(xi,yi,'b'); %plotting inner circle
hold on
h1 = plot(xi1,yi1,'m'); %plotting smaller inner circle
hold on
h2 = plot(x123,y123,'k');
hold on
g = animatedline('Color','k'); % animateed line for hypocycloid
g1 = animatedline('Color','m'); % animateed line for hypocycloid
% c2 = [centerX;centerY]; % centre of rolling circle
% c3 = [centerX1;centerY1]; % centre of smaller rolling circle
for q = 2:length(t)
centerX = c(1)+(R - r2) * cos(t); % x-center of rolling circle
centerY = c(2)+(R - r2) * sin(t); % y-centre of rolling circle
centerX1 = c1(1)+(r2 - r3) * cos(t); % x-center of smaller rolling circle
centerY1 = c1(2)+(r2 - r3) * sin(t); % y-centre of smaller rolling circle
c2 = [centerX;centerY]; % centre of rolling circle
c3 = [centerX1;centerY1];
centerX1 = centerX1(q);
centerY1 = centerY1(q);
% equation of inner circle for change of path
x11 = c2(1,q)+ r2*sin(t);
y11 = c2(2,q) + r2*cos(t);
hold on;
% x21 = c2(1,q)+ r2*sin(t);
% y21 = c2(2,q) + r2*cos(t);
% hold on;
% equation of small inner circle for change of path
x12 = c3(1,q)+ r3*sin(t);
y12 = c3(2,q) + r3*cos(t);
hold on;
% x22 = c3(1,q)+ r3*sin(t);
% y22 = c3(2,q) + r3*cos(t);
% hold on;
set(h,'XData',x11,'YData',y11) ; % animation of inner circle
% set(h,'XData',x21,'YData',y21) ;
set(h1,'XData',x12,'YData',y12) ; % animation of small inner circle
% set(h1,'XData',x22,'YData',y22) ;
axis([-4 4 -4 4])
% animation of hypocycloid path
% addpoints(g,xh(q),yh(q))
% addpoints(g1,xh1(q),yh1(q))
drawnow
end
axis equal

2 Comments
Dyuman Joshi
on 13 Jul 2023
What does the radius r4 correspond to?
Kushal Bollempalli
on 13 Jul 2023
Accepted Answer
More Answers (0)
Categories
Find more on Marine and Underwater Vehicles in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!