Beispiel #1
0
 public Struct6(Point2BR start, Point2BR end, Vector2BR delta)
 {
     this.point2BR_0    = start;
     this.point2BR_1    = end;
     this.vector2BR_0   = delta;
     this.bigRational_0 = this.vector2BR_0.GetLengthSquared();
 }
Beispiel #2
0
        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));
        }
Beispiel #3
0
        public static Ray2BR GetLeastSquaresFit(IList <Point2BR> points)
        {
            if (points.Count < 2)
            {
                throw new ArgumentException("At least 2 points required for least square fit.");
            }
            BigRational zero1 = BigRational.Zero;
            BigRational zero2 = BigRational.Zero;
            BigRational zero3 = BigRational.Zero;
            BigRational zero4 = BigRational.Zero;
            int         count = points.Count;

            for (int index = 0; index < count; ++index)
            {
                Point2BR point = points[index];
                zero1 += point.X;
                zero2 += point.Y;
                zero3 += point.X * point.X;
                zero4 += point.X * point.Y;
            }
            BigRational bigRational1 = (BigRational)((double)count);
            BigRational bigRational2 = zero1 / bigRational1;
            BigRational bigRational3 = zero2 / bigRational1;
            BigRational bigRational4 = zero3 - bigRational1 * bigRational2 * bigRational2;
            BigRational y            = (zero4 - bigRational1 * bigRational2 * bigRational3) / bigRational4;

            return(new Ray2BR(points[0], new Vector2BR(BigRational.One, y)));
        }
Beispiel #4
0
 public BigRational GetDistanceSquared(Point2BR point)
 {
     if (this.direction.IsZero)
     {
         return((point - this.origin).GetLengthSquared());
     }
     return((Vector2BR.DotProduct(point - this.origin, this.direction) * this.direction / this.direction.GetLengthSquared() + this.origin - point).GetLengthSquared());
 }
Beispiel #5
0
 public static bool ContainsPoint(
     Point2BR p,
     Point2BR p0,
     Point2BR p1,
     Point2BR p2,
     int skipEdgeIndex,
     out int onEdgeFlags,
     out int outsideEdgeIndex)
 {
     onEdgeFlags      = 0;
     outsideEdgeIndex = -1;
     if (skipEdgeIndex != 0)
     {
         Vector2BR   vector2Br1  = new Vector2BR(p1.X - p0.X, p1.Y - p0.Y);
         Vector2BR   vector2Br2  = new Vector2BR(p.X - p0.X, p.Y - p0.Y);
         BigRational bigRational = vector2Br1.Y * vector2Br2.X - vector2Br1.X * vector2Br2.Y;
         if (bigRational.IsNegative)
         {
             outsideEdgeIndex = 0;
             return(false);
         }
         if (bigRational.IsZero)
         {
             onEdgeFlags |= 1;
         }
     }
     if (skipEdgeIndex != 1)
     {
         Vector2BR   vector2Br1  = new Vector2BR(p2.X - p1.X, p2.Y - p1.Y);
         Vector2BR   vector2Br2  = new Vector2BR(p.X - p1.X, p.Y - p1.Y);
         BigRational bigRational = vector2Br1.Y * vector2Br2.X - vector2Br1.X * vector2Br2.Y;
         if (bigRational.IsNegative)
         {
             outsideEdgeIndex = 1;
             return(false);
         }
         if (bigRational.IsZero)
         {
             onEdgeFlags |= 2;
         }
     }
     if (skipEdgeIndex != 2)
     {
         Vector2BR   vector2Br1  = new Vector2BR(p0.X - p2.X, p0.Y - p2.Y);
         Vector2BR   vector2Br2  = new Vector2BR(p.X - p2.X, p.Y - p2.Y);
         BigRational bigRational = vector2Br1.Y * vector2Br2.X - vector2Br1.X * vector2Br2.Y;
         if (bigRational.IsNegative)
         {
             outsideEdgeIndex = 2;
             return(false);
         }
         if (bigRational.IsZero)
         {
             onEdgeFlags |= 4;
         }
     }
     return(true);
 }
Beispiel #6
0
 public Ray2BR(
     BigRational startX,
     BigRational startY,
     BigRational directionX,
     BigRational directionY)
 {
     this.origin    = new Point2BR(startX, startY);
     this.direction = new Vector2BR(directionX, directionY);
 }
Beispiel #7
0
        public Point2BR GetClosestPoint(Point2BR point)
        {
            Vector2BR   u             = point - this.point2BR_0;
            Vector2BR   v             = this.point2BR_1 - this.point2BR_0;
            BigRational lengthSquared = v.GetLengthSquared();
            BigRational bigRational   = Vector2BR.DotProduct(u, v);

            return(bigRational.IsNegative || !(bigRational <= lengthSquared) ? (bigRational.IsNegative ? this.point2BR_0 : this.point2BR_1) : bigRational / lengthSquared * v + this.point2BR_0);
        }
Beispiel #8
0
        public BigRational GetDistanceSquared(Point2BR point)
        {
            Vector2BR   u             = point - this.point2BR_0;
            Vector2BR   v             = this.point2BR_1 - this.point2BR_0;
            BigRational lengthSquared = v.GetLengthSquared();
            BigRational bigRational   = Vector2BR.DotProduct(u, v);

            return(bigRational.IsNegative || !(bigRational <= lengthSquared) ? (!bigRational.IsNegative ? (this.point2BR_1 - point).GetLengthSquared() : (this.point2BR_0 - point).GetLengthSquared()) : (bigRational / lengthSquared * v + this.point2BR_0 - point).GetLengthSquared());
        }
Beispiel #9
0
        public BigRational GetNormalizedProjection(Point2BR point)
        {
            if (this.point2BR_0 == this.point2BR_1)
            {
                return(BigRational.NaN);
            }
            Vector2BR delta = this.GetDelta();

            return(Vector2BR.DotProduct(point - this.point2BR_0, delta) / delta.GetLengthSquared());
        }
Beispiel #10
0
            public bool method_1(Point2BR point)
            {
                BigRational bigRational = Vector2BR.DotProduct(point - this.point2BR_0, this.vector2BR_0);

                if (!bigRational.IsNegative)
                {
                    return(bigRational <= this.bigRational_0);
                }
                return(false);
            }
Beispiel #11
0
        public bool Contains(Point2BR p)
        {
            if (this.direction.IsZero)
            {
                return(p == this.origin);
            }
            Vector2BR v = new Vector2BR(-this.direction.Y, this.direction.X);

            return(Vector2BR.DotProduct(p - this.origin, v).IsZero);
        }
Beispiel #12
0
        public bool ContainsProjection(Point2BR point)
        {
            Vector2BR   delta       = this.GetDelta();
            BigRational bigRational = Vector2BR.DotProduct(point - this.point2BR_0, delta);

            if (bigRational.IsNegative)
            {
                return(false);
            }
            BigRational lengthSquared = delta.GetLengthSquared();

            return(!(bigRational.Square() > lengthSquared));
        }
Beispiel #13
0
        public bool Contains(Point2BR p)
        {
            if (this.direction.IsZero)
            {
                return(p == this.origin);
            }
            Vector2BR v = new Vector2BR(-this.direction.Y, this.direction.X);
            Vector2BR u = p - this.origin;

            if (!Vector2BR.DotProduct(u, v).IsZero)
            {
                return(false);
            }
            return(!Vector2BR.DotProduct(u, this.direction).IsNegative);
        }
Beispiel #14
0
        public static bool ContainsPoint(
            Point2BR p,
            Point2BR p0,
            Point2BR p1,
            Point2BR p2,
            out int onEdgeFlags)
        {
            onEdgeFlags = 0;
            Vector2BR   vector2Br1   = new Vector2BR(p1.X - p0.X, p1.Y - p0.Y);
            Vector2BR   vector2Br2   = new Vector2BR(p.X - p0.X, p.Y - p0.Y);
            BigRational bigRational1 = vector2Br1.Y * vector2Br2.X - vector2Br1.X * vector2Br2.Y;

            if (bigRational1.IsNegative)
            {
                return(false);
            }
            if (bigRational1.IsZero)
            {
                onEdgeFlags |= 1;
            }
            Vector2BR   vector2Br3   = new Vector2BR(p2.X - p1.X, p2.Y - p1.Y);
            Vector2BR   vector2Br4   = new Vector2BR(p.X - p1.X, p.Y - p1.Y);
            BigRational bigRational2 = vector2Br3.Y * vector2Br4.X - vector2Br3.X * vector2Br4.Y;

            if (bigRational2.IsNegative)
            {
                return(false);
            }
            if (bigRational2.IsZero)
            {
                onEdgeFlags |= 2;
            }
            Vector2BR   vector2Br5   = new Vector2BR(p0.X - p2.X, p0.Y - p2.Y);
            Vector2BR   vector2Br6   = new Vector2BR(p.X - p2.X, p.Y - p2.Y);
            BigRational bigRational3 = vector2Br5.Y * vector2Br6.X - vector2Br5.X * vector2Br6.Y;

            if (bigRational3.IsNegative)
            {
                return(false);
            }
            if (bigRational3.IsZero)
            {
                onEdgeFlags |= 4;
            }
            return(true);
        }
Beispiel #15
0
        public static bool ContainsPoint(Point2BR p, Point2BR p0, Point2BR p1, Point2BR p2)
        {
            Vector2BR vector2Br1 = Point2BR.Subtract(p1, p0);

            if ((vector2Br1.Y * (p.X - p0.X) - vector2Br1.X * (p.Y - p0.Y)).IsNegative)
            {
                return(false);
            }
            Vector2BR vector2Br2 = Point2BR.Subtract(p2, p1);

            if ((vector2Br2.Y * (p.X - p1.X) - vector2Br2.X * (p.Y - p1.Y)).IsNegative)
            {
                return(false);
            }
            Vector2BR vector2Br3 = Point2BR.Subtract(p0, p2);

            return(!(vector2Br3.Y * (p.X - p2.X) - vector2Br3.X * (p.Y - p2.Y)).IsNegative);
        }
Beispiel #16
0
 public Ray2BR(Point2BR origin, Vector2BR direction)
 {
     this.origin    = origin;
     this.direction = direction;
 }
Beispiel #17
0
 public Line2BR(double startX, double startY, double directionX, double directionY)
 {
     this.origin    = new Point2BR(startX, startY);
     this.direction = new Vector2BR(directionX, directionY);
 }
Beispiel #18
0
 public Segment2BR(double startx, double starty, double endx, double endy)
 {
     this.point2BR_0 = new Point2BR(startx, starty);
     this.point2BR_1 = new Point2BR(endx, endy);
 }
Beispiel #19
0
 public bool method_0(Point2BR p)
 {
     return(Vector2BR.DotProduct(p - this.point2BR_0, new Vector2BR(-this.vector2BR_0.Y, this.vector2BR_0.X)).IsZero);
 }
Beispiel #20
0
 public Segment2BR(BigRational startx, BigRational starty, BigRational endx, BigRational endy)
 {
     this.point2BR_0 = new Point2BR(startx, starty);
     this.point2BR_1 = new Point2BR(endx, endy);
 }
Beispiel #21
0
 public Point2BR GetClosestPoint(Point2BR point)
 {
     return(Vector2BR.DotProduct(point - this.origin, this.direction) / this.direction.GetLengthSquared() * this.direction + this.origin);
 }
Beispiel #22
0
 public Point2BR GetCenter()
 {
     return(Point2BR.GetMidPoint(this.point2BR_0, this.point2BR_1));
 }
Beispiel #23
0
 public Segment2BR(Point2BR start, Point2BR end)
 {
     this.point2BR_0 = start;
     this.point2BR_1 = end;
 }