灯标点逻辑
This commit is contained in:
@@ -230,20 +230,29 @@ namespace 头罩视野.Services
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 设备固定参数
|
// 设备固定参数
|
||||||
private static double R = 330; // 半球半径
|
private static double R = 330; // 半球半径
|
||||||
private static double angleStep = 10; // 每格角度
|
private static double angleStep = 10; // 每格角度
|
||||||
|
|
||||||
|
// 定义参数(和你代码里一致)
|
||||||
|
private const int totalLights = 81;
|
||||||
|
|
||||||
// 传入:72个灯的亮灭数据(0=灭,1=亮)
|
// 传入:72个灯的亮灭数据(0=灭,1=亮)
|
||||||
// 返回:椭圆面积
|
// 返回:椭圆面积
|
||||||
public static double CalculateEllipseArea(int[] lightData, List<(int m, int n)> lightPositions)
|
public static double CalculateEllipseArea(int[] lightData, List<(int m, int n)> lightPositions)
|
||||||
{
|
{
|
||||||
if (lightData.Length != 72 || lightPositions.Count != 72)
|
//if (lightData.Length != totalLights || lightPositions.Count != totalLights)
|
||||||
throw new Exception("必须是72个灯的数据");
|
// throw new Exception("必须是81个灯的数据");
|
||||||
|
|
||||||
// 第一步:收集所有亮灯坐标
|
// 第一步:收集所有亮灯坐标
|
||||||
List<System.Drawing.Point> brightPoints = new List<System.Drawing.Point>();
|
List<System.Drawing.Point> brightPoints = new List<System.Drawing.Point>();
|
||||||
for (int i = 0; i < 72; i++)
|
for (int i = 0; i < totalLights; i++)
|
||||||
{
|
{
|
||||||
if (lightData[i] == 1)
|
if (lightData[i] == 1)
|
||||||
{
|
{
|
||||||
@@ -258,19 +267,39 @@ namespace 头罩视野.Services
|
|||||||
|
|
||||||
// 返回面积
|
// 返回面积
|
||||||
return area;
|
return area;
|
||||||
}
|
}
|
||||||
|
/// 生成设备全部243盏灯的(m,n)位置 上爪1条、下爪1条、左右共用1条,各81灯
|
||||||
// 格数 m,n → 坐标点
|
|
||||||
private static System.Drawing.Point GetLightPoint(int m, int n)
|
private static System.Drawing.Point GetLightPoint(int m, int n)
|
||||||
{
|
{
|
||||||
double radH = m * angleStep * Math.PI / 180;
|
double radH, radV;
|
||||||
double radV = n * angleStep * Math.PI / 180;
|
|
||||||
|
// 上爪灯条(n=0):水平角固定,m控制垂直角
|
||||||
|
if (n == 0)
|
||||||
|
{
|
||||||
|
radH = 0;
|
||||||
|
radV = m * angleStep * Math.PI / 180;
|
||||||
|
}
|
||||||
|
// 下爪灯条(n=1):水平角固定为180°,m控制垂直角
|
||||||
|
else if (n == 1)
|
||||||
|
{
|
||||||
|
radH = Math.PI;
|
||||||
|
radV = m * angleStep * Math.PI / 180;
|
||||||
|
}
|
||||||
|
// 左右共用灯条(n=2):垂直角固定,m控制水平角
|
||||||
|
else
|
||||||
|
{
|
||||||
|
radH = m * angleStep * Math.PI / 180;
|
||||||
|
radV = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保留你原来的投影公式
|
||||||
double x = R * Math.Tan(radH);
|
double x = R * Math.Tan(radH);
|
||||||
double y = R * Math.Tan(radV);
|
double y = R * Math.Tan(radV);
|
||||||
return new System.Drawing.Point((int)x, (int)y);
|
|
||||||
|
return new System.Drawing.Point((int)Math.Round(x), (int)Math.Round(y));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 最小二乘法拟合椭圆(核心算法)
|
// 最小二乘法拟合椭圆(核心算法)cx:椭圆中心点的 X 坐标 cy:椭圆中心点的 Y 坐标 a:椭圆的长半轴长度(较大的那个半径)b:椭圆的短半轴长度(较小的那个半径)
|
||||||
|
|
||||||
|
|
||||||
private static (double cx, double cy, double a, double b, double area) FitEllipse(List<Point> points)
|
private static (double cx, double cy, double a, double b, double area) FitEllipse(List<Point> points)
|
||||||
@@ -313,9 +342,26 @@ namespace 头罩视野.Services
|
|||||||
if (a < b) (a, b) = (b, a);
|
if (a < b) (a, b) = (b, a);
|
||||||
double area = Math.PI * a * b;
|
double area = Math.PI * a * b;
|
||||||
|
|
||||||
return (cx, cy, a, b, area);
|
return (cx, cy, a, b, area);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
//private static System.Drawing.Point GetLightPoint(int m, int n)
|
||||||
|
//{
|
||||||
|
// double radH = m * angleStep * Math.PI / 180;
|
||||||
|
// double radV = n * angleStep * Math.PI / 180;
|
||||||
|
// double x = R * Math.Tan(radH);
|
||||||
|
// double y = R * Math.Tan(radV);
|
||||||
|
// return new System.Drawing.Point((int)x, (int)y);
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ namespace 头罩视野.Views
|
|||||||
{
|
{
|
||||||
public partial class PageTest : Page
|
public partial class PageTest : Page
|
||||||
{
|
{
|
||||||
|
|
||||||
/// 只加这一个变量
|
/// 只加这一个变量
|
||||||
private CancellationTokenSource? _cts;
|
private CancellationTokenSource? _cts;
|
||||||
private IModbusMaster _modbusMaster => ModbusResourceManager.Instance.ModbusMaster;
|
private IModbusMaster _modbusMaster => ModbusResourceManager.Instance.ModbusMaster;
|
||||||
|
|||||||
Reference in New Issue
Block a user