There is a code that calculates the intersection point of the segments (copied it).
An error occurs that x1 - undefined
.
function d(х1, у1, х2, у2, х3, у3, х4, у4) { let x, y; x = ((x1 * y2 - x2 * y1) * (x4 - x3) - (x3 * y4 - x4 * y3) * (x2 - x1)) / ((y1 - y2) * (x4 - x3) - (y3 - y4) * (x2 - x1)); y = ((y3 - y4) * x - (x3 * y4 - x4 * y3)) / (x4 - x3); return x, y; } console.log(d(0, 0, 120, 90, 0, 60, 120, 60));