Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function lineEquation(ax, ay, bx, by) {
- const dx = bx - ax
- const dy = by - ay
- const k = dx === 0 ? 0 : dy / dx
- const n = -ax * k + ay
- return n === 0
- ? `y = ${k}x`
- : `y = ${k}x ${n < 0 ? '-' : '+'} ${Math.abs(n)}`
- }
- function lineIntersection(L1, L2) {
- const den = (L1[0].x - L1[1].x) * (L2[0].y - L2[1].y) - (L1[0].y - L1[1].y) * (L2[0].x - L2[1].x)
- if (den === 0) return 'No intersection'
- const X = ((L1[0].x * L1[1].y - L1[0].y * L1[1].x) * (L2[0].x - L2[1].x) - (L1[0].x - L1[1].x) * (L2[0].x * L2[1].y - L2[0].y * L2[1].x)) / den
- const Y = ((L1[0].x * L1[1].y - L1[0].y * L1[1].x) * (L2[0].y - L2[1].y) - (L1[0].y - L1[1].y) * (L2[0].x * L2[1].y - L2[0].y * L2[1].x)) / den
- return `x: ${X}, y: ${Y}`
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement