public bool Intersects(Line2BR other, out Point2BR?intersection, out bool parallel) { if (this.direction.IsZero) { parallel = false; bool flag; if (flag = other.Contains(this.origin)) { intersection = new Point2BR?(this.origin); } else { intersection = new Point2BR?(); } return(flag); } if (other.Direction.IsZero) { parallel = false; bool flag; if (flag = this.Contains(other.origin)) { intersection = new Point2BR?(other.origin); } else { intersection = new Point2BR?(); } return(flag); } BigRational bigRational1 = this.direction.X * other.direction.Y - this.direction.Y * other.direction.X; if (bigRational1.IsZero) { parallel = true; bool flag; if (flag = other.Contains(this.origin)) { intersection = new Point2BR?(this.origin); } else { intersection = new Point2BR?(); } return(flag); } parallel = false; BigRational bigRational2 = Vector2BR.CrossProduct(other.Origin - this.origin, other.Direction) / bigRational1; intersection = new Point2BR?(this.origin + bigRational2 * this.direction); return(true); }
public static bool Intersects(Line2BR a, Segment2BR b) { if (a.direction.IsZero) { return(b.Contains(a.origin)); } Vector2BR v = new Vector2BR(-a.Direction.Y, a.Direction.X); if (Vector2BR.DotProduct(b.Start - a.Origin, v).IsPositive == Vector2BR.DotProduct(b.End - a.Origin, v).IsPositive) { return(false); } if (b.Start == b.End) { return(a.Contains(b.Start)); } Vector2BR delta = b.GetDelta(); BigRational bigRational1 = a.Direction.X * delta.Y - a.Direction.Y * delta.X; if (bigRational1.IsZero) { return(false); } BigRational bigRational2 = Vector2BR.CrossProduct(b.Start - a.Origin, a.Direction); if (bigRational1.IsPositive) { if (bigRational2.IsNegative || bigRational2 > bigRational1) { return(false); } } else if (bigRational2.IsPositive || bigRational2 < bigRational1) { return(false); } BigRational bigRational3 = bigRational2 / bigRational1; return(true); }
public static bool GetIntersectionCoefficients( Line2BR a, Line2BR b, out BigRational?p, out BigRational?q, out bool parallel) { if (a.direction.IsZero) { if (b.direction.IsZero) { bool flag = a.origin == b.origin; parallel = false; if (flag) { p = new BigRational?(BigRational.Zero); q = new BigRational?(BigRational.Zero); } else { p = new BigRational?(); q = new BigRational?(); } return(flag); } parallel = false; p = new BigRational?(); bool flag1; if (flag1 = b.Contains(a.origin)) { q = new BigRational?(Vector2BR.DotProduct(a.origin - b.origin, b.direction) / b.direction.GetLengthSquared()); } else { q = new BigRational?(); } return(flag1); } if (b.Direction.IsZero) { parallel = false; q = new BigRational?(); bool flag; if (flag = a.Contains(b.origin)) { p = new BigRational?(Vector2BR.DotProduct(b.origin - a.origin, a.direction) / a.direction.GetLengthSquared()); } else { p = new BigRational?(); } return(flag); } BigRational bigRational = a.Direction.X * b.Direction.Y - a.Direction.Y * b.Direction.X; if (bigRational.IsZero) { parallel = true; a.Contains(b.origin); p = new BigRational?(); q = new BigRational?(); return(true); } parallel = false; Vector2BR u = b.Origin - a.Origin; p = new BigRational?(Vector2BR.CrossProduct(u, b.Direction) / bigRational); q = new BigRational?(Vector2BR.CrossProduct(u, a.Direction) / bigRational); return(true); }