Пример #1
0
 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();
 }
Пример #2
0
        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));
        }
Пример #3
0
        public static Ray2LR GetLeastSquaresFit(IList <Point2LR> points)
        {
            if (points.Count < 2)
            {
                throw new ArgumentException("At least 2 points required for least square fit.");
            }
            LongRational zero1 = LongRational.Zero;
            LongRational zero2 = LongRational.Zero;
            LongRational zero3 = LongRational.Zero;
            LongRational zero4 = LongRational.Zero;
            int          count = points.Count;

            for (int index = 0; index < count; ++index)
            {
                Point2LR point = points[index];
                zero1 += point.X;
                zero2 += point.Y;
                zero3 += point.X * point.X;
                zero4 += point.X * point.Y;
            }
            LongRational longRational1 = (LongRational)((double)count);
            LongRational longRational2 = zero1 / longRational1;
            LongRational longRational3 = zero2 / longRational1;
            LongRational longRational4 = zero3 - longRational1 * longRational2 * longRational2;
            LongRational y             = (zero4 - longRational1 * longRational2 * longRational3) / longRational4;

            return(new Ray2LR(points[0], new Vector2LR(LongRational.One, y)));
        }
Пример #4
0
 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());
 }
Пример #5
0
 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);
 }
Пример #6
0
        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());
        }
Пример #7
0
 public Ray2LR(
     LongRational startX,
     LongRational startY,
     LongRational directionX,
     LongRational directionY)
 {
     this.origin    = new Point2LR(startX, startY);
     this.direction = new Vector2LR(directionX, directionY);
 }
Пример #8
0
 public Segment2LR(
     LongRational startx,
     LongRational starty,
     LongRational endx,
     LongRational endy)
 {
     this.start = new Point2LR(startx, starty);
     this.end   = new Point2LR(endx, endy);
 }
Пример #9
0
        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);
        }
Пример #10
0
        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());
        }
Пример #11
0
            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);
            }
Пример #12
0
        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);
        }
Пример #13
0
        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));
        }
Пример #14
0
        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);
        }
Пример #15
0
        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);
        }
Пример #16
0
        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);
        }
Пример #17
0
 public Ray2LR(Point2LR origin, Vector2LR direction)
 {
     this.origin    = origin;
     this.direction = direction;
 }
Пример #18
0
 public Line2LR(double startX, double startY, double directionX, double directionY)
 {
     this.origin    = new Point2LR(startX, startY);
     this.direction = new Vector2LR(directionX, directionY);
 }
Пример #19
0
 public bool method_0(Point2LR p)
 {
     return(Vector2LR.DotProduct(p - this.point2LR_0, new Vector2LR(-this.vector2LR_0.Y, this.vector2LR_0.X)).IsZero);
 }
Пример #20
0
 public Segment2LR(double startx, double starty, double endx, double endy)
 {
     this.start = new Point2LR(startx, starty);
     this.end   = new Point2LR(endx, endy);
 }
Пример #21
0
 public Point2LR GetClosestPoint(Point2LR point)
 {
     return(Vector2LR.DotProduct(point - this.origin, this.direction) / this.direction.GetLengthSquared() * this.direction + this.origin);
 }
Пример #22
0
 public Point2LR GetCenter()
 {
     return(Point2LR.GetMidPoint(this.start, this.end));
 }
Пример #23
0
 public Segment2LR(Point2LR start, Point2LR end)
 {
     this.start = start;
     this.end   = end;
 }