Code covered by the BSD License
-
[width,height,x0,y0,v0,th,mu,...
This is the User Input Section of the (Billiard Table) program
-
billiard(manual_input)
-
tf=time_to_impact(width,heigh...
-
th=theta_impact(th,width,heig...
% This function recalculates the value of (Theta) depending on the impact
-
test_billiard.m
-
View all files
from
Billiard Ball Animation
by Fahad Al Mahmood
This program animates the movement of a billiard ball.
|
| tf=time_to_impact(width,height,th,mu,x0,y0,v0,e)
|
function tf=time_to_impact(width,height,th,mu,x0,y0,v0,e)
g=32.174;
Xpoly_max=[-mu*g/2*cos(th*pi/180) v0*cos(th*pi/180) x0-width];
Ypoly_max=[-mu*g/2*sin(th*pi/180) v0*sin(th*pi/180) y0-height];
Xpoly_0=[-mu*g/2*cos(th*pi/180) v0*cos(th*pi/180) x0];
Ypoly_0=[-mu*g/2*sin(th*pi/180) v0*sin(th*pi/180) y0];
Vpoly=[-mu*g v0];
A=max(roots(Xpoly_max));
B=min(roots(Xpoly_max));
C=max(roots(Ypoly_max));
D=min(roots(Ypoly_max));
E=max(roots(Xpoly_0));
F=min(roots(Xpoly_0));
G=max(roots(Ypoly_0));
H=min(roots(Ypoly_0));
tfv=roots(Vpoly);
if th>0 & th<90
DD=[A B C D tfv];
tf=min(DD);
return;
elseif th>90 & th<180
DD=[E F C D tfv];
tf=min(DD);
return;
elseif th>180 & th<270
DD=[E F G H tfv];
tf=min(DD);
return;
elseif th>270 & th<360
DD=[A B G H tfv];
tf=min(DD);
return;
elseif th==0 | th==360
DD=[A B tfv];
tf=min(DD);
return;
elseif th==90
DD=[C D tfv];
tf=min(DD);
return;
elseif th==180
DD=[E F tfv];
tf=min(DD);
return;
elseif th==270
DD=[G H tfv];
tf=min(DD);
return;
end
|
|
Contact us at files@mathworks.com