DynamicArray(int Size, params T[] ArrData) { this.Size = Size; this.Arr = new T[this.Size]; try { ArrData.CopyTo(Arr, 0); } catch (Exception ex) { for (int i = 0; i < Size; i++) { Arr[i] = default(T); } } }
public static MyPoint FindPointWithAngle(List <MyPoint> data, int step = 30, int count = 5, double DifAngle = 10) { //первая точка с последующими по углу List <ArrData> LeftData = new List <ArrData>(); List <ArrData> RightData = new List <ArrData>(); for (int i = 0; i < data.Count; i += step) { LeftData.Add(new ArrData() { FirstIndex = 0, SecondIndex = i, Difference = Math.Atan2(data[i].Z - data[0].Z, data[i].X - data[0].X) * 180 / Math.PI }); } //Console.Clear(); //Console.WriteLine($"LeftData Count {LeftData.Count} :"); //foreach (ArrData item in LeftData) { // Console.WriteLine($"{item.FirstIndex} \t {item.SecondIndex} \t {item.Difference}"); //} //Console.WriteLine($"||||||||||||||||||||||||||||"); int tempCount = 0; ArrData tempAngle = LeftData[0]; int leftIndex = 0; int rightIndex = 0; double AverageAngle = 0; for (int i = 3; i < 13; i++) { AverageAngle += LeftData[i].Difference; } AverageAngle /= 10; for (int i = 0; i < LeftData.Count; i++) { //if (LeftData[i].Difference * tempAngle.Difference < 0) { //if (LeftData[i].Difference < 0) { if (Math.Abs(LeftData[i].Difference - AverageAngle) > DifAngle) { tempCount++; } else { if (tempCount >= count) { leftIndex = tempAngle.SecondIndex; rightIndex = LeftData[i].SecondIndex; break; } else { tempAngle = LeftData[i]; tempCount = 0; } } } return(new MyPoint() { X = (data[leftIndex].X + data[rightIndex].X) / 2, Z = (data[leftIndex].Z + data[rightIndex].Z) / 2 }); }
public static MyPoint FindPointWithAngleRight(List <MyPoint> data, int step = 30, int count = 5) { List <ArrData> RightData = new List <ArrData>(); for (int i = data.Count - 1; i > 0; i -= step) { RightData.Add(new ArrData() { FirstIndex = data.Count - 1, SecondIndex = i, Difference = Math.Atan2(data[i].Z - data[data.Count - 1].Z, data[i].X - data[data.Count - 1].X) * 180 / Math.PI }); } if (RightData.Count == 0) { return(new MyPoint() { X = 0, Z = 0 }); } int tempCount = 0; ArrData tempAngle = RightData[0]; int leftIndex = 0; int rightIndex = 0; for (int i = 0; i < RightData.Count; i++) { //if (LeftData[i].Difference * tempAngle.Difference < 0) { if (RightData[i].Difference < 0) { tempCount++; } else { if (tempCount >= count) { leftIndex = tempAngle.SecondIndex; rightIndex = RightData[i].SecondIndex; break; } else { tempAngle = RightData[i]; tempCount = 0; } } } MyPoint result = new MyPoint() { X = (data[leftIndex].X + data[rightIndex].X) / 2, Z = (data[leftIndex].Z + data[rightIndex].Z) / 2 }; int pCountOnLine = 0; for (int i = 0; i < data.Count; i++) { if (data[i].X <data[rightIndex].X && data[i].X> data[leftIndex].X) { if (Math.Abs(data[i].Z - result.Z) < 2) { pCountOnLine++; } } } if (pCountOnLine < 20) { return(result); } //Console.WriteLine($"2 {data[rightIndex].Z} {data[leftIndex].Z}"); return(new MyPoint() { X = 0, Z = 0 }); // return new MyPoint() { X = (data[leftIndex].X + data[rightIndex].X) / 2, Z = (data[leftIndex].Z + data[rightIndex].Z) / 2 }; }
public static MyPoint FindPointWithAngle(List <MyPoint> data, int step = 30, int count = 5) { //первая точка с последующими по углу List <ArrData> LeftData = new List <ArrData>(); List <ArrData> RightData = new List <ArrData>(); for (int i = 0; i < data.Count; i += step) { LeftData.Add(new ArrData() { FirstIndex = 0, SecondIndex = i, Difference = Math.Atan2(data[i].Z - data[0].Z, data[i].X - data[0].X) * 180 / Math.PI }); } //for (int i = data.Count - 1; i > 0; i -= step) { // RightData.Add(new ArrData() { // FirstIndex = data.Count - 1, // SecondIndex = i, // Difference = -Math.Atan2(data[i].Z - data[data.Count - 1].Z, data[i].X - data[data.Count - 1].X) * 180 / Math.PI // }); //} //Console.Clear(); //Console.WriteLine($"LeftData Count {LeftData.Count} :"); //foreach (ArrData item in LeftData) { // Console.WriteLine($"{item.FirstIndex} \t {item.SecondIndex} \t {item.Difference}"); //} //Console.WriteLine($"||||||||||||||||||||||||||||"); //Console.WriteLine($"RightData Count {RightData.Count} :"); //foreach (ArrData item in RightData) { // Console.WriteLine($"{item.FirstIndex} \t {item.SecondIndex} \t {item.Difference}"); //} //Console.WriteLine($"||||||||||||||||||||||||||||"); int tempCount = 0; ArrData tempAngle = LeftData[0]; int leftIndex = 0; int rightIndex = 0; for (int i = 0; i < LeftData.Count; i++) { //if (LeftData[i].Difference * tempAngle.Difference < 0) { if (LeftData[i].Difference < 0) { tempCount++; } else { if (tempCount >= count) { leftIndex = tempAngle.SecondIndex; rightIndex = LeftData[i].SecondIndex; break; } else { tempAngle = LeftData[i]; tempCount = 0; } } } if (leftIndex == 0 && rightIndex == 0) { //Console.WriteLine($"1 {data[rightIndex].Z} {data[leftIndex].Z}"); return(FindPointWithAngleRight(data, step, count)); } MyPoint result = new MyPoint() { X = (data[leftIndex].X + data[rightIndex].X) / 2, Z = (data[leftIndex].Z + data[rightIndex].Z) / 2 }; int pCountOnLine = 0; for (int i = 0; i < data.Count; i++) { if (data[i].X <data[leftIndex].X && data[i].X> data[rightIndex].X) { if (Math.Abs(data[i].Z - result.Z) < 2) { pCountOnLine++; } } } if (pCountOnLine < 20) { return(result); } //else { // // Console.WriteLine($"11 {data[rightIndex].Z} {data[leftIndex].Z}"); // return FindPointWithAngleRight(data, step, count); //} return(new MyPoint() { X = 0, Z = 0 }); }