【问题标题】:How to erase a filled 2D polygon, Projectile Animation?如何擦除填充的 2D 多边形,Projectile Animation?
【发布时间】:2014-04-14 13:54:13
【问题描述】:

我正在制作一个篮球的弹丸。但是,到目前为止,动画显示了我不想要的球的痕迹。因此,我想知道如何删除以前的帧。下图说明了该问题。

如何删除痕迹。这是执行此动画的函数的 gui 代码。

% --- 在 shootButton 中按下按钮时执行。 函数 shootButton_Callback(hObject, eventdata, 句柄) % hObject 到 shootButton 的句柄(见 GCBO) % eventdata reserved - 将在未来版本的 MATLAB 中定义 % 使用句柄和用户数据处理结构(参见 GUIDATA) 轴(handles.axes1) initialVelocity = get(handles.launchSpeed,'String'); launchAngle = get(handles.launchAngle,'String'); if(isempty(initialVelocity) || isempty(launchAngle)) fprintf('空输入!\n'); h = errordlg('空输入!'); 等待 %playButton_Callback(hObject,eventdata,handles) 返回 结束

 initialVelocity = str2num(initialVelocity);
 launchAngle = str2num(launchAngle);

 if(isempty(initialVelocity) || isempty(launchAngle))
   fprintf('Wrong Input Format!\n');
  h = errordlg('Wrong Input Format!');
  uiwait
 %playButton_Callback(hObject,eventdata,handles)
 return
else
fprintf('launchAngle %d\n',launchAngle)
fprintf('launchSpeed %d\n',initialVelocity)
end
launchAngle = launchAngle*pi/180;

%the basket coordinates
a = 2.3;%The actual basket radius
b = 1.1;  %vertical radius, Primarily used to create the oval shape. In reality the     basket is a circle with a radius of 2.3
x0 = 96.7;%The translation in the x direction to get the basket to the backboard     location
y0 = 55;%The y translation to get the basket to the backboard location
t = linspace(0,2*pi);     
basketX = x0 + a*cos(t);
basketY = y0 + b*sin(t);

%Ball Coordinates
ball = [sin(-pi:0.001:pi);cos(-pi:0.001:pi)];%Basketball coordinates
scale = 2;%This is to make the ball an appropriate size in comparison to the basket
%These are the translations to place the ball in the players hand
transX = 9;
transY = 14;
ball = [ball(1,:)*scale + transX;ball(2,:)*scale + transY];

%square inside the basketball for rotation purposes
square = [-1 1 1 -1;-1 -1 1 1];
%square = [square(1,:)+transX; square(2,:)+transY];

%Begining the projectile of the basketball
yInitial = min(ball(2,:));
disp(yInitial);
t = 0;%time
g = 9.81;%gravity
i = 1;
transX = 9;
transY = 14;
while(1)
   t = t + .1;
   xPos = initialVelocity*t*cos(launchAngle)
   yPos = yInitial + initialVelocity*t*sin(launchAngle) - g*(t*t)/2

  beta = 45*pi/180*i;
 i = i+ 1;
 rotationFactorX = [cos(beta),-sin(beta)];
 rotationFactorY = [sin(beta),cos(beta)];


 rotatedSquare = [rotationFactorX*square;rotationFactorY*square];


 fill(ball(1,:)+xPos, ball(2,:) + yPos,'r');
  hold on
 fill(rotatedSquare(1,:)+transX+xPos,rotatedSquare(2,:)+transY+yPos,'y')
 hold on
 pause(.00001)


 end

【问题讨论】:

    标签: matlab matlab-figure matlab-guide


    【解决方案1】:

    你试过delete吗?

    ballHandler = fill(ball(1,:)+xPos, ball(2,:) + yPos,'r');
    hold on
    squareHandler = fill(rotatedSquare(1,:)+transX+xPos,rotatedSquare(2,:)+transY+yPos,'y')
    hold on
    pause(.00001)
    delete(ballHandler);
    delete(squareHandler);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-04
      • 1970-01-01
      • 2014-01-01
      • 2014-02-03
      • 1970-01-01
      • 2014-09-28
      相关资源
      最近更新 更多