예제 #1
0
        /// <summary>
        /// 构造函数,参数为大地坐标
        /// </summary>
        /// <param name="start">大地坐标</param>
        /// <param name="end">大地坐标</param>
        public LineCrossGrid3D(Point start, Point end)
        {
            this.isCalc = this.Init();
            if (!this.isCalc)
            {
                return;
            }
            GridHelper.getInstance().getMaxGGridXY(ref this.maxgxid, ref this.maxgyid);

            this.isCalc = !PointComparer.Equals1(start, end) && GridHelper.getInstance().PointXYZToGrid3D(start, ref this.cur);
            if (!this.isCalc)
            {
                return;
            }

            Vector3D dir = Vector3D.constructVector(start, end);

            this.line.setLine(start, dir);

            this.stepx = (this.line.paraEqua.X < 0 ? -1 : 1);
            this.stepy = (this.line.paraEqua.Y < 0 ? -1 : 1);
            this.stepz = (this.line.paraEqua.Z < 0 ? -1 : 1);

            Point ingrid = new Point();

            this.isCalc = GridHelper.getInstance().PointXYZInGrid3D(start, ref ingrid);
            if (!this.isCalc)
            {
                return;
            }

            if (Math.Round(this.line.paraEqua.X, 3) == 0)
            {
                this.tx = this.dx = maxlength;
            }
            else if (this.line.paraEqua.X > 0)
            {
                this.dx = this.gridlength / this.line.paraEqua.X;
                this.tx = (this.gridlength - ingrid.X) / this.line.paraEqua.X;
            }
            else
            {
                this.dx = this.gridlength / (0 - this.line.paraEqua.X);
                this.tx = ingrid.X / (0 - this.line.paraEqua.X);
            }

            if (Math.Round(this.line.paraEqua.Y, 3) == 0)
            {
                this.ty = this.dy = maxlength;
            }
            else if (this.line.paraEqua.Y > 0)
            {
                this.dy = this.gridlength / this.line.paraEqua.Y;
                this.ty = (this.gridlength - ingrid.Y) / this.line.paraEqua.Y;
            }
            else
            {
                this.dy = this.gridlength / (0 - this.line.paraEqua.Y);
                this.ty = ingrid.Y / (0 - this.line.paraEqua.Y);
            }

            if (Math.Round(this.line.paraEqua.Z, 3) == 0)
            {
                this.tz = this.dz = maxlength;//因为tz太大,dz随便定义
            }
            else if (this.line.paraEqua.Z > 0)
            {
                this.dz = this.vgridsize / this.line.paraEqua.Z;
                this.tz = (this.vgridsize - ingrid.Z) / this.line.paraEqua.Z;
            }
            else if (this.line.paraEqua.Z < 0)
            {
                this.dz = this.vgridsize / (0 - this.line.paraEqua.Z);
                this.tz = ingrid.Z / (0 - this.line.paraEqua.Z);
            }
        }
예제 #2
0
        /// <summary>
        /// 构建建筑物底面点数据和中心点以及高度数据,顶面所有点
        /// </summary>
        public static void constructBuildingData(ref Geometric.Point p1, ref Geometric.Point p2,
                                                 ref Geometric.Point p3, ref Geometric.Point p4)
        {
            DateTime t0, t1, t2, t3;

            t0 = DateTime.Now;

            Hashtable ht = new Hashtable();

            Grid3D gid1 = new Grid3D(), gid2 = new Grid3D(), gid3 = new Grid3D(), gid4 = new Grid3D();

            GridHelper.getInstance().PointXYZToGrid3D1(p1, ref gid1);
            GridHelper.getInstance().PointXYZToGrid3D1(p2, ref gid2);
            GridHelper.getInstance().PointXYZToGrid3D1(p3, ref gid3);
            GridHelper.getInstance().PointXYZToGrid3D1(p4, ref gid4);

            ht["x1"] = gid1.gxid;
            ht["x2"] = gid2.gxid;
            ht["x3"] = gid3.gxid;
            ht["x4"] = gid4.gxid;
            ht["y1"] = gid1.gyid;
            ht["y2"] = gid2.gyid;
            ht["y3"] = gid3.gyid;
            ht["y4"] = gid4.gyid;

            DataTable dt = IbatisHelper.ExecuteQueryForDataTable("GetBuildingCenter", ht);

            int    bid;
            double x, y, z, altitude;

            for (int i = 0; i < dt.Rows.Count; i++)//按行遍历DataTable
            {
                bid = Convert.ToInt32(dt.Rows[i]["BuildingID"]);
                if (bid > maxID)
                {
                    maxID = bid;
                }
                if (bid < minID)
                {
                    minID = bid;
                }
                x        = Convert.ToDouble(dt.Rows[i]["BCenterX"]);
                y        = Convert.ToDouble(dt.Rows[i]["BCenterY"]);
                z        = Convert.ToDouble(dt.Rows[i]["BHeight"]);
                altitude = Convert.ToDouble(dt.Rows[i]["BAltitude"]); // 地形
                buildingCenter.Add(bid, new Point(x, y, 0));
                buildingHeight.Add(bid, z + altitude);                // 地形
                buildingAltitude.Add(bid, altitude);                  // 地形
            }

            t1 = DateTime.Now;

            dt = IbatisHelper.ExecuteQueryForDataTable("GetBuildingVertex", ht);
            List <Point> vcollection;
            Point        t;

            //string path = @"f:\t2.txt";
            //StreamWriter sw = File.CreateText(path);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                bid = Convert.ToInt32(dt.Rows[i]["BuildingID"]);
                x   = Convert.ToDouble(dt.Rows[i]["VertexX"]);
                y   = Convert.ToDouble(dt.Rows[i]["VertexY"]);
                t   = new Point(x, y, 0);

                if (buildingVertex.ContainsKey(bid))
                {
                    buildingVertex[bid].Add(t);
                }
                else
                {
                    vcollection = new List <Point>();
                    vcollection.Add(t);
                    buildingVertex.Add(bid, vcollection);
                }
            }
            //sw.Close();
            t2 = DateTime.Now;

            dt = IbatisHelper.ExecuteQueryForDataTable("getBuildingTopVertex", ht);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                bid = Convert.ToInt32(dt.Rows[i]["BuildingID"]);
                x   = Convert.ToDouble(dt.Rows[i]["CX"]);
                y   = Convert.ToDouble(dt.Rows[i]["CY"]);
                z   = buildingHeight[bid];
                t   = new Point(x, y, z);

                //sw.Write(bid + ": " + c.X + " " + c.Y + "\n");

                if (buildingTopVertex.ContainsKey(bid))
                {
                    buildingTopVertex[bid].Add(t);
                }
                else
                {
                    vcollection = new List <Point>();
                    vcollection.Add(t);
                    buildingTopVertex.Add(bid, vcollection);
                }
            }
            //sw.Close();
            t3 = DateTime.Now;

            Console.WriteLine(string.Format("建筑物底面中心:{0}秒", (t1 - t0).TotalMilliseconds / 1000));
            Console.WriteLine(string.Format("建筑物底面顶点:{0}秒", (t2 - t1).TotalMilliseconds / 1000));
            Console.WriteLine(string.Format("建筑物顶面顶点:{0}", (t3 - t2).TotalMilliseconds / 1000));
        }
예제 #3
0
        /// <summary>
        /// 构造函数,参数为大地坐标
        /// </summary>
        /// <param name="start">大地坐标</param>
        /// <param name="dir">方向</param>
        public DDA3D(Point start, Vector3D dir)
        {
            Point tstart = start.clone();

            this.isCalc = this.Init();
            if (!this.isCalc)
            {
                return;
            }
            GridHelper.getInstance().getMaxAccGridXY(ref this.maxgxid, ref this.maxgyid);
            GridHelper.getInstance().getMinAccGridXY(ref this.mingxid, ref this.mingyid);

            this.isCalc = GridHelper.getInstance().PointXYZToAccGrid(tstart, ref this.cur);
            if (!this.isCalc)
            {
                return;
            }

            this.line.setLine(tstart, dir);

            this.stepx = (this.line.paraEqua.X < 0 ? -1 : 1);
            this.stepy = (this.line.paraEqua.Y < 0 ? -1 : 1);
            this.stepz = (this.line.paraEqua.Z < 0 ? -1 : 1);

            Point ingrid = new Point();

            this.isCalc = GridHelper.getInstance().PointXYZInAccGrid(tstart, ref ingrid);
            if (!this.isCalc)
            {
                return;
            }

            //double.MaxValue / 10.0 防止计算时溢出
            if (Math.Round(this.line.paraEqua.X, 3) == 0)
            {
                this.tx = this.dx = maxlength;
            }
            else if (this.line.paraEqua.X > 0)
            {
                this.dx = this.gridlength / this.line.paraEqua.X;
                this.tx = (this.gridlength - ingrid.X) / this.line.paraEqua.X;
            }
            else
            {
                this.dx = this.gridlength / (0 - this.line.paraEqua.X);
                this.tx = ingrid.X / (0 - this.line.paraEqua.X);
            }
            if (Math.Round(this.line.paraEqua.Y, 3) == 0)
            {
                this.ty = this.dy = maxlength;
            }
            else if (this.line.paraEqua.Y > 0)
            {
                this.dy = this.gridlength / this.line.paraEqua.Y;
                this.ty = (this.gridlength - ingrid.Y) / this.line.paraEqua.Y;
            }
            else
            {
                this.dy = this.gridlength / (0 - this.line.paraEqua.Y);
                this.ty = ingrid.Y / (0 - this.line.paraEqua.Y);
            }
            if (Math.Round(this.line.paraEqua.Z, 3) == 0)
            {
                this.tz = this.dz = maxlength;//因为tz很大,所以dz随便定义
            }
            else
            {
                if (this.cur.gzid == 3 && this.line.paraEqua.Z > 0)
                {
                    this.tz = this.dz = maxlength;
                }
                else if (this.line.paraEqua.Z > 0)
                {
                    this.dz = this.vgridsize / this.line.paraEqua.Z;
                    this.tz = (this.vgridsize - ingrid.Z) / this.line.paraEqua.Z;
                }
                else if (this.line.paraEqua.Z < 0)
                {
                    this.dz = this.vgridsize / (0 - this.line.paraEqua.Z);
                    this.tz = ingrid.Z / (0 - this.line.paraEqua.Z);
                }
            }
        }