public Intersection(LineSegment2 line1, LineSegment2 line2) : this() { Line1 = line1; Line2 = line2; var p = line1.End1; var q = line2.End1; var r = line1.ToVector2(); var s = line2.ToVector2(); var denom = r.Cross(s); if (denom == 0) { // The lines are parallel and there's no intersection HasIntersection = false; Distance1 = double.NaN; Distance2 = double.NaN; return; } var t = (q - p).Cross(s) / denom; var u = (q - p).Cross(r) / denom; Point = p + r * t; Distance1 = t; Distance2 = u; HasIntersection = true; }
public Intersection(LineSegment2 line1, LineSegment2 line2) : this() { Line1 = line1; Line2 = line2; var p = line1.End1; var q = line2.End1; var r = line1.ToVector2(); var s = line2.ToVector2(); var denom = r.Cross(s); if (denom == 0) { // The lines are parallel and there's no intersection HasIntersection = false; Distance1 = double.NaN; Distance2 = double.NaN; return; } var t = (q - p).Cross(s)/denom; var u = (q - p).Cross(r)/denom; Point = p + r*t; Distance1 = t; Distance2 = u; HasIntersection = true; }
/// <summary> /// Returns the angle formed between this <see cref="LineSegment2"/> and the supplied <paramref name="lineSegment"/>. /// </summary> /// <param name="lineSegment"></param> /// <returns></returns> public double AngleTo(LineSegment2 lineSegment) { return ToVector2().Angle - lineSegment.ToVector2().Angle; }
/// <summary> /// Returns the angle formed between this <see cref="LineSegment2"/> and the supplied <paramref name="lineSegment"/>. /// </summary> /// <param name="lineSegment"></param> /// <returns></returns> public double AngleTo(LineSegment2 lineSegment) { return(ToVector2().Angle - lineSegment.ToVector2().Angle); }