方法名改大驼峰
This commit is contained in:
parent
3066643bf1
commit
2ef44cdd54
Binary file not shown.
@ -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=""(?<mark>\-{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<Vector3[]> txtToPos(string path, out string[] flightPointNames)
|
||||
public static List<Vector3[]> 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=""(?<mark>\-{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+(?<mark>\d*)\s+vertices";//匹配obj里面标记点的数量
|
||||
string pPos = @"v\s+(?<markX>\-{0,1}\d*\.{0,1}\d*)\s+(?<markY>\-{0,1}\d*\.{0,1}\d*)\s+(?<markZ>\-{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<int> twoArrToArr(List<int[]> twoArr)//重写 泛值List int[]
|
||||
private static List<int> TwoArrToArr(List<int[]> twoArr)//重写 泛值List int[]
|
||||
{
|
||||
List<int> arr = new List<int>();
|
||||
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<int[]> airImitation(Vector3[] startPos, Vector3[] endPos, double lineDistance = 180, double spaceBetween = 900, int checkFps = 10)
|
||||
public static List<int[]> 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<int> planesCollisionInt = new List<int>();//声明碰撞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<int> ABNeedCheck(Vector3[] startPos, Vector3[] middlePos, Vector3[] endPos)//前航点到中间航点 中间航点到终点 所有碰撞飞机id
|
||||
{
|
||||
List<int> re = new List<int>();
|
||||
//获取从起点到中点再到结束点 所有碰撞飞机
|
||||
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<int> 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<Vector3[]> threeStageABypassB(Vector3[] startPos, Vector3[] fMiddlePos, Vector3[] middlePos, Vector3[] bMiddlePos, Vector3[] endPos, List<int> 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<int> xId = new List<int>();//临时存放当前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<Vector3[]> re = new List<Vector3[]>();
|
||||
re.Add(fMiddlePos);
|
||||
re.Add(middlePos);
|
||||
re.Add(bMiddlePos);
|
||||
return re;
|
||||
}
|
||||
private static List<int> ABNeedCheck(Vector3[] startPos, Vector3[] middlePos, Vector3[] endPos)//前航点到中间航点 中间航点到终点 所有碰撞飞机id
|
||||
{
|
||||
List<int> re = new List<int>();
|
||||
//获取从起点到中点再到结束点 所有碰撞飞机
|
||||
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<Vector3[]> exeABypassB(Vector3[] startPos, Vector3[] endPos, out bool isSuccess, SomeCalculateWay strPrint)//绕行获取中间航点
|
||||
public static List<Vector3[]> ExeABypassB(Vector3[] startPos, Vector3[] endPos, out bool isSuccess, SomeCalculateWay strPrint)//绕行获取中间航点
|
||||
{
|
||||
isSuccess = false;
|
||||
List<Vector3[]> middlePosS = new List<Vector3[]>();//声明返回坐标集合 可能是1 到 3组坐标 既 1到3个中间航点
|
||||
@ -851,7 +792,7 @@ namespace FlightRoute
|
||||
List<int> checkEd = new List<int>();//复查绕行未通过的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);
|
||||
|
@ -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<Vector3[]> txt = FlyBase.txtToPos(ofdl.FileName, out string[] fightNames);//从txt文件里面读取航点 信息
|
||||
List<Vector3[]> txt = FlyBase.TxtToPos(ofdl.FileName, out string[] fightNames);//从txt文件里面读取航点 信息
|
||||
//3D绕行计算
|
||||
List<Vector3[]> txtC = FlyBase.exeABypassB(txt[0], txt[1], out this.isSuccess, strPrint);
|
||||
List<Vector3[]> 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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user