页面逻辑调整
This commit is contained in:
@@ -29,6 +29,27 @@ namespace 头罩视野.Services
|
||||
return _standardTotalArea - binocularTotalArea;
|
||||
}
|
||||
|
||||
|
||||
//计算双目视野
|
||||
|
||||
public static double CalculateBinocularArea(
|
||||
List<int> leftFinal,
|
||||
List<int> rightFinal,
|
||||
List<(int m, int n)> lightPositions)
|
||||
{
|
||||
// 双目并集:左眼亮 OR 右眼亮 = 亮
|
||||
int[] binocularData = new int[243];
|
||||
for (int i = 0; i < 243; i++)
|
||||
{
|
||||
binocularData[i] = leftFinal[i] | rightFinal[i];
|
||||
}
|
||||
|
||||
// 计算面积
|
||||
return CalculateEllipseArea(binocularData, lightPositions);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//下方视野 下方视野角度 = 人眼到「最低亮灯条」的夹角
|
||||
|
||||
public static double CalculateBottomViewAngle(int[] lightData, List<(int m, int n)> lightPositions)
|
||||
@@ -107,101 +128,6 @@ namespace 头罩视野.Services
|
||||
}
|
||||
|
||||
|
||||
//// 传入:81个灯的亮灭数据(0=灭,1=亮)
|
||||
//// 返回:椭圆面积
|
||||
//public static double CalculateEllipseArea(int[] lightData, List<(int m, int n)> lightPositions)
|
||||
//{
|
||||
// //if (lightData.Length != totalLights || lightPositions.Count != totalLights)
|
||||
// // throw new Exception("必须是81个灯的数据");
|
||||
|
||||
// // 第一步:收集所有亮灯坐标
|
||||
// List<System.Drawing.Point> brightPoints = new List<System.Drawing.Point>();
|
||||
// for (int i = 0; i < totalLights; i++)
|
||||
// {
|
||||
// if (totalLights > lightData.Count())
|
||||
// {
|
||||
|
||||
// }
|
||||
// if (lightData[i] == 1)
|
||||
// {
|
||||
|
||||
|
||||
// var (m, n) = lightPositions[i];
|
||||
// System.Drawing.Point p = GetLightPoint(m, n);
|
||||
// brightPoints.Add(p);
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 第二步:用亮点拟合椭圆
|
||||
// var (cx, cy, a, b, area) = FitEllipse(brightPoints);
|
||||
|
||||
// // 返回面积
|
||||
// return area;
|
||||
//}
|
||||
|
||||
//public static double CalculateEllipseArea(int[] lightData, List<(int m, int n)> lightPositions)
|
||||
//{
|
||||
// // 日志:方法入口
|
||||
// System.Diagnostics.Debug.WriteLine($"===== CalculateEllipseArea 开始 =====");
|
||||
// System.Diagnostics.Debug.WriteLine($"lightData.Length = {lightData?.Length ?? 0}");
|
||||
// System.Diagnostics.Debug.WriteLine($"lightPositions.Count = {lightPositions?.Count ?? 0}");
|
||||
// System.Diagnostics.Debug.WriteLine($"totalLights = {totalLights}");
|
||||
|
||||
// // 1. 参数校验
|
||||
// if (lightData == null || lightPositions == null)
|
||||
// {
|
||||
// System.Diagnostics.Debug.WriteLine("错误:lightData 或 lightPositions 为 null");
|
||||
// return double.NaN;
|
||||
// }
|
||||
|
||||
// if (lightData.Length != totalLights || lightPositions.Count != totalLights)
|
||||
// {
|
||||
// System.Diagnostics.Debug.WriteLine($"数据长度不匹配:lightData.Length={lightData.Length}, totalLights={totalLights}, lightPositions.Count={lightPositions.Count}");
|
||||
// // 这里可以根据实际需要决定是否抛出异常或使用较小长度继续
|
||||
// }
|
||||
|
||||
// // 2. 收集亮灯坐标
|
||||
// List<System.Drawing.Point> brightPoints = new List<System.Drawing.Point>();
|
||||
// for (int i = 0; i < totalLights && i < lightData.Length && i < lightPositions.Count; i++)
|
||||
// {
|
||||
// if (lightData[i] == 1)
|
||||
// {
|
||||
// var (m, n) = lightPositions[i];
|
||||
// System.Drawing.Point p = GetLightPoint(m, n);
|
||||
// brightPoints.Add(p);
|
||||
// }
|
||||
// }
|
||||
|
||||
// System.Diagnostics.Debug.WriteLine($"收集到的亮灯点数:{brightPoints.Count}");
|
||||
|
||||
// if (brightPoints.Count < 5)
|
||||
// {
|
||||
// System.Diagnostics.Debug.WriteLine($"警告:亮灯点不足5个(实际{brightPoints.Count}),无法拟合椭圆,返回 NaN");
|
||||
// return double.NaN;
|
||||
// }
|
||||
|
||||
// // 3. 拟合椭圆
|
||||
// var (cx, cy, a, b, area) = FitEllipse(brightPoints);
|
||||
|
||||
// System.Diagnostics.Debug.WriteLine($"拟合结果:cx={cx}, cy={cy}, a={a}, b={b}, area={area}");
|
||||
|
||||
// if (double.IsNaN(a) || double.IsNaN(b) || double.IsNaN(area))
|
||||
// {
|
||||
// System.Diagnostics.Debug.WriteLine("错误:拟合结果包含 NaN");
|
||||
// return double.NaN;
|
||||
// }
|
||||
|
||||
// if (a <= 0 || b <= 0)
|
||||
// {
|
||||
// System.Diagnostics.Debug.WriteLine($"错误:椭圆半轴无效(a={a}, b={b}),面积计算将得到 NaN 或 0");
|
||||
// return double.NaN;
|
||||
// }
|
||||
|
||||
// System.Diagnostics.Debug.WriteLine($"最终返回面积:{area}");
|
||||
// return area;
|
||||
//}
|
||||
|
||||
|
||||
public static double CalculateEllipseArea(int[] lightData, List<(int m, int n)> lightPositions)
|
||||
{
|
||||
// 参数有效性检查
|
||||
|
||||
Reference in New Issue
Block a user