Hi, I’ve been trying to draw a blue line like the one shown in the image that passes through 2 given points (red points) and ends as soon as it touches the black line (which i know the x position of but I dont know the y position of the green point). I managed to get the line to pass through both points by using the code below as an example. However the line continues going till the end of the page (like the dotted blue part) and when I change the x position to the one I want it to be, the line shifts completely like the yellow line in the picture and stops passing from the red points. I’m not sure what I need to do to keep it passing through the two red points but stopping at the x position I want it to stop at. (green point)
x1 //first circle's x
y1 //first circle's y
x2 //second circle's x
y2 //second circle's y
//draw a line from top to bottom if the line is vertical, prevents division by 0
if x1 == x2
line(x1, 0, x1, height)
return
m = (y2 - y1) / (x2 - x1) // rise / run, gives us the line slope
b = y1 - m * x1 // solves offset by assuming it's 0 and accounting for the error at X=x1
line(0, b, width, m * width + b) //draw a line starting at (0, f(0)) and ending at (width, f(width)) for the line equation