does anybody know how CAD exports 3D models to stl fromat?....

I need to know the algorithm it uses to do this, or even the base code if possible!

Thanks