Plotting a moving circle.
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I need a circle to follow the end of a line to represent a wheel. However when I plot the center of the circle to be farther down but still revolving around xr3 and yr3 it shifts the center of the revolving radius to another point higher up than what is specified.
xr3=-10
yr3=0
r4m=linspace(degtorad(theta4),3*pi/2,100)
thetawl1=(r4+2)*cos(r4m)+xr3
thetawl2=(r4+2)*sin(r4m)+yr3
xcircle=(r4+5)*cos(r4m)+xr3
ycircle=(r4+5)*sin(r4m)+yr3
for i=1:1:length(r4m)
plot([xr3,thetawl1(i)],[yr3,thetawl2(i)],'r-')
hold on
wheel=rectangle('Position',[xcircle(i) ycircle(i) 6 6],'Curvature',[1,1],'LineWidth',10)
hold off
axis equal
axis ([-15 10 -20 5])
getframe
end
0 commentaires
Réponses (1)
Walter Roberson
le 14 Fév 2018
We recommend against plotting and replotting within a loop. We recommend that you instead build the graphics objects before the loop, and then in the loop, update the properties of the graphics objects. Or sometimes it is easier to write, for example:
xr3=-10
yr3=0
r4m=linspace(degtorad(theta4),3*pi/2,100)
thetawl1=(r4+2)*cos(r4m)+xr3
thetawl2=(r4+2)*sin(r4m)+yr3
xcircle=(r4+5)*cos(r4m)+xr3
ycircle=(r4+5)*sin(r4m)+yr3
for i=1:1:length(r4m)
if i == 1
L1 = plot([xr3,thetawl1(i)],[yr3,thetawl2(i)],'r-')
hold on
wheel = rectangle('Position',[xcircle(i) ycircle(i) 6 6],'Curvature',[1,1],'LineWidth',10)
hold off
axis equal
axis ([-15 10 -20 5])
else
set(L1, 'XData', [xr3,thetawl1(i)], 'YData', [yr3,thetawl2(i)]);
set(wheel, 'Position', [xcircle(i) ycircle(i) 6 6]);
end
getframe
end
6 commentaires
Voir également
Catégories
En savoir plus sur Polar Plots 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!