Have you tried asking our friend Google?
Anyway, my search returns in the top five result this MATLAB script which looks fairly promising.
If you need help programming something like this, I would suggest looking into programming help on _ray tracing_ , since the mathematics of tracing a billiard trajectory is basically the same.