Plotting a moving circle.

8 ビュー (過去 30 日間)
Stephen Taylor
Stephen Taylor 2018 年 2 月 14 日
コメント済み: Walter Roberson 2018 年 2 月 15 日
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

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 2 月 14 日
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 件のコメント
Stephen Taylor
Stephen Taylor 2018 年 2 月 15 日
So then would viscircle be a better function to use to plot what I need then?
Walter Roberson
Walter Roberson 2018 年 2 月 15 日
Yes, viscircle sounds good.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangePolar Plots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by