public static bool Intersects(Segment2BR segment1, Segment2BR segment2) { if (segment1.point2BR_0 == segment1.point2BR_1) { return(segment2.Contains(segment1.point2BR_0)); } Vector2BR v1 = segment1.point2BR_1 - segment1.point2BR_0; Vector2BR u1 = segment2.Start - segment1.point2BR_0; Vector2BR u2 = segment2.End - segment1.point2BR_0; Vector2BR v2 = new Vector2BR(-v1.Y, v1.X); BigRational bigRational1 = Vector2BR.DotProduct(u1, v2); BigRational bigRational2 = Vector2BR.DotProduct(u2, v2); if (bigRational1.IsPositive && bigRational2.IsPositive || bigRational1.IsNegative && bigRational2.IsNegative) { return(false); } BigRational a = Vector2BR.DotProduct(u1, v1); BigRational b = Vector2BR.DotProduct(u2, v1); BigRational bigRational3 = b - a; if (bigRational3.IsZero) { BigRational bigRational4 = a; if (bigRational4.IsNegative) { return(false); } return(bigRational4.Square() <= v1.GetLengthSquared()); } BigRational bigRational5 = bigRational2 - bigRational1; if (bigRational5.IsZero) { if (BigMath.Max(a, b).IsNegative) { return(false); } return(BigMath.Min(a, b).Square() <= v1.GetLengthSquared()); } BigRational bigRational6 = bigRational3 / bigRational5; BigRational bigRational7 = a - bigRational1 * bigRational6; if (bigRational7.IsNegative) { return(false); } return(bigRational7.Square() < v1.GetLengthSquared()); }
public bool Contains(Point2BR point) { if (point.X > BigMath.Max(this.point2BR_0.X, this.point2BR_1.X) || point.X < BigMath.Min(this.point2BR_0.X, this.point2BR_1.X) || (point.Y > BigMath.Max(this.point2BR_0.Y, this.point2BR_1.Y) || point.Y < BigMath.Min(this.point2BR_0.Y, this.point2BR_1.Y))) { return(false); } if (this.point2BR_0 == this.point2BR_1) { return(true); } Vector2BR delta = this.GetDelta(); Vector2BR u = point - this.point2BR_0; Vector2BR v = new Vector2BR(-delta.Y, delta.X); if (!Vector2BR.DotProduct(u, v).IsZero) { return(false); } BigRational bigRational = Vector2BR.DotProduct(u, delta); if (bigRational.IsNegative) { return(false); } BigRational lengthSquared = delta.GetLengthSquared(); return(!(bigRational > lengthSquared)); }