I am making a projectile of a basket ball. However, as of now, the animation shows the traces of the ball, which I do not want. Hence, I am wondering how to delete the previous frames. The issue is illustrated in the following picture.
How do I delete the traces. Here is my gui code for the function that does this animation.
% --- Executes on button press in shootButton. function shootButton_Callback(hObject, eventdata, handles) % hObject handle to shootButton (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see 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('Empty Input!'); uiwait %playButton_Callback(hObject,eventdata,handles) return end
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