Пример #1
0
 public WText2D(string T, WPoint2D P, int H)
 {
     Text       = T;
     Position   = P;
     Height     = H;
     this.Kind  = GeoKind.DText;
     this.Color = Color.White;
 }
Пример #2
0
 public WArc2D(WPoint2D Center, WPoint2D StartPoint, WPoint2D EndPoint, bool Direction, ref WGeometry2D WGC)
 {
     this.WGC    = WGC;
     _center     = Center;
     _startpoint = StartPoint;
     _endpoint   = EndPoint;
     _direction  = Direction;
     GetLength();
 }
Пример #3
0
        public bool Equals(WPoint2D other, double tolerance)
        {
            if (tolerance < 0)
            {
                throw new ArgumentException("epsilon < 0");
            }

            return(Math.Abs(other.X - this.X) < tolerance &&
                   Math.Abs(other.Y - this.Y) < tolerance);
        }
Пример #4
0
        /// 将某条线上的所有点加入到Rim边界中
        private WPoint2D Add_Curve2Shape(WCurve2D C, WPoint2D P0)
        {
            bool Reverse = true;

            if (Math.Abs(C.StartPoint.X - P0.X) < WGeos2D_Paras.E_Merge &&
                Math.Abs(C.StartPoint.Y - P0.Y) < WGeos2D_Paras.E_Merge)
            {
                Reverse = false;
            }

            switch (C.Kind)
            {
            case GeoKind.Line:
                if (Reverse == false)
                {
                    Shape.Add(C.EndPoint);
                    return(C.EndPoint);
                }
                else
                {
                    Shape.Add(C.StartPoint);
                    return(C.StartPoint);
                }

            case GeoKind.PolyLine:
                WPolyLine2D PL = (WPolyLine2D)C;
                if (Reverse == false)
                {
                    for (int i = 1; i < PL.Count - 1; i++)
                    {
                        Shape.Add(PL[i]);
                    }
                    Shape.Add(PL[PL.Count - 1]);
                    return(PL[PL.Count - 1]);
                }
                else
                {
                    for (int i = PL.Count - 2; i > 0; i--)
                    {
                        Shape.Add(PL[i]);
                    }
                    Shape.Add(PL[0]);
                    return(PL[0]);
                }

            default:
                break;
            }
            return(new WPoint2D());
        }
Пример #5
0
        public WCircle2D(WPoint2D Center, double R, ref WGeometry2D WGC)
        {
            this.WGC    = WGC;
            _center     = Center;
            _startpoint = new WPoint2D(0, 0);
            _endpoint   = new WPoint2D(0, 0);
            _r          = R;
            GetLength();

            _xmin = Center.X - R;
            _xmax = Center.X + R;
            _ymin = Center.Y - R;
            _ymax = Center.Y + R;
        }
Пример #6
0
        public WPoint2D IntersectWith(WLine2D other)
        {
            if (this.IsParallelTo(other))
            {
                return(null);
            }

            WPoint2D  p = this.StartPoint;
            WPoint2D  q = other.StartPoint;
            WVector2D r = this.StartPoint.VectorTo(this.EndPoint);
            WVector2D s = other.StartPoint.VectorTo(other.EndPoint);
            double    t = (q - p).CrossProduct(s) / (r.CrossProduct(s));

            return(p + t * r);
        }
Пример #7
0
        public WRim2D(ref WEntity2D[] Cs, List <int> Rim)
        {
            this.Meshed      = false;
            this.Nums        = Rim;
            this.Trace       = 0;
            this.Smaller     = new List <int>();
            this.Curves      = new WEntity2D[Rim.Count];
            this.Shape       = new List <WPoint2D>();
            this.Layer       = "Rims";
            this.Color       = Color.AliceBlue;
            this.Color_Shape = Color.Black;
            this.Kind        = GeoKind.Rim;
            Initial_Bound();
            ///
            WCurve2D C;
            WPoint2D P0 = new WPoint2D();
            WPoint2D P1 = new WPoint2D();
            WPoint2D P2 = new WPoint2D();

            for (int i = 0; i < Rim.Count; i++)
            {
                this.Curves[i] = Cs[Rim[i]];
                C = (WCurve2D)Cs[Rim[i]];
                Update_Bound(C.Xmax, C.Ymax);
                Update_Bound(C.Xmin, C.Ymin);
                /////形成边界
                if (i == 0)
                {
                    P1 = ((WCurve2D)(Cs[Rim[Rim.Count - 1]])).StartPoint;
                    P2 = ((WCurve2D)(Cs[Rim[Rim.Count - 1]])).EndPoint;
                    if (Geos2D_Other.Check_PsMerge(P1, C.StartPoint) == true ||
                        Geos2D_Other.Check_PsMerge(P2, C.StartPoint) == true)
                    {
                        P0 = C.StartPoint;
                    }
                    if (Geos2D_Other.Check_PsMerge(P1, C.EndPoint) == true ||
                        Geos2D_Other.Check_PsMerge(P2, C.EndPoint) == true)
                    {
                        P0 = C.EndPoint;
                    }
                }
                P0 = Add_Curve2Shape(C, P0);
            }
        }
Пример #8
0
        /// <summary>
        /// 求最近点
        /// </summary>
        public WPoint2D ClosestPointTo(WPoint2D P)
        {
            WVector2D v; /////P1到P的向量
            WVector2D d; /////P1到P2向量
            double    dotProduct;
            WVector2D alongVector;
            double    L;
            WPoint2D  Pn       = Vertexs[0];
            double    DisMin   = double.MaxValue;
            WPoint2D  PointMin = Vertexs[0];
            double    Dis;

            for (int i = 0; i < Vertexs.Count - 1; i++)
            {
                v          = Vertexs[i].VectorTo(P);
                d          = Vertexs[i].VectorTo(Vertexs[i + 1]);
                L          = d.Length;
                d          = d.Normalize();
                dotProduct = v.DotProduct(d);
                /////
                if (dotProduct < 0)
                {
                    dotProduct = 0;
                }

                if (dotProduct > L)
                {
                    dotProduct = L;
                }

                alongVector = dotProduct * d;
                Pn          = Vertexs[i] + alongVector;
                Dis         = P.DistanceTo(Pn);
                if (Dis < DisMin)
                {
                    DisMin   = Dis;
                    PointMin = Pn;
                }
            }
            return(Pn);
        }
Пример #9
0
 public WLine2D(WPoint2D startPoint, WPoint2D endPoint)
 {
     this._startpoint = startPoint;
     this._endpoint   = endPoint;
     this.WGC         = WGC;
     if (Math.Abs(this.StartPoint.X - this.EndPoint.X) <= WGeos2D_Paras.E_Merge &&
         Math.Abs(this.StartPoint.Y - this.EndPoint.Y) <= WGeos2D_Paras.E_Merge)
     {
         throw new ArgumentException("该线段起点和终点重合!");
     }
     ///
     _xmin = Math.Min(startPoint.X, endPoint.X);
     _xmax = Math.Max(startPoint.X, endPoint.X);
     _ymin = Math.Min(startPoint.Y, endPoint.Y);
     _ymax = Math.Max(startPoint.Y, endPoint.Y);
     ///
     GetLength();
     this.Nodes      = new List <WPoint2D>();
     this.Nodes_num  = new List <int>();
     this.Free_Check = true;
 }
Пример #10
0
        public WPoint2D ClosestPointTo(WPoint2D p, bool Extent)
        {
            WVector2D v          = this.StartPoint.VectorTo(p);
            double    dotProduct = v.DotProduct(this.Direction);

            if (!Extent)
            {
                if (dotProduct < 0)
                {
                    dotProduct = 0;
                }

                double l = this.Length;
                if (dotProduct > l)
                {
                    dotProduct = l;
                }
            }

            WVector2D alongVector = dotProduct * this.Direction;

            return(this.StartPoint + alongVector);
        }
Пример #11
0
 public bool Contains(WPoint2D pt)
 {
     return((pt.X >= _xmin) && (pt.X <= _xmax) && (pt.Y >= _ymin) && (pt.Y <= _ymax));
 }
Пример #12
0
 /// 切割线
 /// <summary>
 /// 切割线
 /// </summary>
 public abstract WEntity2D[] CutByPoint(WPoint2D P);
Пример #13
0
 /// 获取点到线的距离
 /// <summary>
 /// 获取点到线的距离
 /// </summary>
 public abstract double GetDistance(WPoint2D P);
Пример #14
0
 public override WEntity2D[] CutByPoint(WPoint2D P)
 {
     return(new WEntity2D[0]);
 }
Пример #15
0
 /// <summary>
 /// 得到点到线的距离
 /// </summary>
 public override double GetDistance(WPoint2D P)
 {
     return(P.DistanceTo(this.ClosestPointTo(P, false)));
 }
Пример #16
0
 /// <summary>
 /// 判断点是否在线的范围内
 /// </summary>
 /// <param name="pt"></param>
 /// <param name="Range">阈值,应该大于0</param>
 /// <returns></returns>
 public bool Contains(WPoint2D pt, Single Range)
 {
     return((pt.X >= (_bound[0] - Range)) && (pt.X <= (_bound[1] + Range)) && (pt.Y >= (_bound[2] - Range)) && (pt.Y <= (_bound[3] + Range)));
 }
Пример #17
0
 /// <summary>
 /// 判断点是否在线的范围内
 /// </summary>
 /// <param name="pt"></param>
 /// <param name="Range">阈值,应该大于0</param>
 /// <returns></returns>
 public bool Contains(WPoint2D pt, Single Range)
 {
     return((pt.X >= (_xmin - Range)) && (pt.X <= (_xmax + Range)) && (pt.Y >= (_ymin - Range)) && (pt.Y <= (_ymax + Range)));
 }
Пример #18
0
 public override double GetDistance(WPoint2D P)
 {
     return(Math.Abs(Math.Sqrt((P.X - _center.X) * (P.X - _center.X) +
                               (P.Y - _center.Y) * (P.Y - _center.Y)) -
                     _r));
 }
Пример #19
0
 public void Add_P(WPoint2D P)
 {
     Rim.Add(new WPoint2D(P.X, P.Y));
     Update_Bound(P.X, P.Y);
 }
Пример #20
0
        public double DistanceTo(WPoint2D otherPoint)
        {
            var vector = this.VectorTo(otherPoint);

            return(vector.Length);
        }
Пример #21
0
 public WVector2D VectorTo(WPoint2D otherPoint)
 {
     return(otherPoint - this);
 }
Пример #22
0
 public override double GetDistance(WPoint2D P)
 {
     return(double.MaxValue);
 }
Пример #23
0
 public bool Contains(WPoint2D pt)
 {
     return((pt.X >= _bound[0]) && (pt.X <= _bound[1]) && (pt.Y >= _bound[2]) && (pt.Y <= _bound[3]));
 }