getIntersectPoint method
- Line other
Get Intersect point of this line and another line
Implementation
Point? getIntersectPoint(Line other) {
final x1 = a.x;
final x2 = b.x;
final x3 = other.a.x;
final x4 = other.b.x;
final y1 = a.y;
final y2 = b.y;
final y3 = other.a.y;
final y4 = other.b.y;
final denom = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
if (denom == 0) return null;
final t = ((x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)) / denom;
final s = -((x1 - x2) * (y1 - y3) - (y1 - y2) * (x1 - x3)) / denom;
if (t >= 0 && t <= 1 && s >= 0 && s <= 1) {
return Point(x1 + t * (x2 - x1), y1 + t * (y2 - y1));
} else {
return null;
}
}