⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 draw2.m

📁 为了下载东西
💻 M
字号:
%
%  Syntax:  draw(X,Phi,hCart,hBall)
%
%  Inputs:  X is a scalar specifying the cart's position in [m].  
%           Phi is a scalar specifying the ball's angular deviation in [rad].
%
%  Result:  Altered basic draw-routine.  The draw is now differential so that
%           the cart is not drawn from scratch but moved.  Similar is available
%           for the ball but not used at the moment.
%
%           Hordur Kvaran, 03.12.97
%
function draw2(X,Phi,hCart,hBall)

%
%  Define the width and height of the cart, the ball radius and the radius
%  of curvature for the rails:
%
W = 0.35; H = 0.05; R = 0.055; Rcurvature = 0.50;
numCircle = 20;
%

% Update the cart coordinates

CartNodeX = get(hCart,'Xdata');
%CartNodeY = get(hCart,'Ydata');
Xold = get(hCart,'UserData');
CartNodeX=CartNodeX+X-Xold;

% Update the ball coordinates

%Code to update without rolling
%BallNodeX = get(hBall,'Xdata');
%BallNodeY = get(hBall,'Ydata');
%PhiOld = get(hBall,'UserData');
%BallNodeX = BallNodeX + (X+(Rcurvature+W/2)*tan(Phi)) - (Xold+(Rcurvature+W/2)*tan(PhiOld));
%BallNodeY = BallNodeY + (H+R-Rcurvature*(1-cos(Phi))+(H/2)*cos(Phi)) - (H+R-Rcurvature*(1-cos(PhiOld))+(H/2)*cos(PhiOld));

BallNodeX = ones(1,numCircle+2) * ( X + (Rcurvature + W/2)*tan(Phi));
BallNodeY = ones(1,numCircle+2) * ( H + R - Rcurvature*(1-cos(Phi)) + (H/2)*cos(Phi));
Roll = Rcurvature*tan(Phi)/(2*pi*R)*2*pi;   % X distance traveled due to roll.  
for i = 0:numCircle,
   BallNodeX(i+2) = BallNodeX(i+2) + R*sin(Roll+i*2*pi/numCircle);
   BallNodeY(i+2) = BallNodeY(i+2) + R*cos(Roll+i*2*pi/numCircle);
end

%
%  Assign new coordinates to the cart/ball patch objects, and redraw:
%  Note that precisely this method seems to be the fastest way to update
%  the display.  This is used in Matlab's Simulink animation demos.
%
set(hCart,'Xdata',CartNodeX);%,'Ydata',CartNodeY);
set(hBall,'Xdata',BallNodeX,'Ydata',BallNodeY);
drawnow;

% A necessary evil because of Matlab 4.  If this goes with the update for Xdata and Ydata
% the animation disappears.
set(hCart,'UserData',X);
%set(hBall,'UserData',Phi);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -