Connecting a line that passes though 2 points

Extending a line - #2 by Chrisir this is the question i got the code from