点点距测量工具:端点由点改为线段

This commit is contained in:
李伟
2026-05-06 13:27:41 +08:00
parent 7846445b33
commit 8dbc274e63
2 changed files with 126 additions and 1 deletions
@@ -9,12 +9,21 @@ namespace XP.ImageProcessing.RoiControl.Models
/// <summary>一次点点距测量的所有视觉元素</summary>
public class MeasureGroup
{
// 保留原有圆点属性以兼容其他代码
public Ellipse Dot1 { get; set; }
public Ellipse Dot2 { get; set; }
// 新增:垂直线段(替代圆点的视觉表现)
public Line PerpLine1 { get; set; }
public Line PerpLine2 { get; set; }
public Line Line { get; set; }
public TextBlock Label { get; set; }
public Point P1 { get; set; }
public Point P2 { get; set; }
/// <summary>垂直线段长度(像素)</summary>
public double PerpLineLength { get; set; } = 10.0;
public double Distance
{
@@ -30,6 +39,46 @@ namespace XP.ImageProcessing.RoiControl.Models
Line.X1 = P1.X; Line.Y1 = P1.Y;
Line.X2 = P2.X; Line.Y2 = P2.Y;
Line.Visibility = Visibility.Visible;
// 更新垂直线段位置
UpdatePerpLines();
}
/// <summary>更新两条垂直线段的位置</summary>
public void UpdatePerpLines()
{
if (PerpLine1 == null || PerpLine2 == null) return;
// 计算两点连线的方向向量
double dx = P2.X - P1.X;
double dy = P2.Y - P1.Y;
double len = Math.Sqrt(dx * dx + dy * dy);
if (len < 0.001) return; // 避免除零
// 归一化方向向量
double ux = dx / len;
double uy = dy / len;
// 垂直方向向量 (-uy, ux)
double vx = -uy;
double vy = ux;
// P1处的垂直线段
double halfLen1 = PerpLineLength / 2;
PerpLine1.X1 = P1.X + vx * halfLen1;
PerpLine1.Y1 = P1.Y + vy * halfLen1;
PerpLine1.X2 = P1.X - vx * halfLen1;
PerpLine1.Y2 = P1.Y - vy * halfLen1;
PerpLine1.Visibility = Visibility.Visible;
// P2处的垂直线段
double halfLen2 = PerpLineLength / 2;
PerpLine2.X1 = P2.X + vx * halfLen2;
PerpLine2.Y1 = P2.Y + vy * halfLen2;
PerpLine2.X2 = P2.X - vx * halfLen2;
PerpLine2.Y2 = P2.Y - vy * halfLen2;
PerpLine2.Visibility = Visibility.Visible;
}
public void UpdateLabel(string distanceText = null)