www.pudn.com > BackscatterMap.rar > shadowing.cs, change:2009-07-07,size:5530b
using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Collections; using System.Collections.Generic; using System.Windows.Forms; using System.Text; using System.Data.SqlTypes; using System.IO; namespace WindowsApplication4 { class shadowing { readgrid myrg = new readgrid(); static public double[,] elevation; static public int number; static public int radarX = 1000; //预设雷达的位置坐标,对规则格网取样间隔归一化 static public int radarZ = 1000; static public double unit = 30; //规则格网的取样间隔 static public double interval = 30; //极坐标取样间隔为30m static public double maxR = 20000; //最大作用距离为20Km static public int colNum = 360; //以k*unit为半径(k=1、2.....)作一系列同心圆,同心圆的个数为colNum static public int rowNum = colNum; static public double theta = 2 * Math.PI / rowNum; //theta为分割同心圆的角度 static public double radarHeight; public shadowing() { elevation = myrg.read(); number = elevation.GetLength(0); radarHeight = elevation[radarX, radarZ] + 100; } //----------------------------------------------- //建立以雷达位置为中心的极坐标辅助网格 public struct dPoint { public double x; public double z; } public dPoint[,] point = new dPoint[rowNum, colNum]; //二维数组,用此数组对象获得每个扇区中心点的X,Z轴坐标值 public double[,] polaCoord() { shadowing myshadowing = new shadowing(); for (int i = 0; i < rowNum; i++) { double temp1 = interval * Math.Cos((i + 0.5) * theta); double temp2 = interval * Math.Sin((i + 0.5) * theta); double temp3 = interval * 0.5 * Math.Cos((i + 0.5) * theta) + radarX * unit; double temp4 = interval * 0.5 * Math.Sin((i + 0.5) * theta) + radarZ * unit; for (int j = 0; j < colNum; j++) { point[i, j].x = temp3; point[i, j].z = temp4; temp3 = temp3 + temp1; temp4 = temp4 + temp2; } } double[,] node = new double[rowNum, colNum]; for (int i = 0; i < rowNum; i++) //通过插值获得各扇区中心点的高程值 { for (int j = 0; j < colNum; j++) { node[i, j] = myshadowing.interpolate(point[i, j].x, point[i, j].z); } } return node; } //-----------此方法用来作插值,从而获得(x,z)坐标的高程值-------------------- public double interpolate(double x, double z) { int i = (int)(x / unit); int j = (int)(z / unit); double unitX = (x - i * unit) / unit; double unitZ = (z - j * unit) / unit; double ele = elevation[i, j] + (elevation[i + 1, j] - elevation[i, j]) * unitX + (elevation[i, j + 1] - elevation[i, j]) * unitZ + (elevation[i, j] - elevation[i, j + 1] + elevation[i + 1, j + 1] - elevation[i + 1, j]) * unitX * unitZ; return ele; } //-------------此方法用来判断扇区的遮蔽情况,如被遮蔽返回True,未被遮蔽返回False--------------- public bool[,] shadow() { shadowing myshadowing1 = new shadowing(); double[,] centerPoint = myshadowing1.polaCoord(); bool[,] sign = new bool[rowNum, colNum]; double[] temp = new double[colNum]; bool[] tempSign = new bool[colNum]; for (int i = 0; i < rowNum; i++) { for (int j = 0; j < colNum; j++) { temp[j] = centerPoint[i, j]; } tempSign = myshadowing1.juge(temp); for (int k = 0; k < colNum; k++) { sign[i, k] = tempSign[k]; } } return sign; } //--------用增量法判断一个方向的遮蔽情况,返回一个特定方向各个扇区是否被遮蔽,遮蔽返回Ture,否则返回False public bool[] juge(double[] temp) { bool[] sign1 = new bool[colNum]; for (int i = 0; i < colNum; i++) { sign1[i] = false; } ///////////////////////// int j = 1; double hv; double hc; double temp1; while (j < colNum) { do { hv = temp[j - 1]; hc = temp[j]; temp1 = j * (hc - hv) - (hv - radarHeight); //计算天线到第j个点的向量和天线到最后一个可视点的向量的叉乘 j++; } while (j < colNum && temp1 > 0); j = j - 1; double slope = (hv - radarHeight) / j; int k = 1; while ((j < colNum) && (temp[j] < hv + k * slope)) { sign1[j] = true; k++; j++; } j++; } return sign1; } } }