首页 文章

如何擦除填充的2D多边形,Projectile Animation?

提问于
浏览
1

我正在制作一个篮子球的抛射物 . 然而,截至目前,动画显示了球的痕迹,这是我不想要的 . 因此,我想知道如何删除以前的帧 . 问题如下图所示 .

BasketBall Projectile

如何删除跟踪 . 这是我执行此动画的函数的gui代码 .

%---在按钮按下时执行shootButton . function shootButton_Callback(hObject,eventdata,handles)%h对handleButton的句柄(参见GCBO)%eventdata reserved - 将在未来版本的MATLAB中定义%处理带句柄和用户数据的结构(参见GUIDATA)axes(handles.axes1)initialVelocity = get(handles.launchSpeed,'String'); launchAngle = get(handles.launchAngle,'String'); if(isempty(initialVelocity)|| isempty(launchAngle))fprintf('Empty Input!\ n'); h = errordlg('空输入!'); uiwait%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

1 回答

  • 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);
    

相关问题