Convert a matlab function into a maxscript function

I would like to convert (if it's possible) the function "tubeplot" written in matlab language into maxscript.
You must know some Mathematics (vector, matrix) to help me to solve this problem.

See what it does here :
http://www.nada.kth.se/~asa/Ray/Tubeplot/tubeplot.html