How can I make x circles move within a space?

I've been able to make a circle move inside a rectangle with this code:
if (r(2)+R >=b)
r(2)=b-R;
v(2)=-v(2)
end
plot(r(1)+R*x,r(2)+R*y,'-b','MarkerSize',28*R)
rectangle('Position',[0,0,a,b])
axis equal
pause(dt/deltat)
end
how do I do the same thing, but with n circles?

 Accepted Answer

Use logical indexing. For example,
mask = r(2,:)+R >=b;
r(2,mask) = b-R;
v(2,,mask) = -v(2,mask);

2 Comments

and how can I create n circles?
Try viscircles if you have the Image Processing Toolbox.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB 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!