From 2ef44cdd544dea251657b2ff47c93dd403856146 Mon Sep 17 00:00:00 2001 From: tian <4021673@qq.com> Date: Tue, 13 Oct 2020 11:35:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=90=8D=E6=94=B9=E5=A4=A7?= =?UTF-8?q?=E9=A9=BC=E5=B3=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vs/FlyExe/v15/.suo | Bin 56832 -> 60928 bytes FlyExe/FlightRoute.cs | 185 +++++++++++++------------------------- FlyExe/MainWindow.xaml.cs | 12 +-- 3 files changed, 69 insertions(+), 128 deletions(-) diff --git a/.vs/FlyExe/v15/.suo b/.vs/FlyExe/v15/.suo index 721671649435d6f87c669ef15314e35a0968631c..58d955ac0e0737558fb613c679d5e88b786f31b7 100644 GIT binary patch delta 3381 zcmchae^6A{7036!eUJs-vjk8USbk_kXdt*CDrrTYuraGc7ZxE9MMawgVpBA@i_%!x zM2t`=)_x~W4JX)>EtYRuEEX#<9f?FpSOoFp8{RBQ)f`oi z%z0r#+{#-vg)fGKN1TsBq52feBD=gw$1e@31= zE~N5wa7$`$fmyMWWE$Zh3JE{4h`2FLB$7#aTCF9Q$R||7MtqMbChj9jh{Z%H!Trie zE+NW^r9^Du6_o!LK~1EH7WAgiUqz*Af{oxJ`2ew+c#v=tbwO`dTs>u)Xk%#Xafru) z-h#?@(sU5p2%fN$05^j=!sdy)N{T^TU%r;lX1tS1?p*w!;x}B>kIC45|DL!B(#pp5jI{zanHw>Z z)u!LkpmXcsR*T`A_mRSfDV|{WMBU;`zkspSN(Ahaq96VY4{ExW3eU}z6vb9@p2sj( zk{DeH)sPjZv%AGB@aK@vIU0FjPB(m>(`e(cjVZ*>;m_@jd!AGhuHU^@6@1{M?YYa- z>4o|+8v-dcsL3idCU+=8-&&&zJ}I$?r*R9gYwLFu4sSjRv9XQGt%?X`)_h@`dG1?n z`;cBfDS)Z+UZKOkv`*o(w_wJA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b&?2=CZDcax(P{?muV0h}0Gg-t_cSUuRU4-D1GI5M22 zXPtG4q?7z_6@#SsSJI_jNvo>9AVUm39?a7hT*xr}S9dx*Bl}QU-mZHt(d`m^1L^bz Pl6CRtfDnQHbK(C4I07b1 diff --git a/FlyExe/FlightRoute.cs b/FlyExe/FlightRoute.cs index fff5045..17fe162 100644 --- a/FlyExe/FlightRoute.cs +++ b/FlyExe/FlightRoute.cs @@ -128,7 +128,7 @@ namespace FlightRoute public static class FlyBase { //逐行读取 文档 - private static string[] readFile(string path) + private static string[] ReadFile(string path) { StreamReader sr = new StreamReader(path, Encoding.Default); String line; @@ -153,11 +153,11 @@ namespace FlightRoute return arr; } //svg航点坐标文档 转坐标集合 PS:灯光映射 支持格式 - public static Vector3[] svgToPosForLight(string path) + public static Vector3[] SvgToPosForLight(string path) { //读取文档内容 string[] arr; - arr = FlyBase.readFile(path); + arr = FlyBase.ReadFile(path); //获取飞机x轴 z轴 坐标 ArrayList tempVec = new ArrayList();//记录飞机坐标 string cx = @"cx=""(?\-{0,1}\d*\.{0,1}\d*)"""; @@ -176,15 +176,15 @@ namespace FlightRoute tempVec.Add(new Vector3(x, 0, z)); } } - Vector3[] vec = arrToVec(tempVec);//把arrlist转换成坐标集合 + Vector3[] vec = ArrToVec(tempVec);//把arrlist转换成坐标集合 return vec;//返回坐标集合 } //txt航点坐标文档 转坐标集合 PS:目前是C4D坐标文档 - public static List txtToPos(string path, out string[] flightPointNames) + public static List TxtToPos(string path, out string[] flightPointNames) { //读取文档内容 string[] arr; - arr = FlyBase.readFile(path); + arr = FlyBase.ReadFile(path); //处理文档内容 int group = 0;//获取有几组坐标 foreach (string item in arr) @@ -222,11 +222,11 @@ namespace FlightRoute return re;//out flightPointNames 输出航点名称,re返回值 返回航点集合 } //svg航点坐标文档 转坐标集合 - public static Vector3[] svgToPos(string path) + public static Vector3[] SvgToPos(string path) { //读取文档内容 string[] arr; - arr = FlyBase.readFile(path); + arr = FlyBase.ReadFile(path); //获取飞机x轴 z轴 坐标 ArrayList tempVec = new ArrayList();//记录飞机坐标 string cx = @"cx=""(?\-{0,1}\d*\.{0,1}\d*)"""; @@ -250,8 +250,8 @@ namespace FlightRoute } } //坐标集原点相对位置 移到坐标集质心 - Vector3[] vec = arrToVec(tempVec);//把arrlist转换成坐标集合 - Vector3 centerPos = getPosCenter(vec);//获取中心点 + Vector3[] vec = ArrToVec(tempVec);//把arrlist转换成坐标集合 + Vector3 centerPos = GetPosCenter(vec);//获取中心点 int key = 0; foreach (Vector3 item in vec) { @@ -262,11 +262,11 @@ namespace FlightRoute return vec;//返回坐标集合 } //obj航点坐标文档 转坐标集合 - public static Vector3[] objToPos(string path) + public static Vector3[] ObjToPos(string path) { //读取文档内容 string[] arr; - arr = FlyBase.readFile(path); + arr = FlyBase.ReadFile(path); //获取飞机x轴 z轴 坐标 string pCou = @"#\s+(?\d*)\s+vertices";//匹配obj里面标记点的数量 string pPos = @"v\s+(?\-{0,1}\d*\.{0,1}\d*)\s+(?\-{0,1}\d*\.{0,1}\d*)\s+(?\-{0,1}\d*\.{0,1}\d*)"; @@ -292,7 +292,7 @@ namespace FlightRoute linage++; } //坐标集原点相对位置 移到坐标集质心 - Vector3[] vec = arrToVec(tempVec);//把arrlist转换成坐标集合 + Vector3[] vec = ArrToVec(tempVec);//把arrlist转换成坐标集合 //重新定义中心点为原点 //Vector3 centerPos = getPosCenter(vec);//获取中心点 //int key = 0; @@ -305,7 +305,7 @@ namespace FlightRoute return vec;//返回坐标集合 } //Arraylist 转 Vector3[] 坐标集 - private static Vector3[] arrToVec(ArrayList arr) + private static Vector3[] ArrToVec(ArrayList arr) { int cou = arr.Count; Vector3[] re = new Vector3[cou]; @@ -318,7 +318,7 @@ namespace FlightRoute return re; } //数组最大值 最小值 - private static double getMaxOrMin(double[] arr, bool isMax = true) + private static double GetMaxOrMin(double[] arr, bool isMax = true) { ArrayList list = new ArrayList(arr); list.Sort(); @@ -327,7 +327,7 @@ namespace FlightRoute } //二维数组打成一维 去掉重复 - private static ArrayList twoArrToArr(ArrayList twoArr) + private static ArrayList TwoArrToArr(ArrayList twoArr) { ArrayList arr = new ArrayList(); foreach (int[] item in twoArr) @@ -339,7 +339,7 @@ namespace FlightRoute } return arr; } - private static List twoArrToArr(List twoArr)//重写 泛值List int[] + private static List TwoArrToArr(List twoArr)//重写 泛值List int[] { List arr = new List(); foreach (int[] item in twoArr) @@ -352,17 +352,17 @@ namespace FlightRoute return arr; } //两点距离 - private static double gageLength(Vector3 v1, Vector3 v2) + private static double GageLength(Vector3 v1, Vector3 v2) { return Math.Sqrt(Math.Pow(v1.x - v2.x, 2) + Math.Pow(v1.y - v2.y, 2) + Math.Pow(v1.z - v2.z, 2)); } //点乘 用来求朝向 返回0到1之间 - private static double dotPro(Vector3 v1, Vector3 v2) + private static double DotPro(Vector3 v1, Vector3 v2) { return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; } //叉乘 - private static Vector3 crossPro(Vector3 v1, Vector3 v2) + private static Vector3 CrossPro(Vector3 v1, Vector3 v2) { double x = v1.y * v2.z - v1.z * v2.y; double y = v1.z * v2.x - v1.x * v2.z; @@ -370,7 +370,7 @@ namespace FlightRoute return new Vector3(x, y, z); } //坐标置换 向量乘以矩阵(i帽j帽k帽)得到置换后的向量坐标 ps:x指向i帽 y轴指向j帽 z轴指向k帽 - private static Vector3 matrixMul(Vector3 vec, Vector3[] mat)//vec:要变换的向量 mat:矩阵标量 + private static Vector3 MatrixMul(Vector3 vec, Vector3[] mat)//vec:要变换的向量 mat:矩阵标量 { Vector3 re = new Vector3();//声明返回值 re.x = vec.x * mat[0].x + vec.y * mat[1].x + vec.z * mat[2].x; @@ -387,7 +387,7 @@ namespace FlightRoute } return false; } - private static double[] recentlyOfLine(Vector3 a1, Vector3 a2, Vector3 b1, Vector3 b2) + private static double[] RecentlyOfLine(Vector3 a1, Vector3 a2, Vector3 b1, Vector3 b2) { if (a1 == a2) a2 += 1; if (b1 == b2) b2 += 1; @@ -473,7 +473,7 @@ namespace FlightRoute return re; } //获取坐标组重心或中心 - private static Vector3 getPosCenter(Vector3[] pos, bool isCentroid = true) + private static Vector3 GetPosCenter(Vector3[] pos, bool isCentroid = true) { int cou = pos.Length; if (isCentroid)//重心 @@ -505,9 +505,9 @@ namespace FlightRoute z[key] = item.z; key++; } - double xc = (getMaxOrMin(x) + getMaxOrMin(x, false)) * .5; - double yc = (getMaxOrMin(y) + getMaxOrMin(y, false)) * .5; - double zc = (getMaxOrMin(z) + getMaxOrMin(z, false)) * .5; + double xc = (GetMaxOrMin(x) + GetMaxOrMin(x, false)) * .5; + double yc = (GetMaxOrMin(y) + GetMaxOrMin(y, false)) * .5; + double zc = (GetMaxOrMin(z) + GetMaxOrMin(z, false)) * .5; return new Vector3(xc, yc, zc); } } @@ -538,7 +538,7 @@ namespace FlightRoute //输出日志回调函数 public delegate void SomeCalculateWay(string str); //碰撞检测 - public static List airImitation(Vector3[] startPos, Vector3[] endPos, double lineDistance = 180, double spaceBetween = 900, int checkFps = 10) + public static List AirImitation(Vector3[] startPos, Vector3[] endPos, double lineDistance = 180, double spaceBetween = 900, int checkFps = 10) { int cou = startPos.Length;//飞机总数 //获取所有飞行时间 和航线距离 @@ -546,7 +546,7 @@ namespace FlightRoute double[] planesFlyTime = new double[cou];//记录所有飞行时间 for (int i = 0; i < cou; i++) { - double len = gageLength(startPos[i], endPos[i]);//距离 + double len = GageLength(startPos[i], endPos[i]);//距离 planesLen[i] = len; double flyTime = len / 300;//时间 planesFlyTime[i] = flyTime; @@ -560,7 +560,7 @@ namespace FlightRoute { if (i + 1 + x < cou) { - double distance = recentlyOfLine(startPos[i], endPos[i], startPos[i + 1 + x], endPos[i + 1 + x])[2];//航线距离 + double distance = RecentlyOfLine(startPos[i], endPos[i], startPos[i + 1 + x], endPos[i + 1 + x])[2];//航线距离 if (distance < lineDistance) { int[] z = new int[] { i, i + 1 + x }; @@ -598,7 +598,7 @@ namespace FlightRoute else endPos[second].setFormerly(startPos[second]);//归位 当前时间飞机坐标 //判断距离 碰撞记录id - if (gageLength(endPos[frist], endPos[second]) < spaceBetween + 300 * ((double)distances[i] / lineDistance))//间距小于 基础间距+300*(航线实际距离/航线检测最小距离) 既:例基础间距+航线距离的反比 + if (GageLength(endPos[frist], endPos[second]) < spaceBetween + 300 * ((double)distances[i] / lineDistance))//间距小于 基础间距+300*(航线实际距离/航线检测最小距离) 既:例基础间距+航线距离的反比 { endPos[frist] = fristFormerly;//第一架 终点回归原位 endPos[second] = secondFormerly;//第二架 终点回归原位 @@ -613,12 +613,12 @@ namespace FlightRoute return planesCollision;//返回二维数组 飞机ID从0开始 } //单机碰撞检测 - public static bool onlyImitation(int onlyPlaneId, Vector3[] startPos, Vector3[] endPos, double lineDistance = 190, double spaceBetween = 1600, int checkFps = 10)//飞机id从0开始 + public static bool OnlyImitation(int onlyPlaneId, Vector3[] startPos, Vector3[] endPos, double lineDistance = 190, double spaceBetween = 1600, int checkFps = 10)//飞机id从0开始 { //指定飞机 起始坐标 终点坐标 飞行时间 Vector3 onlyStartVec = startPos[onlyPlaneId]; Vector3 onlyEndVec = endPos[onlyPlaneId]; - double onlyFlyTime = gageLength(onlyStartVec, onlyEndVec) / 300; + double onlyFlyTime = GageLength(onlyStartVec, onlyEndVec) / 300; //选出与指定飞机 航线有交叉的飞机 用于模拟飞行碰撞检测 for (int contrastId = 0; contrastId < startPos.Length; contrastId++) { @@ -626,10 +626,10 @@ namespace FlightRoute Vector3 StartVec = startPos[contrastId];//对比飞机起始坐标 Vector3 EndVec = endPos[contrastId];//对比飞机结束坐标 // 判断两条轨迹 之间的最小距离 - double distance = recentlyOfLine(onlyStartVec, onlyEndVec, StartVec, EndVec)[2];//航线最小距离 + double distance = RecentlyOfLine(onlyStartVec, onlyEndVec, StartVec, EndVec)[2];//航线最小距离 if (distance < lineDistance) { - double flyTime = gageLength(EndVec, StartVec) / 300;//获取飞行总时间 + double flyTime = GageLength(EndVec, StartVec) / 300;//获取飞行总时间 //指定飞机 和 当前比较飞机 以飞行时间长得为总时间 int zongFlyTime;//声明 以航线较长的飞行时间 为总时长 if (onlyFlyTime >= flyTime) zongFlyTime = (int)onlyFlyTime + 1;//总时间延长一到两秒 @@ -640,16 +640,16 @@ namespace FlightRoute //飞机当前坐标 Vector3 onlyCurrentVec = onlyEndVec.setZeroEd(onlyStartVec);//归零的 当前坐标 onlyCurrentVec.normalize(300 / checkFps * currentTime);//当前时间飞行 标准化长度 坐标 - if (onlyCurrentVec.getMag() >= gageLength(onlyEndVec, onlyStartVec)) onlyCurrentVec = onlyEndVec;//溢出距离 当前坐标定义为终点位置 + if (onlyCurrentVec.getMag() >= GageLength(onlyEndVec, onlyStartVec)) onlyCurrentVec = onlyEndVec;//溢出距离 当前坐标定义为终点位置 else onlyCurrentVec.setFormerly(onlyStartVec);//归位 当前时间飞机坐标 //要进行比较飞机 当前坐标 Vector3 currentVec = EndVec.setZeroEd(StartVec);//归零的 当前坐标 currentVec.normalize(300 / checkFps * currentTime);//当前时间飞行 标准化长度 坐标 - if (currentVec.getMag() >= gageLength(EndVec, StartVec)) currentVec = EndVec;//溢出距离 当前坐标定义为终点位置 + if (currentVec.getMag() >= GageLength(EndVec, StartVec)) currentVec = EndVec;//溢出距离 当前坐标定义为终点位置 else currentVec.setFormerly(StartVec);//归位 当前时间飞机坐标 - double planeLen = gageLength(onlyCurrentVec, currentVec);//获取检测飞机s 当前间距 + double planeLen = GageLength(onlyCurrentVec, currentVec);//获取检测飞机s 当前间距 //间距小于 基础间距+800*(航线实际距离/航线检测最小距离) 既:例基础间距+航线距离的反比 if (planeLen < spaceBetween + 300 * (distance / lineDistance)) { @@ -661,14 +661,14 @@ namespace FlightRoute return false;//返回没有碰撞; } //智能挫层 - public static ArrayList collisionLayer(Vector3[] startPos, Vector3[] endPos, string axes = "y") + public static ArrayList CollisionLayer(Vector3[] startPos, Vector3[] endPos, string axes = "y") { //获取所有碰撞飞机id List planesCollisionInt = new List();//声明碰撞id组 int key = 0; foreach (var item in startPos)//遍历所有飞机 单体检测碰撞 { - if (onlyImitation(key, startPos, endPos)) planesCollisionInt.Add(key);//如果碰撞 添加到碰撞id组 + if (OnlyImitation(key, startPos, endPos)) planesCollisionInt.Add(key);//如果碰撞 添加到碰撞id组 key++; } //记录第一图案原位 @@ -696,7 +696,7 @@ namespace FlightRoute startPos[i].y = defaultPos + shiftCou / 2 * -350; endPos[i].y = defaultPos + shiftCou / 2 * -350; } - if (!(onlyImitation(i, startPos, endPos))) break;//如果 不碰撞跳出 + if (!(OnlyImitation(i, startPos, endPos))) break;//如果 不碰撞跳出 shiftCou++; } } @@ -706,7 +706,7 @@ namespace FlightRoute return middle;//返回一个二维向量数组 middle[0]是第一个中间航点 middle[1]是第二个中间航点 } //添加中间航点 群组 - private static Vector3[] setMiddleCurvedValue(Vector3[] startPos, Vector3[] endPos, double middlePos = 0.5, double scale = 1) + private static Vector3[] SetMiddleCurvedValue(Vector3[] startPos, Vector3[] endPos, double middlePos = 0.5, double scale = 1) { int cou = startPos.Length;//飞机总数 Vector3[] mps = new Vector3[cou]; @@ -717,7 +717,7 @@ namespace FlightRoute Vector3 bp = endPos[i]; mps[i] = (bp - ap) * middlePos + ap; } - Vector3 centerPos = getPosCenter(mps);//计算所有中间航点的重心点 + Vector3 centerPos = GetPosCenter(mps);//计算所有中间航点的重心点 //中间航点缩放 for (int i = 0; i < cou; i++) { @@ -726,13 +726,25 @@ namespace FlightRoute return mps; } //添加中间航点 单体 - private static Vector3 setOddMiddleCurvedValue(Vector3 startPos, Vector3 endPos, double middlePos = 0.5) + private static Vector3 SetOddMiddleCurvedValue(Vector3 startPos, Vector3 endPos, double middlePos = 0.5) { //算中间航点 Vector3 mp = (endPos - startPos) * middlePos + startPos + .1; return mp; } //3D绕行与让行 ps:起点s 中点s 终点s 需要检查的ID组 绕行比例 每个比例的绕行次数 绕行的法线偏移距离 + private static List ABNeedCheck(Vector3[] startPos, Vector3[] middlePos, Vector3[] endPos)//前航点到中间航点 中间航点到终点 所有碰撞飞机id + { + List re = new List(); + //获取从起点到中点再到结束点 所有碰撞飞机 + int key = 0; + foreach (var item in startPos) + { + if (OnlyImitation(key, startPos, middlePos) || OnlyImitation(key, middlePos, endPos)) re.Add(key);//记录 起点到中点 或者 中点到终点有碰撞的飞机 + key++; + } + return re; + } private static Vector3[] ABypassB(Vector3[] startPos, Vector3[] middlePos, Vector3[] endPos, List check, double[] mRate, int loopIndex = 800, double offsetDistance = 60)//法线螺旋线绕行 { Console.WriteLine("check:{0}", check.Count); @@ -745,7 +757,7 @@ namespace FlightRoute for (int k = 0; k < mRate.Length; k++) { //初始化位置 - middlePos[id] = setOddMiddleCurvedValue(startPos[id], endPos[id], mRate[k]); + middlePos[id] = SetOddMiddleCurvedValue(startPos[id], endPos[id], mRate[k]); //碰撞绕行 for (int i = 0; i < loopIndex; i++) { @@ -755,14 +767,14 @@ namespace FlightRoute Vector3 a = startPos[id]; Vector3 b = endPos[id]; Vector3 c = middlePos[id]; - Vector3 mp = FlyBase.crossPro(a - c, b - c);//乘差算 坐标原点上面的法线 方向向量 + Vector3 mp = FlyBase.CrossPro(a - c, b - c);//乘差算 坐标原点上面的法线 方向向量 if (k % 2 == 0) mp.normalize(offsetDistance);//正螺旋 else mp.normalize(offsetDistance * -1);//逆螺旋 middlePos[id] = mp + c; } //碰撞检测 - if (onlyImitation(id, startPos, middlePos)) continue;//前半段检测 - if (onlyImitation(id, middlePos, endPos)) continue;//后半段检测 + if (OnlyImitation(id, startPos, middlePos)) continue;//前半段检测 + if (OnlyImitation(id, middlePos, endPos)) continue;//后半段检测 pa = true; break; } @@ -772,78 +784,7 @@ namespace FlightRoute } return middlePos; } - private static List threeStageABypassB(Vector3[] startPos, Vector3[] fMiddlePos, Vector3[] middlePos, Vector3[] bMiddlePos, Vector3[] endPos, List check, double[] mRate)//三段绕 - { - //初始化 - double[] fmRate = { 0 }; - double[] bmRate = { 1 }; - //二段绕行 - foreach (int id in check) - { - bool pa = false; - Vector3 initialPos = middlePos[id];//记录初始位置 如果绕行不成功 还原位置 - for (int k = 0; k < mRate.Length; k++) - { - - //初始化位置 - middlePos[id] = setOddMiddleCurvedValue(startPos[id], endPos[id], mRate[k]); - //二段碰撞绕行 - for (int i = 0; i < 800; i++) - { - if (i != 0)//第一次保证原位置 ps:先不移动位置 检测一次 移动其他飞机之后 可能让本架飞机不碰撞 - { - //获取法线向量 - Vector3 a = startPos[id]; - Vector3 b = endPos[id]; - Vector3 c = middlePos[id]; - Vector3 mp = FlyBase.crossPro(a - c, b - c);//乘差算 坐标原点上面的法线 方向 - mp.normalize(60); - middlePos[id] = mp + c; - } - //绕一段 和 三段 - Vector3[] tempFMiddlePos;//临时存放 一段 - Vector3[] tempBMiddlePos;//临时存放 三段 - List xId = new List();//临时存放当前id 用于绕行方法 - xId.Add(id); - if (onlyImitation(id, startPos, middlePos) || onlyImitation(id, middlePos, endPos))//因为二段改变位置 检测直接二段绕行 是否通过 - { - tempFMiddlePos = FlyBase.ABypassB(startPos, fMiddlePos, middlePos, xId, fmRate, 45, 90);//一段绕行 - if (onlyImitation(id, startPos, tempFMiddlePos)) continue;//检测一段 前 重新循环二段 - else if (onlyImitation(id, tempFMiddlePos, middlePos)) continue;//检测一段 后 重新循环二段 - - tempBMiddlePos = FlyBase.ABypassB(middlePos, bMiddlePos, endPos, xId, bmRate, 45, 90);//三段绕行 - if (onlyImitation(id, startPos, tempBMiddlePos)) continue;//检测三段 前 重新循环二段 - else if (onlyImitation(id, fMiddlePos, middlePos)) continue;//检测三段 后 重新循环二段 - - fMiddlePos = tempFMiddlePos;//如果通过 更新一段坐标 - bMiddlePos = tempBMiddlePos;//如果通过 更新三段坐标 - } - pa = true; - break;//跳出 - } - if (pa) break; - } - if (!pa) middlePos[id] = initialPos;//绕行不成功 位置还原 - } - List re = new List(); - re.Add(fMiddlePos); - re.Add(middlePos); - re.Add(bMiddlePos); - return re; - } - private static List ABNeedCheck(Vector3[] startPos, Vector3[] middlePos, Vector3[] endPos)//前航点到中间航点 中间航点到终点 所有碰撞飞机id - { - List re = new List(); - //获取从起点到中点再到结束点 所有碰撞飞机 - int key = 0; - foreach (var item in startPos) - { - if (onlyImitation(key, startPos, middlePos) || onlyImitation(key, middlePos, endPos)) re.Add(key);//记录 起点到中点 或者 中点到终点有碰撞的飞机 - key++; - } - return re; - } - public static List exeABypassB(Vector3[] startPos, Vector3[] endPos, out bool isSuccess, SomeCalculateWay strPrint)//绕行获取中间航点 + public static List ExeABypassB(Vector3[] startPos, Vector3[] endPos, out bool isSuccess, SomeCalculateWay strPrint)//绕行获取中间航点 { isSuccess = false; List middlePosS = new List();//声明返回坐标集合 可能是1 到 3组坐标 既 1到3个中间航点 @@ -851,7 +792,7 @@ namespace FlightRoute List checkEd = new List();//复查绕行未通过的id组 //中段绕行 初始化 double[] mRate = { .5, .6, .4, .7, .3 };//中点绕行的比例 - Vector3[] middlePos = setMiddleCurvedValue(startPos, endPos, 0.5, 1.2);//加中间航点 + Vector3[] middlePos = SetMiddleCurvedValue(startPos, endPos, 0.5, 1.2);//加中间航点 bool pa = false; strPrint("中(二)段绕行开始"); while (true)//中段绕行循环 @@ -884,7 +825,7 @@ namespace FlightRoute else pa = false; } //一段绕行初始化 - Vector3[] fMiddlePos = setMiddleCurvedValue(startPos, middlePos, 0, 1); + Vector3[] fMiddlePos = SetMiddleCurvedValue(startPos, middlePos, 0, 1); double[] fmRate = { 0, .05, .1, .15, .2 };//中点绕行的比例 pa = false; check = ABNeedCheck(startPos, fMiddlePos, middlePos); @@ -923,7 +864,7 @@ namespace FlightRoute //添加中段绕行结果 middlePosS.Add(middlePos); //三段绕行初始化 - Vector3[] bMiddlePos = setMiddleCurvedValue(middlePos, endPos, 1, 1); + Vector3[] bMiddlePos = SetMiddleCurvedValue(middlePos, endPos, 1, 1); double[] bmRate = { 1, .95, 0.9, .85, .8 };//中点绕行的比例 pa = false; check = ABNeedCheck(middlePos, bMiddlePos, endPos); diff --git a/FlyExe/MainWindow.xaml.cs b/FlyExe/MainWindow.xaml.cs index 50ba406..80c54e6 100644 --- a/FlyExe/MainWindow.xaml.cs +++ b/FlyExe/MainWindow.xaml.cs @@ -27,7 +27,7 @@ namespace FlyExe InitializeComponent(); } //保存输出文本 - private static void saveFile(string filePath, string txtCon) + private static void SaveFile(string filePath, string txtCon) { txtCon = txtCon.TrimEnd((char[])"\n\r".ToCharArray());//去除最后的回车符 Console.WriteLine(txtCon); @@ -58,9 +58,9 @@ namespace FlyExe strPrint("开始"); if (ofdl.ShowDialog() == true) { - List txt = FlyBase.txtToPos(ofdl.FileName, out string[] fightNames);//从txt文件里面读取航点 信息 + List txt = FlyBase.TxtToPos(ofdl.FileName, out string[] fightNames);//从txt文件里面读取航点 信息 //3D绕行计算 - List txtC = FlyBase.exeABypassB(txt[0], txt[1], out this.isSuccess, strPrint); + List txtC = FlyBase.ExeABypassB(txt[0], txt[1], out this.isSuccess, strPrint); string txta = ""; string txtb = ""; string txtc = ""; @@ -72,9 +72,9 @@ namespace FlyExe if (txtC.Count > 2) txtc += id + " 0" + " " + txtC[2][id - 1].x + " " + txtC[2][id - 1].y + " " + txtC[2][id - 1].z + "\r\n"; id++; } - saveFile("C:/Users/ddkk/Desktop/a.txt", txta); - if (txtC.Count > 1) saveFile("C:/Users/ddkk/Desktop/b.txt", txtb); - if (txtC.Count > 2) saveFile("C:/Users/ddkk/Desktop/c.txt", txtc); + SaveFile("C:/Users/ddkk/Desktop/a.txt", txta); + if (txtC.Count > 1) SaveFile("C:/Users/ddkk/Desktop/b.txt", txtb); + if (txtC.Count > 2) SaveFile("C:/Users/ddkk/Desktop/c.txt", txtc); } if (this.isSuccess == true) {