Example #1
0
        /// <summary>
        /// 设定初始数据
        /// </summary>
        private void Init()
        {
            // 获取地质对象的三个控制点,若找不到控制点,则退出
            sg_Vector3[] ptsForM1;
            if (!CoordSys.CoordHelp.get_KWZBPt3(SJLYID, out ptsForM1))
            {
                return;
            }

            // 根据三个控制点,建立M1
            if (ptsForM1.Count() > 2)
            {
                m1 = new CoordSys.M1(ptsForM1);
            }

            string DXID      = string.Empty;
            string OperateID = GUIDGenerator.NewGUID;

            EditDataSet = GLDXMDXKBLL.GetEditDataSet(SJLYID, OperateID, DXID, string.Empty); // ?

            sg_Vector3[] ptsForM3;                                                           // 用于求M3的控制点
            dt = BLHTBLL.GetXDMXJDZB(SJLYID);                                                // 用于求M3(可能重构进入CoordHelp相关函数中)

            if (!CoordHelp.get_JBBLZBPt3(SJLYID, out ptsForM3))
            {
                return;
            }

            // 根据三个控制点,建立M3
            if (!CoordHelp.IsPtsCollinear(ptsForM3))
            {
                this.m3Raw = new M3(ptsForM3);
            }

            if (!this.m3Raw.IsValid)
            {
                throw new Exception("M3创建失败,请检查控制点坐标。");
            }

            // 大地控制点在M3下的坐标
            sg_Vector3 pts1InM3 = this.m3Raw.getLocCoord(ptsForM3[0]);
            sg_Vector3 pts2InM3 = this.m3Raw.getLocCoord(ptsForM3[1]);
            sg_Vector3 pts3InM3 = this.m3Raw.getLocCoord(ptsForM3[2]);

            // 获取新的原点
            double xNewO = Math.Min(Math.Min(pts1InM3.x, pts2InM3.x), pts3InM3.x);
            double yNewO = Math.Min(Math.Min(pts1InM3.y, pts2InM3.y), pts3InM3.y);


            // 获取新原点下的坐标偏移值
            double xOffset = xNewO - pts1InM3.x;  // 减控制点1的横纵坐标什么意思???
            double yOffset = yNewO - pts1InM3.y;

            // 建立M3Screen (M3与M3Screen)
            this.m3Screen = new M3(ptsForM3, xOffset, yOffset);

            // 确定矩形参数 //矩形的四个顶点作为屏幕坐标的基准点
            recWidth = Math.Max(Math.Max(pts1InM3.x, pts2InM3.x), pts3InM3.x)
                       - Math.Min(Math.Min(pts1InM3.x, pts2InM3.x), pts3InM3.x);
            recHeight = Math.Max(Math.Max(pts1InM3.y, pts2InM3.y), pts3InM3.y)
                        - Math.Min(Math.Min(pts1InM3.y, pts2InM3.y), pts3InM3.y);
            sg_Vector3 recLeftLow   = new sg_Vector3(0, 0);
            sg_Vector3 recLeftHigh  = new sg_Vector3(0, recHeight);
            sg_Vector3 recRightLow  = new sg_Vector3(recWidth, 0);
            sg_Vector3 recRightHigh = new sg_Vector3(recWidth, recHeight);

            widthHeightRito = recWidth / recHeight;

            // 绘制矩形
        }
Example #2
0
        /// <summary>
        /// 设定初始数据
        /// </summary>
        private void Init()
        {
            // 获取地质对象的三个控制点,若找不到控制点,则退出
            sg_Vector3[] ptsForM1;
            if (!CoordSys.CoordHelp.get_KWZBPt3(SJLYID, out ptsForM1))
            {
                return;
            }

            // 根据三个控制点,建立M1
            if (ptsForM1.Count() > 2)
            {
                m1 = new CoordSys.M1(ptsForM1);
            }

            string DXID      = string.Empty;
            string OperateID = GUIDGenerator.NewGUID;

            EditDataSet = GLDXMDXKBLL.GetEditDataSet(SJLYID, OperateID, DXID, string.Empty); // ?



            // 用于求M3的控制点
            dt = BLHTBLL.GetXDMXJDZB(SJLYID); // 用于求M3(可能重构进入CoordHelp相关函数中)

            if (!CoordHelp.get_JBBLZBPt3(SJLYID, CtrlPts, out ptsForM3))
            {
                return;
            }

            // 根据三个控制点,建立M3
            if (!CoordHelp.IsPtsCollinear(ptsForM3))
            {
                this.m3Raw = new M3(ptsForM3);
            }

            if (!this.m3Raw.IsValid)
            {
                throw new Exception("M3创建失败,请检查控制点坐标。");
            }


            // 建立M3Screen (M3与M3Screen)
            //  this.m3Screen = new M3(ptsForM3, xOffset, yOffset);

            Point3D[] Pts = new Point3D[3];
            Pts[0] = new Point3D(ptsForM3[0].x, ptsForM3[0].y, ptsForM3[0].z);
            Pts[1] = new Point3D(ptsForM3[1].x, ptsForM3[1].y, ptsForM3[1].z);
            Pts[2] = new Point3D(ptsForM3[2].x, ptsForM3[2].y, ptsForM3[2].z);

            //  确定三角形上方顶点、左下的点、右下的点
            //  以三角形中最长的边为底边
            Point3D pLeftDown = Pts[0], pRightDown = Pts[1], pUp = Pts[2];

            if (Pts[1].DistanceTo(Pts[2]) > pLeftDown.DistanceTo(pRightDown))
            {
                pLeftDown  = Pts[1];
                pRightDown = Pts[2];
                pUp        = Pts[0];
            }
            if (Pts[2].DistanceTo(Pts[0]) > pLeftDown.DistanceTo(pRightDown))
            {
                pLeftDown  = Pts[2];
                pRightDown = Pts[0];
                pUp        = Pts[1];
            }
            Vector3D tmpBA = pRightDown - pLeftDown;
            Vector3D tmpCA = pUp - pLeftDown;

            //叉乘,如果方向指向下,就要把三角形镜像一下,否则不符合勘察人员的视角
            //镜像,左下方的点和右下方的点互换即可
            Vector3D tmpResult = tmpCA.CrossProduct(tmpBA);

            if (tmpResult.Z < 0)
            {
                Point3D tmpP = pLeftDown;
                pLeftDown  = pRightDown;
                pRightDown = tmpP;
            }

            // 根据海伦公式,计算三角的高
            double distAB = pLeftDown.DistanceTo(pRightDown);
            double distAC = pLeftDown.DistanceTo(pUp);
            double distBC = pRightDown.DistanceTo(pUp);

            double r = (distAB + distAC + distBC) / 2;
            double S = Math.Sqrt(r * (r - distBC) * (r - distAB) * (r - distAC));
            double h = 2 * S / distAB;

            //计算包络矩形的宽高比
            widthHeightRito  = distAB / h;
            ptsTriangleSC[0] = pUp;
            ptsTriangleSC[1] = pLeftDown;
            ptsTriangleSC[2] = pRightDown;
        }