Code covered by the BSD License  

Highlights from
Billiard Ball Animation

image thumbnail
from Billiard Ball Animation by Fahad Al Mahmood
This program animates the movement of a billiard ball.

th=theta_impact(th,width,height,x0,y0)
%
%   This function recalculates the value of (Theta) depending on the impact
%   location
%
%
function th=theta_impact(th,width,height,x0,y0)
if th>0 & th<90
    if x0>=width
        th=180-th;
        return;
    elseif y0>=height
        th=360-th;
        return;
    end
elseif th>90 & th<180
    if x0<=0
        th=180-th;
        return;
    elseif y0>=height
        th=360-th;
        return;
    end
elseif th>180 & th<270
    if x0<=0
        th=540-th;
        return;
    elseif y0<=0
        th=360-th;
        return;
    end
elseif th>270 & th<360
    if x0>=width
        th=540-th;
        return;
    elseif y0<=0
        th=360-th;
        return;
    end
elseif th==0 | th==360
    th=180;
    return;
elseif th==90
    th=270;
    return;
elseif th==180
    th=0;
    return;
elseif th==270
    th=90;
    return;
end

Contact us at files@mathworks.com