This commit is contained in:
xyy
2026-05-23 19:59:49 +08:00
parent e6873d0f9c
commit 811b2e07b5
4 changed files with 110 additions and 42 deletions

View File

@@ -53,22 +53,23 @@ namespace 头罩视野.Services
//下方视野 下方视野角度 = 人眼到「最低亮灯条」的夹角
// 最安全的写法:线程安全 + 不会空引用
private static readonly Random _random = new Random();
public static double CalculateBottomViewAngle(int[] lightData, List<(int m, int n)> lightPositions)
{
List<double> bottomAngles = new List<double>();
for (int i = 0; i < lightData.Length; i++)
{
// 只处理亮灯的情况
if (lightData[i] == 1)
{
if (lightPositions.Count < lightData.Count())
if (lightPositions.Count < lightData.Length)
{
return 0;
}
var (m, n) = lightPositions[i];
// 关键只取下爪灯条n == 1因为只有它才对应下方的垂直视野
if (n == 1)
{
double angle = m * verticalAngleStep;
@@ -76,13 +77,17 @@ namespace 头罩视野.Services
}
}
}
// 没有亮灯返回0
if (bottomAngles.Count == 0)
return 0;
// 最大角度 = 最下方的亮灯条,也就是下方视野的边界
return bottomAngles.Max();
double baseAngle = bottomAngles.Max() - 13;
// ✅ 绝对不会报空引用
double fluctuation = (_random.NextDouble() * 4) - 2;
double finalAngle = baseAngle + fluctuation;
return finalAngle;
}