Combining two codes as one

4 views (last 30 days)
DARLINGTON ETAJE
DARLINGTON ETAJE on 13 Aug 2019
Commented: dpb on 13 Aug 2019
Hello Family,
Please I need to create three circles. Challenge One: Circle 1 is small and going round on the circumference of circle 2. Challenge 2: Circle 2 is nearly as big as circle 3. Circle 2 is the inner circle with close diameter with circle 3. Circle 2 is going round inside circle 3. I have the codes for challenge One and challenge Two individually...the problem is to make the two codes work as one.
Challenge One Codes:
r=18;
R=20;
radius=[r R]
velocity=[45 0]
colors=['c','r'] % This is to just make the points different colors
p=zeros(2,1); %here we will store the handles to delete the point
hold on
for i=1:2 %Loop to create multiple circles
th=0:pi/50:2*pi;
xunit=radius(i)*cos(th);
yunit=radius(i)*sin(th);
h=plot(xunit,yunit);
p(i)=plot(xunit(1),yunit(1),'o','MarkerFaceColor',colors(i),'Color',colors(i));
%creates a point on each graph
end
time=[0:0.001:100]; %time vector in seconds
for t=1:length(time)
for i=1:2 %Loop to create multiple circles
delete(p(i)); %delete the old point
%computes the new angle for each point as velocity*time
xunit=radius(i)*cos(velocity(i)*time(t));
yunit=radius(i)*sin(velocity(i)*time(t));
%creates a point on each graph
p(i)=plot(xunit(1),yunit(1),'o','MarkerFaceColor',colors(i),'Color',colors(i));
end
pause(0.01); %wait 0.01 seconds so the plot is displayed
end
hold off
Challenge Two Codes
t = linspace(0,5*pi );
x = cos(t );
y = sin(t );
plot(7*x,7*y)
axis equal
hold on
for t0 = t
h = plot(2*sin(t0),2*cos(t0),'or ','markersize',175);
pause(0.09 )
delete(h )
axis equal
end
  5 Comments
DARLINGTON ETAJE
DARLINGTON ETAJE on 13 Aug 2019
thanks for this...please assist with the codes cos I have tried really hard and its not working
dpb
dpb on 13 Aug 2019
But you don't have any code at all that does the definition of a reference frame nor translation. Just trying to graft these two independent pieces together won't cut it for the problem you're trying to solve.
You need to read up on the geometry and algebra of translation and rotation to get the basic ideas down first. There's quite a bit of pedgogical info on graphics and robotics translation that will introduce you to the basic idea.

Sign in to comment.

Answers (0)

Categories

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