Plotting a moving circle.

조회 수: 6 (최근 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 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