public EdgeIntersectionResult CalculateIntersection(NavigationEdge other) { var result = new EdgeIntersectionResult(); var dx12 = this.B.X - this.A.X; var dy12 = this.B.Y - this.A.Y; var dx34 = other.B.X - other.A.X; var dy34 = other.B.Y - other.A.Y; var denominator = dy12 * dx34 - dx12 * dy34; if (denominator == 0) { return(result); } // normally t1 is 0 -> 1 (or no hit), but for us it's 0 -> 1 var t1 = ((this.A.X - other.A.X) * dy34 + (other.A.Y - this.A.Y) * dx34) / denominator; result.LinesIntersect = true; // normally t1 is 0 -> 1 (or no hit), but for us it's 0 -> 1 var t2 = ((other.A.X - this.A.X) * dy12 + (this.A.Y - other.A.Y) * dx12) / -denominator; // result.IntersectionPoint = new DeterministicVector2(this.A.X + dx12 * t1, this.A.Y + dy12 * t1); result.SegmentsIntersect = t1 >= 0 && t1 <= 1 && t2 >= 0 && t2 <= 1; result.Deltas = new DeterministicVector2(t1, t2); if (t1 < 0) { t1 = new DeterministicFloat(0); } else if (t1 > 1) { t1 = new DeterministicFloat(1); } if (t2 < 0) { t1 = new DeterministicFloat(0); } else if (t2 > 1) { t2 = new DeterministicFloat(1); } // result.SegmentIntersection = new NavigationEdge(new DeterministicVector2(this.A.X + dx12 * t1, this.A.Y + dy12 * t1), new DeterministicVector2(other.A.X + dx34 * t2, other.A.Y + dy34 * t2)); return(result); }