/// <summary> ///追踪处理单元中的射线 /// </summary> private void TracingUnitRay(RayTracingModel unit, Node tx, Terrain ter, ReceiveBall rxBall, City cityBuilding, List <FrequencyBand> txFrequencyBand) { double rayBeamAngle = unit.AngleOfRayBeam * Math.PI / 180; //追踪射线1 if (unit.FirstRay.WhetherHaveTraced == false)//若该射线之前还没有追踪 { RayInfo newRay = new RayInfo(unit.FirstRay.Origin, unit.FirstRay.SVector); List <Path> pathtemp = this.GetSingleRayPaths(tx, ter, rxBall, cityBuilding, newRay, rayBeamAngle, txFrequencyBand); unit.FirstRay.Flag = this.JudgeIfArriveRx(pathtemp); unit.FirstRay.Path = pathtemp; unit.FirstRay.WhetherHaveTraced = true; } //追踪射线2 if (unit.SecondRay.WhetherHaveTraced == false)//若该射线之前还没有追踪 { RayInfo newRay = new RayInfo(unit.SecondRay.Origin, unit.SecondRay.SVector); List <Path> pathtemp = this.GetSingleRayPaths(tx, ter, rxBall, cityBuilding, newRay, rayBeamAngle, txFrequencyBand); unit.SecondRay.Flag = this.JudgeIfArriveRx(pathtemp); unit.SecondRay.Path = pathtemp; unit.FirstRay.WhetherHaveTraced = true; } //追踪射线3 if (unit.ThirdRay.WhetherHaveTraced == false)//若该射线之前还没有追踪 { RayInfo newRay = new RayInfo(unit.ThirdRay.Origin, unit.ThirdRay.SVector); List <Path> pathtemp = this.GetSingleRayPaths(tx, ter, rxBall, cityBuilding, newRay, rayBeamAngle, txFrequencyBand); unit.ThirdRay.Flag = this.JudgeIfArriveRx(pathtemp); unit.ThirdRay.Path = pathtemp; unit.FirstRay.WhetherHaveTraced = true; } unit.HaveTraced = true; return; }
/// <summary> ///获取每个三角形细分的顶点 /// </summary> protected List <Point> GetSubDivisionPoints(RayTracingModel unit, int TessellationFrequency) { List <Point> vertex = new List <Point>(); Point param1 = new Point(unit.FirstRay.SVector); Point param2 = new Point(unit.SecondRay.SVector); Point param3 = new Point(unit.ThirdRay.SVector); vertex.Add(param1); vertex.Add(param2); vertex.Add(param3); SpectVector n1 = new SpectVector(param1, param2); SpectVector n2 = new SpectVector(param1, param3); double length = param1.GetDistance(param2) / TessellationFrequency; Point[] p1 = new Point[TessellationFrequency]; Point[] p2 = new Point[TessellationFrequency]; for (int i = 0; i < TessellationFrequency; i++) { p1[i] = new Point(param1.X + (i + 1) * (n1.a / Math.Sqrt(Math.Pow(n1.a, 2) + Math.Pow(n1.b, 2) + Math.Pow(n1.c, 2)) * length), param1.Y + (i + 1) * (n1.b / Math.Sqrt(Math.Pow(n1.a, 2) + Math.Pow(n1.b, 2) + Math.Pow(n1.c, 2)) * length), param1.Z + (i + 1) * (n1.c / Math.Sqrt(Math.Pow(n1.a, 2) + Math.Pow(n1.b, 2) + Math.Pow(n1.c, 2)) * length)); p2[i] = new Point(param1.X + (i + 1) * (n2.a / Math.Sqrt(Math.Pow(n2.a, 2) + Math.Pow(n2.b, 2) + Math.Pow(n2.c, 2)) * length), param1.Y + (i + 1) * (n2.b / Math.Sqrt(Math.Pow(n2.a, 2) + Math.Pow(n2.b, 2) + Math.Pow(n2.c, 2)) * length), param1.Z + (i + 1) * (n2.c / Math.Sqrt(Math.Pow(n2.a, 2) + Math.Pow(n2.b, 2) + Math.Pow(n2.c, 2)) * length)); vertex.Add(p1[i]); vertex.Add(p2[i]); } for (int j = 0; j < TessellationFrequency; j++) { SpectVector m = new SpectVector(p1[j], p2[j]); GetTrianglePoint(m, p1[j], p2[j], length, vertex); } return(vertex); }
/// <summary> ///将初始三角形上的各条射线分成处理单元 /// </summary> protected List <RayTracingModel> HandleInitialRayToUnit(List <ClassNewRay>[] raysPath) { try { List <RayTracingModel> triangleUnits = new List <RayTracingModel>(); for (int i = 0; i < raysPath.Length - 1; i++) { for (int j = 0; j < raysPath[i].Count; j++) { RayTracingModel param = new RayTracingModel(raysPath[i][j], raysPath[i + 1][j], raysPath[i + 1][j + 1]); param.HaveTraced = true; triangleUnits.Add(param); } } if (raysPath.Length > 2)//若三角形平分大于2层 { for (int m = raysPath.Length - 1; m > 2; m--) { for (int n = 1; n < raysPath[m].Count - 1; n++) { RayTracingModel param = new RayTracingModel(raysPath[m][n], raysPath[m - 1][n - 1], raysPath[m - 1][n]); param.HaveTraced = true; triangleUnits.Add(param); } } } return(triangleUnits); } catch (Exception) { LogFileManager.ObjLog.error("在分配初始射线成处理单元时出错"); return(new List <RayTracingModel>()); } }
/// <summary> ///细分处理单元 /// </summary> protected List <RayTracingModel> DivideRayUnit(RayTracingModel unit) { if (unit == null) { LogFileManager.ObjLog.error("在细分处理单元时,输入的处理单元为null"); return(new List <RayTracingModel>()); } List <RayTracingModel> divideUnits = new List <RayTracingModel>(); //3条射线都没有到达接收机 if (unit.FirstRay.Flag == false && unit.SecondRay.Flag == false && unit.ThirdRay.Flag == false) { return(divideUnits); } //只有射线1到达接收机 else if (unit.FirstRay.Flag == true && unit.SecondRay.Flag == false && unit.ThirdRay.Flag == false) { divideUnits = GetFirstRayUnits(unit); return(divideUnits); } //只有射线2到达接收机 else if (unit.FirstRay.Flag == false && unit.SecondRay.Flag == true && unit.ThirdRay.Flag == false) { divideUnits = GetSecongRayUnits(unit); return(divideUnits); } //只有射线3到达接收机 else if (unit.FirstRay.Flag == false && unit.SecondRay.Flag == false && unit.ThirdRay.Flag == true) { divideUnits = GetThirdRayUnits(unit); return(divideUnits); } //射线1和射线2到达接收机 else if (unit.FirstRay.Flag == true && unit.SecondRay.Flag == true && unit.ThirdRay.Flag == false) { divideUnits = GetFirstAndSecondRaysUnits(unit); return(divideUnits); } //射线1和射线3到达接收机 else if (unit.FirstRay.Flag == true && unit.SecondRay.Flag == false && unit.ThirdRay.Flag == true) { divideUnits = GetFirstAndThirdRaysUnits(unit); return(divideUnits); } //射线2和射线3到达接收机 else if (unit.FirstRay.Flag == false && unit.SecondRay.Flag == true && unit.ThirdRay.Flag == true) { divideUnits = GetSecongdAndThirdRaysUnits(unit); return(divideUnits); } else { divideUnits = GetAllRaysUnits(unit); return(divideUnits); } }
/// <summary> ///获取射线3的细分单元 /// </summary> protected List <RayTracingModel> GetThirdRayUnits(RayTracingModel unit) { ClassNewRay ray3 = (ClassNewRay)unit.ThirdRay.Clone(); ClassNewRay ray4 = new ClassNewRay(unit.ThirdRay.Origin, GetMiddleVectorOfTwoVectors(unit.FirstRay.SVector, unit.SecondRay.SVector), false); ClassNewRay ray5 = new ClassNewRay(unit.ThirdRay.Origin, GetMiddleVectorOfTwoVectors(unit.FirstRay.SVector, unit.ThirdRay.SVector), false); ClassNewRay ray6 = new ClassNewRay(unit.ThirdRay.Origin, GetMiddleVectorOfTwoVectors(unit.SecondRay.SVector, unit.ThirdRay.SVector), false); List <RayTracingModel> divideUnits = new List <RayTracingModel>(); divideUnits.Add(new RayTracingModel(ray3, ray5, ray6)); divideUnits.Add(new RayTracingModel(ray4, ray5, ray6)); divideUnits.Add(new RayTracingModel(unit.FirstRay, ray4, ray5, true)); divideUnits.Add(new RayTracingModel(unit.SecondRay, ray4, ray6, true)); return(divideUnits); }
/// <summary> ///提取路径 /// </summary> protected void ExtractPathOfUnit(RayTracingModel unit, List <Path> pathInfo) { if (unit.FirstRay.Path != null && unit.FirstRay.Path.Count != 0) { pathInfo.AddRange(unit.FirstRay.Path); } if (unit.SecondRay.Path != null && unit.SecondRay.Path.Count != 0) { pathInfo.AddRange(unit.SecondRay.Path); } if (unit.ThirdRay.Path != null && unit.ThirdRay.Path.Count != 0) { pathInfo.AddRange(unit.ThirdRay.Path); } }
/// <summary> ///初始阶段在每个三角形上发出一定的射线 /// </summary> /// <param name="tx">发射机</param> /// <param name="ter">地形</param> /// <param name="rxBall">接收球</param> /// <param name="cityBuilding">建筑物</param> /// <param name="unit">射线处理单元</param> /// <param name="TessellationFrequency">镶嵌次数,等于三角形每条边的细分次数</param> /// <param name="divideAngle">射线束夹角</param> /// <param name="TxFrequencyBand">发射机频段信息</param> /// <returns></returns> private List <RayTracingModel> GetInitialTrianglePath(Node tx, Terrain ter, ReceiveBall rxBall, City cityBuilding, RayTracingModel unit, int TessellationFrequency, double divideAngle, List <FrequencyBand> txFrequencyBand) { Point vertex1 = new Point(unit.FirstRay.SVector); //三角形的顶点 Point vertex2 = new Point(unit.SecondRay.SVector); //三角形的顶点 Point vertex3 = new Point(unit.ThirdRay.SVector); //三角形的顶点 SpectVector vector12 = new SpectVector(vertex1, vertex2); SpectVector vector23 = new SpectVector(vertex2, vertex3); double length = vertex1.GetDistance(vertex2) / TessellationFrequency; //每段的距离 Point[] pointOfEdge12 = new Point[TessellationFrequency]; //存放棱上的点,不包括顶点1 // p1[0] = vertex1; for (int i = 0; i < TessellationFrequency; i++) { pointOfEdge12[i] = new Point(vertex1.X + (i + 1) * (vector12.a / Math.Sqrt(Math.Pow(vector12.a, 2) + Math.Pow(vector12.b, 2) + Math.Pow(vector12.c, 2)) * length), vertex1.Y + (i + 1) * (vector12.b / Math.Sqrt(Math.Pow(vector12.a, 2) + Math.Pow(vector12.b, 2) + Math.Pow(vector12.c, 2)) * length), vertex1.Z + (i + 1) * (vector12.c / Math.Sqrt(Math.Pow(vector12.a, 2) + Math.Pow(vector12.b, 2) + Math.Pow(vector12.c, 2)) * length)); } List <Point>[] vertexPoints = new List <Point> [TessellationFrequency + 1];//存放三角形内每条平行边上的点 vertexPoints[0] = new List <Point> { vertex1 }; //把顶点1放到数组第一位 for (int j = 1; j <= TessellationFrequency; j++) //得到三角形切分后每条边上的点 { vertexPoints[j] = new List <Point>(); vertexPoints[j].Add(pointOfEdge12[j - 1]); this.GetTriangleInternalEdgePoint(vector23, pointOfEdge12[j - 1], length, j, vertexPoints[j]); } List <ClassNewRay>[] raysPath = this.GetEachTriangleRay(tx, ter, rxBall, cityBuilding, TessellationFrequency, divideAngle, txFrequencyBand, vertexPoints); //根据得到的点构造射线 List <RayTracingModel> triangleUnits = this.HandleInitialRayToUnit(raysPath); //得到初始追踪完的三角形处理单元 return(triangleUnits); }