Clean up line intersection function
This commit is contained in:
@@ -529,10 +529,13 @@
|
|||||||
return edge || actualCorner;
|
return edge || actualCorner;
|
||||||
}
|
}
|
||||||
|
|
||||||
function lineIntxnPt({ x1, y1, x2, y2 }, {x1: x3, y1: y3, x2: x4, y2: y4 }) {
|
function lineIntxnPt({ x1, y1, x2, y2 }, { x1: x3, y1: y3, x2: x4, y2: y4 }) {
|
||||||
// https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection#Given_two_points_on_each_line
|
// https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection#Given_two_points_on_each_line
|
||||||
const x = ((x1*y2-y1*x2)*(x3-x4)-(x1-x2)*(x3*y4-y3*x4))/((x1-x2)*(y3-y4)-(y1-y2)*(x3-x4));
|
const denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
|
||||||
const y = ((x1*y2-y1*x2)*(y3-y4)-(y1-y2)*(x3*y4-y3*x4))/((x1-x2)*(y3-y4)-(y1-y2)*(x3-x4));
|
const l1Det = x1 * y2 - y1 * x2;
|
||||||
|
const l2Det = x3 * y4 - y3 * x4;
|
||||||
|
const x = (l1Det * (x3 - x4) - (x1 - x2) * l2Det) / denominator;
|
||||||
|
const y = (l1Det * (y3 - y4) - (y1 - y2) * l2Det) / denominator;
|
||||||
|
|
||||||
return { x: x, y: y };
|
return { x: x, y: y };
|
||||||
}
|
}
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
Reference in New Issue
Block a user