Plotting a moving circle.

6 次查看(过去 30 天)
Stephen Taylor
Stephen Taylor 2018-2-14
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 CenterFile Exchange 中查找有关 Polar Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by