Combining two codes as one
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
dpb
le 13 Août 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.
Réponses (0)
Voir également
Catégories
En savoir plus sur Graphics Performance dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!