//calculate the point of intersection between two line segments public Point2D Intersection(Line2D L, out bool found) { var pt = new Point2D(0.0, 0.0); var a = P1; var b = P2; var c = L.P1; var d = L.P2; var rTop = (a.y - c.y)*(d.x - c.x) - (a.x - c.x)*(d.y - c.y); var rBot = (b.x - a.x)*(d.y - c.y) - (b.y - a.y)*(d.x - c.x); var sTop = (a.y - c.y)*(b.x - a.x) - (a.x - c.x)*(b.y - a.y); var sBot = (b.x - a.x)*(d.y - c.y) - (b.y - a.y)*(d.x - c.x); if ((rBot == 0 || sBot == 0)) { found = false; return pt; } var r = rTop/rBot; var s = sTop/sBot; if ((r > 0) && (r < 1) && (s > 0) && (s < 1)) { pt.x = a.x + r*(b.x - a.x); pt.y = a.y + r*(b.y - a.y); found = true; return pt; } found = false; return pt; }
public Line2D(Line2D other) { P1 = other.P1; P2 = other.P2; }