Blender Python project points around mesh

Does somebody know the algorithm or has an idea for this problem: I want to draw line (2d or 3d space) into the viewport and want to project points onto a mesh that are snapped around the covered object (line and edge loop) - here an image for better understanding:

enter image description here

The contours addon does this, but I cant really extract the algorithm from the code.