Plot a small circle moving along a larger semi-circle
Show older comments
I draw my semi circle with this code
%Equation for semi circle
th = linspace( pi, 0, 100);
R = 1; %or whatever radius you want
x = R*cos(th);
y = R*sin(th);
%draws the semi circle
h=line(60*x,60*y,...
'Parent', axs,...
'LineWidth',2) ;
after that i draw my circle on top of semi circle with
ball=rectangle('Position',[-5,60,r_ball,r_ball],...
'Curvature',[1,1],...
'FaceColor','b',...
'Parent',axs);
the initial position of the ball is placed at the top of the semicircle in the center. the problem is the way the rectangle() determines the position of the circle. it creates the smallest square that can contain the circle and plots that. so when i use the set() to modify its position it uses one of the vertices from the square ( which is why i must use -5 offset to visually center the ball on the semi circle)
problem with this, when i continue to animate the circle along the semi circle the ball begins to clip the hemisphere once it starts to reach the ends (where Y component is 0). which makes sense due to the offset. removing the offset will of course make the ball follow completely off the hemisphere until it reaches the ends.
how would i fix this so that the edge of the ball, follows smoothly the edge of the semi circle.
Accepted Answer
More Answers (0)
Categories
Find more on 2-D and 3-D Plots 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!