Patrick B. answered 06/20/19
Math and computer tutor/teacher
First the perpendicular line has slope that is the negative reciprocal.
so the cap has slope (x1-x2)/(y2-y1) , which is the negative reciprocal of the slope of given your line.
We now have four unknowns: x3, y3, x4, y4 where (x3,y3) and (x4,y4) are the endpoints of the cap.
So we need 4 equations.
Midpoint formula gives:
(x3 + x4)/2 = x1 ----> x3 + x4 = 2 * x1
(y3 + y4)/2 = y1 ---> y3 + y4 = 2 * y1
Distance formula gives:
( x3 - x4) ^2 + ( y3-y4)^2 = N^2
Finally the slopes are negative reciprocals of each other, so
(y4 - y3)/(x4-x3) = (x1-x2)/(y2-y1) per the formula above.
Then y4 - y3 = (x1-x2)*(x4-x3)/(y2-y1) <--- please label this equation ALPHA
Plugging this into the distance formula:
(x3-x4)^2 [ 1 + {(x1-x2)/(y2-y1)}^2 ] = N^2
So then
(x3-x4) = N/ sqrt[ 1 + {(x1-x2)/(y2-y1)}^2 ]
Adding this to the second equation gives:
2*x3 = 2*x2 + N/ sqrt[ 1 + {(x1-x2)/(y2-y1)}^2 ]
so that
x3 = x2 + (1/2) N/ sqrt[ 1 + {(x1-x2)/(y2-y1)}^2 ]
Once found, the second equation gives x4
You can then plug the values you have just calculated for x3 and x4 into the slope
equation labeled ALPHA above. That will give you a numerical value for y4 - y3
Finally, using y3 + y4 = 2*y2, you can find y3 and y4