WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

animation durch for-schleife

 

vnecked
Forum-Anfänger

Forum-Anfänger


Beiträge: 10
Anmeldedatum: 21.03.11
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 10.04.2011, 13:57     Titel: animation durch for-schleife
  Antworten mit Zitat      
hallo:)
hätte da ne einfache frage
und zwar: ich brauch eine animation mit einer for schleife..

wie komme ich von dieser ausgangsposition

Code:
% Erster Arm --> x1,x2 und y1,y2 stehen f�r Punkt P
 x1=0;  x2=60*cos(2);
 y1=0;  y2=60*sin(2);
 x=[x1 x2]; y=[y1 y2];
 plot(x,y,'LineWidth',2)
 hold on
 
 % Zweiter Arm--> x2,x3 und y2,y3 sind Koordinaten f�r Punkt Q
 x2=60*cos(2);   x3=60*cos(2)-60*cos(2+0.7);
 y2=60*sin(2);   y3=60*sin(2)-60*sin(2+0.7);
 x=[x2 x3]; y=[y2 y3];
 plot(x,y, 'LineWidth', 2)
 hold on





auf diese position
Code:
%Erster Arm --> x1,x2 und y1,y2 stehen f�r Punkt P
 x1=0;  x2=60*cos(1.4);
 y1=0;  y2=60*sin(1.4);
 x=[x1 x2]; y=[y1 y2];
 plot(x,y,'LineWidth',2)
 hold on
 
 % Zweiter Arm--> x2,x3 und y2,y3 sind Koordinaten f�r Punkt Q
 x2=60*cos(1.4);   x3=60*cos(1.4)-60*cos(1.4+1.4);
 y2=60*sin(1.4);   y3=60*sin(1.4)-60*sin(1.4+1.4);
 x=[x2 x3]; y=[y2 y3];
 plot(x,y, 'LineWidth', 2)
 hold on
 



durch eine for schleife? :S kann mir da jemand helfen?
wäre sehr dankbar!!
Private Nachricht senden Benutzer-Profile anzeigen


Jan S
Moderator

Moderator


Beiträge: 11.057
Anmeldedatum: 08.07.10
Wohnort: Heidelberg
Version: 2009a, 2016b
     Beitrag Verfasst am: 12.04.2011, 00:35     Titel: Re: animation durch for-schleife
  Antworten mit Zitat      
Hallo vnecked,
Das läßt sich noch kompakter formulieren. Vielleicht meinst Du so etwas mit "durch eine FOR-Schleife":
Code:
H = [];
a = linspace(2, 1.4, 100);
b = linspace(0.7, 1.4, 100);
for i = 1:100
   x = [0,  60 * cos(a(i)), 60 * cos(a(i)) - 60 * cos(a(i) + b(i))];
   y = [0,  60 * sin(a(i)),  60 * sin(a(i)) - 60 * sin(a(i) + b(i))];
   if isempty(H)
     H = plot(x, y, 'LineWidth', 2);
   else
     set(H, 'XData', x, 'YData', y);
   end
end
 

Gruß, Jan
Private Nachricht senden Benutzer-Profile anzeigen
 
vnecked
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 10
Anmeldedatum: 21.03.11
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 12.04.2011, 10:31     Titel:
  Antworten mit Zitat      
danke:) jetzt versteh ich endlich das prinzip der forschleife in matlab!! Smile
Private Nachricht senden Benutzer-Profile anzeigen
 
vnecked
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 10
Anmeldedatum: 21.03.11
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 17.04.2011, 14:12     Titel:
  Antworten mit Zitat      
ok hab gedacht es funktioniert so..
aber leider bewegt sich gar nichts wenn ich den quellcode ausführen lasse :S
ich bekomm das einfach nicht gebacken:D
die aufgabenstellung war die 4 postionen der arme darzustellen..
und hab dann auch ne animation hinbekommen..allerdings ohne forschleife..
kann mir das jemand genau erklären? :S
Private Nachricht senden Benutzer-Profile anzeigen
 
vnecked
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 10
Anmeldedatum: 21.03.11
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 17.04.2011, 14:13     Titel:
  Antworten mit Zitat      
Code:
%Aufgabe 1 : Roboterarm 17.03.11
 
 
 %AUSGANGSPOSITION
 
 %Boden
 plot([-20 80], [0 0],'k', 'LineWidth', 4)
 hold on
 
 % Erster Arm --> x1,x2 und y1,y2 stehen f�r Punkt P
 x1=0;  x2=60*cos(1.847);
 y1=0;  y2=60*sin(1.847);
 x=[x1 x2]; y=[y1 y2];
 plot(x,y,'LineWidth',2)
 hold on
 
 % Zweiter Arm--> x2,x3 und y2,y3 sind Koordinaten f�r Punkt Q
 x2=60*cos(1.847);   x3=60*cos(1.847)-60*cos(1.847+0.34787);
 y2=60*sin(1.847);   y3=60*sin(1.847)-60*sin(1.847+0.34787);
 x=[x2 x3]; y=[y2 y3];
 plot(x,y, 'LineWidth', 2)
 hold on

 % Kugel Einheitskreis
 r=5;   x=20;  y=(60*sin(1.847)-60*sin(1.847+0.34787))/2;
 n=100;
 phi=linspace(0,2*pi,n+1);
 fill(x+r*cos(phi),y+r*sin(phi),'r')
 hold on
 
 % Viereck
 fill([45 55 55 45],[0 0 25 25],'g');
 plot([45 55 55 45],[0 0 25 25],'k','LineWidth',1);
 hold on

 % Kreisb�gen f�r Winkel aplha und beta
 % alpha
 r=5;   x=0;    y=0;
 n=100;
 alpha1=pi/25;   alpha2=5*pi/8;
 phi=linspace(alpha1,alpha2,n+1);
 plot(x+r*cos(phi),y+r*sin(phi),'k')
 text(0.5,2.5,'\alpha')
 hold on
 % beta
 r=10.5;   x=60*cos(1.847);    y=60*sin(1.847);
 n=100;
 alpha1=12.5*pi/8;   alpha2=13.8*pi/8;
 phi=linspace(alpha1,alpha2,n+1);
 plot(x+r*cos(phi),y+r*sin(phi),'k')
 text(60*cos(1.847)+2,60*sin(1.847)-6,'\beta')
 hold on
 
 text(10,63,'alpha = 1.847    beta = 0.37487')
 
 
 
 %--------------------------------------------------------------------
 
 % Zweites Bild mit Winkel alpha=2 , beta=0.7
 
 % Erster Arm --> x1,x2 und y1,y2 stehen f�r Punkt P
 x1=0;  x2=60*cos(2);
 y1=0;  y2=60*sin(2);
 x=[x1 x2]; y=[y1 y2];
 plot(x,y,'LineWidth',2)
 hold on
 
 % Zweiter Arm--> x2,x3 und y2,y3 sind Koordinaten f�r Punkt Q
 x2=60*cos(2);   x3=60*cos(2)-60*cos(2+0.7);
 y2=60*sin(2);   y3=60*sin(2)-60*sin(2+0.7);
 x=[x2 x3]; y=[y2 y3];
 plot(x,y, 'LineWidth', 2)
 hold on

 % Kugel Einheitskreis
 r=5;   x=60*cos(2)-60*cos(2+0.7);  y=(60*sin(2)-60*sin(2+0.7)-5);
 n=100;
 phi=linspace(0,2*pi,n+1);
 fill(x+r*cos(phi),y+r*sin(phi),'r')
 hold on
 
 % Kreisb�gen f�r Winkel aplha und beta
 % alpha
 r=5;   x=0;    y=0;
 n=100;
 alpha1=pi/25;   alpha2=5*pi/8;
 phi=linspace(alpha1,alpha2,n+1);
 plot(x+r*cos(phi),y+r*sin(phi),'k')
 text(0.5,2.5,'\alpha')
 hold on
 % beta
 r=8;   x=60*cos(2);    y=60*sin(2);
 n=100;
 alpha1=13*pi/8;   alpha2=15*pi/8;
 phi=linspace(alpha1,alpha2,n+1);
 plot(x+r*cos(phi),y+r*sin(phi),'k')
 text(60*cos(1.847)-5,60*sin(1.847)-7,'\beta')
 hold on
 
 text(10,63,'alpha = 2    beta = 0.7')
 
 %--------------------------------------------------------------------
 
 %Drittes Bild mit Winkel alpha=1. , beta=1.4
 
 %Erster Arm --> x1,x2 und y1,y2 stehen f�r Punkt P
 x1=0;  x2=60*cos(1.4);
 y1=0;  y2=60*sin(1.4);
 x=[x1 x2]; y=[y1 y2];
 plot(x,y,'LineWidth',2)
 hold on
 
 % Zweiter Arm--> x2,x3 und y2,y3 sind Koordinaten f�r Punkt Q
 x2=60*cos(1.4);   x3=60*cos(1.4)-60*cos(1.4+1.4);
 y2=60*sin(1.4);   y3=60*sin(1.4)-60*sin(1.4+1.4);
 x=[x2 x3]; y=[y2 y3];
 plot(x,y, 'LineWidth', 2)
 hold on

 % Kugel Einheitskreis
 r=5;   x=60*cos(1.4)-60*cos(1.4+1.4);  y=(60*sin(1.4)-60*sin(1.4+1.4))-5;
 n=100;
 phi=linspace(0,2*pi,n+1);
 fill(x+r*cos(phi),y+r*sin(phi),'r')
 hold on
 
 % Kreisb�gen f�r Winkel aplha und beta
 % alpha
 r=5;   x=0;    y=0;
 n=100;
 alpha1=pi/25;   alpha2=5.5*pi/12;
 phi=linspace(alpha1,alpha2,n+1);
 plot(x+r*cos(phi),y+r*sin(phi),'k')
 text(0.5,2.5,'\alpha')
 hold on
 % beta
 r=8;   x=60*cos(1.4);    y=60*sin(1.4);
 n=100;
 alpha1=11.5*pi/8;   alpha2=15*pi/8;
 phi=linspace(alpha1,alpha2,n+1);
 plot(x+r*cos(phi),y+r*sin(phi),'k')
 text(60*cos(1.4)+1.5,60*sin(1.4)-3,'\beta')
 hold on
 
 text(10,63,'alpha = 1.4    beta = 1.4')
 
 %--------------------------------------------------------------------
 
 %Viertes Bild mit Winkel alpha=0.95844 , beta=1.4734
 
 %Erster Arm --> x1,x2 und y1,y2 stehen f�r Punkt P
 x1=0;  x2=60*cos(0.95844);
 y1=0;  y2=60*sin(0.95844);
 x=[x1 x2]; y=[y1 y2];
 plot(x,y,'LineWidth',2)
 hold on
 
 % Zweiter Arm--> x2,x3 und y2,y3 sind Koordinaten f�r Punkt Q
 x2=60*cos(0.95844);   x3=60*cos(0.95844)-60*cos(0.95844+1.4734);
 y2=60*sin(0.95844);   y3=60*sin(0.95844)-60*sin(0.95844+1.4734);
 x=[x2 x3]; y=[y2 y3];
 plot(x,y, 'LineWidth', 2)
 hold on

 % Kugel Einheitskreis
 r=5;   x=60*cos(0.95844)-60*cos(0.95844+1.4734);  y=(60*sin(0.95844)-60*sin(0.95844+1.4734))-5;
 n=100;
 phi=linspace(0,2*pi,n+1);
 fill(x+r*cos(phi),y+r*sin(phi),'r')
 hold on
 
 % Kreisb�gen f�r Winkel aplha und beta
 % alpha
 r=8;   x=0;    y=0;
 n=100;
 alpha1=pi/15;   alpha2=4*pi/12;
 phi=linspace(alpha1,alpha2,n+1);
 plot(x+r*cos(phi),y+r*sin(phi),'k')
 text(2.5,2.5,'\alpha')
 hold on
 % beta
 r=8;   x=60*cos(0.95844);    y=60*sin(0.95844);
 n=100;
 alpha1=10.5*pi/8;   alpha2=14*pi/8;
 phi=linspace(alpha1,alpha2,n+1);
 plot(x+r*cos(phi),y+r*sin(phi),'k')
 text(60*cos(0.95844),60*sin(0.95844)-3,'\beta')
 hold on
 
 text(10,63,'alpha = 0.95844    beta = 1.4734')
 
 axis equal
 
 
  % Erster Arm --> x1,x2 und y1,y2 stehen f�r Punkt P
 x1=0;  x2=60*cos(1.847);
 y1=0;  y2=60*sin(1.847);
 x=[x1 x2]; y=[y1 y2];
 plot(x,y,'LineWidth',2)
 hold on
 
 % Zweiter Arm--> x2,x3 und y2,y3 sind Koordinaten f�r Punkt Q
 x2=60*cos(1.847);   x3=60*cos(1.847)-60*cos(1.847+0.34787);
 y2=60*sin(1.847);   y3=60*sin(1.847)-60*sin(1.847+0.34787);
 x=[x2 x3]; y=[y2 y3];
 plot(x,y, 'LineWidth', 2)
 hold on
Private Nachricht senden Benutzer-Profile anzeigen
 
vnecked
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 10
Anmeldedatum: 21.03.11
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 17.04.2011, 14:49     Titel:
  Antworten mit Zitat      
Code:
%Aufgabe 1 : Roboterarm 17.03.11
%AUSGANGSPOSITION

% Viereck
 fill([45 55 55 45],[0 0 25 25],'g');
 plot([45 55 55 45],[0 0 25 25],'k','LineWidth',1);
 hold on
 
 %Boden
 plot([-20 80], [0 0],'k', 'LineWidth', 4)
 hold on

 
  % Erster Arm --> x1,x2 und y1,y2 stehen f�r Punkt P
  for i = 1.847:2
 x1=0;  x2=60*cos(i);
 y1=0;  y2=60*sin(i);
 x=[x1 x2]; y=[y1 y2];
 plot(x,y,'LineWidth',2)
 axis equal
 
 hold on
 
 end
 
 


hab grad mal probiert eine bewegung zu animieren..aber es passiert einfach nichts :S
Private Nachricht senden Benutzer-Profile anzeigen
 
Jan S
Moderator

Moderator


Beiträge: 11.057
Anmeldedatum: 08.07.10
Wohnort: Heidelberg
Version: 2009a, 2016b
     Beitrag Verfasst am: 19.04.2011, 12:20     Titel: Re: animation durch for-schleife
  Antworten mit Zitat      
Hallo vnecked,
Ich habe in meinem obigen Beispiel vergessen, den Bildschirm updaten zulassen. => DRAWNOW.
Code:
H = [];
a = linspace(2, 1.4, 100);
b = linspace(0.7, 1.4, 100);
for i = 1:100
   x = [0,  60 * cos(a(i)), 60 * cos(a(i)) - 60 * cos(a(i) + b(i))];
   y = [0,  60 * sin(a(i)),  60 * sin(a(i)) - 60 * sin(a(i) + b(i))];
   if isempty(H)
     H = plot(x, y, 'LineWidth', 2);
   else
     set(H, 'XData', x, 'YData', y);
   end
   drawnow;  % EDITED
end
 

Gruß, Jan
Private Nachricht senden Benutzer-Profile anzeigen
 
vnecked
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 10
Anmeldedatum: 21.03.11
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 19.04.2011, 14:45     Titel:
  Antworten mit Zitat      
Code:

H = [];
a = linspace(1.847, 2, 100);
b = linspace(0.37487, 0.7, 100);

for i1 = 1:100
   x = [0,  60 * cos(a(i1)), 60 * cos(a(i1)) - 60 * cos(a(i1) + b(i1))];
   y = [0,  60 * sin(a(i1)),  60 * sin(a(i1)) - 60 * sin(a(i1) + b(i1))];
   if isempty(H)
     H = plot(x, y, 'LineWidth', 2);  
   else
     set(H, 'XData', x, 'YData', y);
   end
     axis([-30 100 -30 100])
   drawnow;  % EDITED
end
 
u = [];
c = linspace(2, 1.4, 100);
d = linspace(0.7, 1.4, 100);
for i2 = 1:100
   x = [0,  60 * cos(c(i2)), 60 * cos(c(i2)) - 60 * cos(c(i2) + d(i2))];
   y = [0,  60 * sin(c(i2)),  60 * sin(c(i2)) - 60 * sin(c(i2) + d(i2))];
   if isempty(u)
     u = plot(x, y, 'LineWidth', 2);
   else
     set(u, 'XData', x, 'YData', y);
   end
     axis([-30 100 -30 100])
   drawnow;  % EDITED
  hold off
end


K = [];
e = linspace(1.4, 0.95844, 100);
f = linspace(1.4, 1.4734, 100);
for i3 = 1:100
   x = [0,  60 * cos(e(i3)), 60 * cos(e(i3)) - 60 * cos(e(i3) + f(i3))];
   y = [0,  60 * sin(e(i3)),  60 * sin(e(i3)) - 60 * sin(e(i3) + f(i3))];
   if isempty(K)
     k = plot(x, y, 'LineWidth', 2);
   else
     set(k, 'XData', x, 'YData', y);
   end
     axis([-30 100 -30 100])
   drawnow;  % EDITED
end
 
 




habs jetzt mal in 3 schleifen gepackt:D keine ahnung wies in 1er funktioniert..aufjedenfall klappts jetzt...

jetzt bräucht ich noch diese beiden elemente..die müssen in der animation die ganze zeit vorhanden sein




Code:

 % Viereck
 fill([45 55 55 45],[0 0 25 25],'g');
 plot([45 55 55 45],[0 0 25 25],'k','LineWidth',1);
 hold on
  %Boden
 plot([-30 100], [0 0],'k', 'LineWidth', 4)
hold on

 


wie bekomm ich das am besten hin?
Private Nachricht senden Benutzer-Profile anzeigen
 
Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.
Du kannst Dateien in diesem Forum posten
Du kannst Dateien in diesem Forum herunterladen
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2025 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.