public Struct9(Point2LR start, Point2LR end, Vector2LR delta) { this.point2LR_0 = start; this.point2LR_1 = end; this.vector2LR_0 = delta; this.longRational_0 = this.vector2LR_0.GetLengthSquared(); }
public bool Contains(Point2LR point) { if (point.X > LongRational.Max(this.start.X, this.end.X) || point.X < LongRational.Min(this.start.X, this.end.X) || (point.Y > LongRational.Max(this.start.Y, this.end.Y) || point.Y < LongRational.Min(this.start.Y, this.end.Y))) { return(false); } if (this.start == this.end) { return(true); } Vector2LR delta = this.GetDelta(); Vector2LR u = point - this.start; Vector2LR v = new Vector2LR(-delta.Y, delta.X); if (!Vector2LR.DotProduct(u, v).IsZero) { return(false); } LongRational longRational = Vector2LR.DotProduct(u, delta); if (longRational.IsNegative) { return(false); } LongRational lengthSquared = delta.GetLengthSquared(); return(!(longRational > lengthSquared)); }
public LongRational GetDistanceSquared(Point2LR point) { if (this.direction.IsZero) { return((point - this.origin).GetLengthSquared()); } return((Vector2LR.DotProduct(point - this.origin, this.direction) * this.direction / this.direction.GetLengthSquared() + this.origin - point).GetLengthSquared()); }
public static bool ContainsPoint( Point2LR p, Point2LR p0, Point2LR p1, Point2LR p2, int skipEdgeIndex, out int onEdgeFlags, out int outsideEdgeIndex) { onEdgeFlags = 0; outsideEdgeIndex = -1; if (skipEdgeIndex != 0) { Vector2LR vector2Lr1 = new Vector2LR(p1.X - p0.X, p1.Y - p0.Y); Vector2LR vector2Lr2 = new Vector2LR(p.X - p0.X, p.Y - p0.Y); LongRational longRational = vector2Lr1.Y * vector2Lr2.X - vector2Lr1.X * vector2Lr2.Y; if (longRational.IsNegative) { outsideEdgeIndex = 0; return(false); } if (longRational.IsZero) { onEdgeFlags |= 1; } } if (skipEdgeIndex != 1) { Vector2LR vector2Lr1 = new Vector2LR(p2.X - p1.X, p2.Y - p1.Y); Vector2LR vector2Lr2 = new Vector2LR(p.X - p1.X, p.Y - p1.Y); LongRational longRational = vector2Lr1.Y * vector2Lr2.X - vector2Lr1.X * vector2Lr2.Y; if (longRational.IsNegative) { outsideEdgeIndex = 1; return(false); } if (longRational.IsZero) { onEdgeFlags |= 2; } } if (skipEdgeIndex != 2) { Vector2LR vector2Lr1 = new Vector2LR(p0.X - p2.X, p0.Y - p2.Y); Vector2LR vector2Lr2 = new Vector2LR(p.X - p2.X, p.Y - p2.Y); LongRational longRational = vector2Lr1.Y * vector2Lr2.X - vector2Lr1.X * vector2Lr2.Y; if (longRational.IsNegative) { outsideEdgeIndex = 2; return(false); } if (longRational.IsZero) { onEdgeFlags |= 4; } } return(true); }
public Ray2LR( LongRational startX, LongRational startY, LongRational directionX, LongRational directionY) { this.origin = new Point2LR(startX, startY); this.direction = new Vector2LR(directionX, directionY); }
public LongRational GetDistanceSquared(Point2LR point) { Vector2LR u = point - this.start; Vector2LR v = this.end - this.start; LongRational lengthSquared = v.GetLengthSquared(); LongRational longRational = Vector2LR.DotProduct(u, v); return(longRational.IsNegative || !(longRational <= lengthSquared) ? (!longRational.IsNegative ? (this.end - point).GetLengthSquared() : (this.start - point).GetLengthSquared()) : (longRational / lengthSquared * v + this.start - point).GetLengthSquared()); }
public Point2LR GetClosestPoint(Point2LR point) { Vector2LR u = point - this.start; Vector2LR v = this.end - this.start; LongRational lengthSquared = v.GetLengthSquared(); LongRational longRational = Vector2LR.DotProduct(u, v); return(longRational.IsNegative || !(longRational <= lengthSquared) ? (longRational.IsNegative ? this.start : this.end) : longRational / lengthSquared * v + this.start); }
public bool method_1(Point2LR point) { LongRational longRational = Vector2LR.DotProduct(point - this.point2LR_0, this.vector2LR_0); if (!longRational.IsNegative) { return(longRational <= this.longRational_0); } return(false); }
public bool Contains(Point2LR p) { if (this.direction.IsZero) { return(p == this.origin); } Vector2LR v = new Vector2LR(-this.direction.Y, this.direction.X); return(Vector2LR.DotProduct(p - this.origin, v).IsZero); }
public LongRational GetNormalizedProjection(Point2LR point) { if (this.start == this.end) { return(LongRational.NaN); } Vector2LR delta = this.GetDelta(); return(Vector2LR.DotProduct(point - this.start, delta) / delta.GetLengthSquared()); }
public static bool Intersects(Ray2LR a, Segment2LR b) { if (a.direction.IsZero) { return(b.Contains(a.origin)); } Vector2LR v = new Vector2LR(-a.Direction.Y, a.Direction.X); if (Vector2LR.DotProduct(b.Start - a.Origin, v).IsPositive == Vector2LR.DotProduct(b.End - a.Origin, v).IsPositive) { return(false); } if (b.Start == b.End) { return(a.Contains(b.Start)); } Vector2LR delta = b.GetDelta(); LongRational longRational1 = a.Direction.X * delta.Y - a.Direction.Y * delta.X; if (longRational1.IsZero) { return(false); } Vector2LR u = b.Start - a.Origin; LongRational longRational2 = Vector2LR.CrossProduct(u, delta); if (longRational1.IsPositive) { if (longRational2.IsNegative) { return(false); } } else if (longRational2.IsPositive) { return(false); } LongRational longRational3 = Vector2LR.CrossProduct(u, a.Direction); if (longRational1.IsPositive) { if (longRational3.IsNegative || longRational3 > longRational1) { return(false); } } else if (longRational3.IsPositive || longRational3 < longRational1) { return(false); } LongRational longRational4 = longRational3 / longRational1; LongRational longRational5 = longRational2 / longRational1; return(true); }
public bool Intersects(Line2LR other, out Point2LR?intersection, out bool parallel) { if (this.direction.IsZero) { parallel = false; bool flag; if (flag = other.Contains(this.origin)) { intersection = new Point2LR?(this.origin); } else { intersection = new Point2LR?(); } return(flag); } if (other.Direction.IsZero) { parallel = false; bool flag; if (flag = this.Contains(other.origin)) { intersection = new Point2LR?(other.origin); } else { intersection = new Point2LR?(); } return(flag); } LongRational longRational1 = this.direction.X * other.direction.Y - this.direction.Y * other.direction.X; if (longRational1.IsZero) { parallel = true; bool flag; if (flag = other.Contains(this.origin)) { intersection = new Point2LR?(this.origin); } else { intersection = new Point2LR?(); } return(flag); } parallel = false; LongRational longRational2 = Vector2LR.CrossProduct(other.Origin - this.origin, other.Direction) / longRational1; intersection = new Point2LR?(this.origin + longRational2 * this.direction); return(true); }
public bool ContainsProjection(Point2LR point) { Vector2LR delta = this.GetDelta(); LongRational longRational = Vector2LR.DotProduct(point - this.start, delta); if (longRational.IsNegative) { return(false); } LongRational lengthSquared = delta.GetLengthSquared(); return(!(longRational.Square() > lengthSquared)); }
public bool Contains(Point2LR p) { if (this.direction.IsZero) { return(p == this.origin); } Vector2LR v = new Vector2LR(-this.direction.Y, this.direction.X); Vector2LR u = p - this.origin; if (!Vector2LR.DotProduct(u, v).IsZero) { return(false); } return(!Vector2LR.DotProduct(u, this.direction).IsNegative); }
public static bool ContainsPoint( Point2LR p, Point2LR p0, Point2LR p1, Point2LR p2, out int onEdgeFlags) { onEdgeFlags = 0; Vector2LR vector2Lr1 = new Vector2LR(p1.X - p0.X, p1.Y - p0.Y); Vector2LR vector2Lr2 = new Vector2LR(p.X - p0.X, p.Y - p0.Y); LongRational longRational1 = vector2Lr1.Y * vector2Lr2.X - vector2Lr1.X * vector2Lr2.Y; if (longRational1.IsNegative) { return(false); } if (longRational1.IsZero) { onEdgeFlags |= 1; } Vector2LR vector2Lr3 = new Vector2LR(p2.X - p1.X, p2.Y - p1.Y); Vector2LR vector2Lr4 = new Vector2LR(p.X - p1.X, p.Y - p1.Y); LongRational longRational2 = vector2Lr3.Y * vector2Lr4.X - vector2Lr3.X * vector2Lr4.Y; if (longRational2.IsNegative) { return(false); } if (longRational2.IsZero) { onEdgeFlags |= 2; } Vector2LR vector2Lr5 = new Vector2LR(p0.X - p2.X, p0.Y - p2.Y); Vector2LR vector2Lr6 = new Vector2LR(p.X - p2.X, p.Y - p2.Y); LongRational longRational3 = vector2Lr5.Y * vector2Lr6.X - vector2Lr5.X * vector2Lr6.Y; if (longRational3.IsNegative) { return(false); } if (longRational3.IsZero) { onEdgeFlags |= 4; } return(true); }
public static bool ContainsPoint(Point2LR p, Point2LR p0, Point2LR p1, Point2LR p2) { Vector2LR vector2Lr1 = Point2LR.Subtract(p1, p0); if ((vector2Lr1.Y * (p.X - p0.X) - vector2Lr1.X * (p.Y - p0.Y)).IsNegative) { return(false); } Vector2LR vector2Lr2 = Point2LR.Subtract(p2, p1); if ((vector2Lr2.Y * (p.X - p1.X) - vector2Lr2.X * (p.Y - p1.Y)).IsNegative) { return(false); } Vector2LR vector2Lr3 = Point2LR.Subtract(p0, p2); return(!(vector2Lr3.Y * (p.X - p2.X) - vector2Lr3.X * (p.Y - p2.Y)).IsNegative); }
public static bool GetIntersectionCoefficients( Line2LR a, Line2LR b, out LongRational?p, out LongRational?q, out bool parallel) { if (a.direction.IsZero) { if (b.direction.IsZero) { bool flag = a.origin == b.origin; parallel = false; if (flag) { p = new LongRational?(LongRational.Zero); q = new LongRational?(LongRational.Zero); } else { p = new LongRational?(); q = new LongRational?(); } return(flag); } parallel = false; p = new LongRational?(); bool flag1; if (flag1 = b.Contains(a.origin)) { q = new LongRational?(Vector2LR.DotProduct(a.origin - b.origin, b.direction) / b.direction.GetLengthSquared()); } else { q = new LongRational?(); } return(flag1); } if (b.Direction.IsZero) { parallel = false; q = new LongRational?(); bool flag; if (flag = a.Contains(b.origin)) { p = new LongRational?(Vector2LR.DotProduct(b.origin - a.origin, a.direction) / a.direction.GetLengthSquared()); } else { p = new LongRational?(); } return(flag); } LongRational longRational = a.Direction.X * b.Direction.Y - a.Direction.Y * b.Direction.X; if (longRational.IsZero) { parallel = true; a.Contains(b.origin); p = new LongRational?(); q = new LongRational?(); return(true); } parallel = false; Vector2LR u = b.Origin - a.Origin; p = new LongRational?(Vector2LR.CrossProduct(u, b.Direction) / longRational); q = new LongRational?(Vector2LR.CrossProduct(u, a.Direction) / longRational); return(true); }
public static bool GetIntersectionCoefficients( Ray2LR a, Segment2LR b, out LongRational?p, out LongRational?q, out bool areParallel) { if (a.direction.IsZero) { areParallel = false; p = new LongRational?(); bool flag; if (flag = b.Contains(a.origin)) { Vector2LR delta = b.GetDelta(); q = new LongRational?(Vector2LR.DotProduct(a.origin - b.Start, delta) / delta.GetLengthSquared()); } else { q = new LongRational?(); } return(flag); } Vector2LR v = new Vector2LR(-a.direction.Y, a.direction.X); Vector2LR u = b.Start - a.Origin; LongRational longRational1 = Vector2LR.DotProduct(u, v); LongRational longRational2 = Vector2LR.DotProduct(b.End - a.Origin, v); if (longRational1.IsPositive && longRational2.IsPositive || longRational1.IsNegative && longRational2.IsNegative) { p = new LongRational?(); q = new LongRational?(); areParallel = false; return(false); } Vector2LR delta1 = b.GetDelta(); if (delta1.IsZero) { areParallel = false; p = new LongRational?(Vector2LR.DotProduct(u, a.direction) / a.direction.GetLengthSquared()); q = new LongRational?(LongRational.Zero); return(true); } LongRational longRational3 = a.Direction.X * delta1.Y - a.Direction.Y * delta1.X; if (longRational3.IsZero) { p = new LongRational?(); q = new LongRational?(); areParallel = true; return(true); } areParallel = false; LongRational longRational4 = Vector2LR.CrossProduct(u, delta1); if (longRational3.IsPositive) { if (longRational4.IsNegative) { p = new LongRational?(); q = new LongRational?(); return(false); } } else if (longRational4.IsPositive) { p = new LongRational?(); q = new LongRational?(); return(false); } LongRational longRational5 = Vector2LR.CrossProduct(u, a.Direction); if (longRational3.IsPositive) { if (longRational5.IsNegative || longRational5 > longRational3) { p = new LongRational?(); q = new LongRational?(); return(false); } } else if (longRational5.IsPositive || longRational5 < longRational3) { p = new LongRational?(); q = new LongRational?(); return(false); } p = new LongRational?(longRational4 / longRational3); q = new LongRational?(longRational5 / longRational3); return(true); }
public bool method_0(Point2LR p) { return(Vector2LR.DotProduct(p - this.point2LR_0, new Vector2LR(-this.vector2LR_0.Y, this.vector2LR_0.X)).IsZero); }
public Ray2LR(Point2LR origin, Vector2LR direction) { this.origin = origin; this.direction = direction; }
public static bool GetIntersectionCoefficients( Ray2LR a, Ray2LR b, out LongRational?p, out LongRational?q, out bool parallel) { if (a.direction.IsZero) { if (b.direction.IsZero) { bool flag = a.origin == b.origin; parallel = false; if (flag) { p = new LongRational?(LongRational.Zero); q = new LongRational?(LongRational.Zero); } else { p = new LongRational?(); q = new LongRational?(); } return(flag); } parallel = false; p = new LongRational?(); bool flag1; if (flag1 = b.Contains(a.origin)) { q = new LongRational?(Vector2LR.DotProduct(a.origin - b.origin, b.direction) / b.direction.GetLengthSquared()); } else { q = new LongRational?(); } return(flag1); } if (b.Direction.IsZero) { parallel = false; q = new LongRational?(); bool flag; if (flag = a.Contains(b.origin)) { p = new LongRational?(Vector2LR.DotProduct(b.origin - a.origin, a.direction) / a.direction.GetLengthSquared()); } else { p = new LongRational?(); } return(flag); } LongRational longRational1 = a.Direction.X * b.Direction.Y - a.Direction.Y * b.Direction.X; if (longRational1.IsZero) { parallel = true; if (!a.Contains(b.origin)) { b.Contains(a.origin); } p = new LongRational?(); q = new LongRational?(); return(true); } parallel = false; Vector2LR u = b.origin - a.origin; LongRational longRational2 = Vector2LR.CrossProduct(u, b.direction); if (longRational1.IsPositive) { if (longRational2.IsNegative) { p = new LongRational?(); q = new LongRational?(); return(false); } } else if (longRational2.IsPositive) { p = new LongRational?(); q = new LongRational?(); return(false); } LongRational longRational3 = Vector2LR.CrossProduct(u, a.direction); if (longRational1.IsPositive) { if (longRational3.IsNegative) { p = new LongRational?(); q = new LongRational?(); return(false); } } else if (longRational3.IsPositive) { p = new LongRational?(); q = new LongRational?(); return(false); } p = new LongRational?(longRational2 / longRational1); q = new LongRational?(longRational3 / longRational1); return(true); }
public Line2LR(double startX, double startY, double directionX, double directionY) { this.origin = new Point2LR(startX, startY); this.direction = new Vector2LR(directionX, directionY); }
public static bool GetIntersectionParameters( Segment2LR a, Segment2LR b, out LongRational[] pArray, out LongRational[] qArray) { Vector2LR delta1 = a.GetDelta(); Vector2LR delta2 = b.GetDelta(); LongRational longRational1 = delta1.X * delta2.Y - delta1.Y * delta2.X; if (longRational1.IsZero) { Segment2LR.Struct9 struct9_1 = new Segment2LR.Struct9(a.start, a.end, delta1); Segment2LR.Struct9 struct9_2 = new Segment2LR.Struct9(b.start, b.end, delta2); if ((struct9_1.longRational_0 > struct9_2.longRational_0 ? (!struct9_1.method_0(b.start) ? 0 : (struct9_1.method_0(b.End) ? 1 : 0)) : (struct9_2.longRational_0.IsZero || !struct9_2.method_0(a.start) ? 0 : (struct9_2.method_0(a.end) ? 1 : 0))) != 0) { if (struct9_1.method_1(b.start)) { if (struct9_1.method_1(b.end)) { pArray = new LongRational[2] { a.GetNormalizedProjection(b.start), a.GetNormalizedProjection(b.end) }; qArray = new LongRational[2] { LongRational.Zero, LongRational.One }; return(true); } if (struct9_2.method_1(a.start)) { pArray = new LongRational[2] { LongRational.Zero, a.GetNormalizedProjection(b.start) }; qArray = new LongRational[2] { b.GetNormalizedProjection(a.start), LongRational.Zero }; return(true); } if (struct9_2.method_1(a.End)) { pArray = new LongRational[2] { a.GetNormalizedProjection(b.start), LongRational.One }; qArray = new LongRational[2] { LongRational.Zero, b.GetNormalizedProjection(a.end) }; return(true); } } else if (struct9_1.method_1(b.end)) { if (struct9_2.method_1(a.start)) { if (struct9_2.method_1(a.End)) { pArray = new LongRational[2] { LongRational.Zero, LongRational.One }; qArray = new LongRational[2] { b.GetNormalizedProjection(a.start), b.GetNormalizedProjection(a.end) }; } else { pArray = new LongRational[2] { LongRational.Zero, a.GetNormalizedProjection(b.end) }; qArray = new LongRational[2] { b.GetNormalizedProjection(a.start), LongRational.One }; } return(true); } if (struct9_2.method_1(a.End)) { pArray = new LongRational[2] { LongRational.One, a.GetNormalizedProjection(b.end) }; qArray = new LongRational[2] { b.GetNormalizedProjection(a.end), LongRational.One }; return(true); } } else if (struct9_2.method_1(a.start)) { pArray = new LongRational[2] { LongRational.Zero, LongRational.One }; qArray = new LongRational[2] { b.GetNormalizedProjection(a.start), b.GetNormalizedProjection(a.end) }; return(true); } } pArray = (LongRational[])null; qArray = (LongRational[])null; return(false); } LongRational longRational2 = (b.Start.X - a.Start.X) * delta2.Y - (b.Start.Y - a.Start.Y) * delta2.X; if (longRational1.IsPositive) { if (longRational2.IsNegative || longRational2 > longRational1) { pArray = (LongRational[])null; qArray = (LongRational[])null; return(false); } } else if (longRational2.IsPositive || longRational2 < longRational1) { pArray = (LongRational[])null; qArray = (LongRational[])null; return(false); } LongRational longRational3 = (b.Start.X - a.Start.X) * delta1.Y - (b.Start.Y - a.Start.Y) * delta1.X; if (longRational1.IsPositive) { if (longRational3.IsNegative || longRational3 > longRational1) { pArray = (LongRational[])null; qArray = (LongRational[])null; return(false); } } else if (longRational3.IsPositive || longRational3 < longRational1) { pArray = (LongRational[])null; qArray = (LongRational[])null; return(false); } LongRational longRational4 = longRational2 / longRational1; LongRational longRational5 = longRational3 / longRational1; pArray = new LongRational[1] { longRational4 }; qArray = new LongRational[1] { longRational5 }; return(true); }
public Point2LR GetClosestPoint(Point2LR point) { return(Vector2LR.DotProduct(point - this.origin, this.direction) / this.direction.GetLengthSquared() * this.direction + this.origin); }
public bool Intersects(Ray2LR other, out Point2LR?intersection, out bool parallel) { if (this.direction.IsZero) { parallel = false; bool flag; if (flag = other.Contains(this.origin)) { intersection = new Point2LR?(this.origin); } else { intersection = new Point2LR?(); } return(flag); } if (other.Direction.IsZero) { parallel = false; bool flag; if (flag = this.Contains(other.origin)) { intersection = new Point2LR?(other.origin); } else { intersection = new Point2LR?(); } return(flag); } LongRational longRational1 = this.direction.X * other.direction.Y - this.direction.Y * other.direction.X; if (longRational1.IsZero) { parallel = true; bool flag; if (flag = other.Contains(this.origin)) { intersection = new Point2LR?(this.origin); } else { intersection = new Point2LR?(); } return(flag); } parallel = false; Vector2LR u = other.origin - this.origin; LongRational longRational2 = Vector2LR.CrossProduct(u, other.direction); if (longRational1.IsPositive) { if (longRational2.IsNegative) { intersection = new Point2LR?(); return(false); } } else if (longRational2.IsPositive) { intersection = new Point2LR?(); return(false); } LongRational longRational3 = Vector2LR.CrossProduct(u, this.direction); if (longRational1.IsPositive) { if (longRational3.IsNegative) { intersection = new Point2LR?(); return(false); } } else if (longRational3.IsPositive) { intersection = new Point2LR?(); return(false); } LongRational longRational4 = longRational2 / longRational1; intersection = new Point2LR?(this.origin + longRational4 * this.direction); return(true); }
public static bool Intersects(Segment2LR a, Segment2LR b) { Vector2LR delta1 = a.GetDelta(); Vector2LR delta2 = b.GetDelta(); LongRational longRational1 = delta1.X * delta2.Y - delta1.Y * delta2.X; if (longRational1.IsZero) { Segment2LR.Struct9 struct9_1 = new Segment2LR.Struct9(a.start, a.end, delta1); Segment2LR.Struct9 struct9_2 = new Segment2LR.Struct9(b.start, b.end, delta2); if ((struct9_1.longRational_0 > struct9_2.longRational_0 ? (!struct9_1.method_0(b.start) ? 0 : (struct9_1.method_0(b.End) ? 1 : 0)) : (struct9_2.longRational_0.IsZero || !struct9_2.method_0(a.start) ? 0 : (struct9_2.method_0(a.end) ? 1 : 0))) != 0) { if (struct9_1.method_1(b.start)) { if (struct9_1.method_1(b.end) || struct9_2.method_1(a.start) || struct9_2.method_1(a.End)) { return(true); } } else if (struct9_1.method_1(b.end)) { if (struct9_2.method_1(a.start) || struct9_2.method_1(a.End)) { return(true); } } else if (struct9_2.method_1(a.start)) { return(true); } } return(false); } LongRational longRational2 = (b.Start.X - a.Start.X) * delta2.Y - (b.Start.Y - a.Start.Y) * delta2.X; if (longRational1.IsPositive) { if (longRational2.IsNegative || longRational2 > longRational1) { return(false); } } else if (longRational2.IsPositive || longRational2 < longRational1) { return(false); } LongRational longRational3 = (b.Start.X - a.Start.X) * delta1.Y - (b.Start.Y - a.Start.Y) * delta1.X; if (longRational1.IsPositive) { if (longRational3.IsNegative || longRational3 > longRational1) { return(false); } } else if (longRational3.IsPositive || longRational3 < longRational1) { return(false); } return(true); }