箭头位置,指向连接点的中心

This commit is contained in:
艾竹
2023-01-15 22:17:46 +08:00
parent 5bdf10445f
commit 718d8c01e9
9 changed files with 102 additions and 28 deletions

View File

@@ -9,18 +9,20 @@ namespace AIStudio.Wpf.DiagramDesigner
public static double SourceMarkerAdjustement(PointBase[] route, double markerWidth)
{
var angleInRadians = Math.Atan2(route[1].Y - route[0].Y, route[1].X - route[0].X) + Math.PI;
var xChange = markerWidth * Math.Cos(angleInRadians);
var yChange = markerWidth * Math.Sin(angleInRadians);
route[0] = new PointBase(route[0].X - xChange, route[0].Y - yChange);
//不需要留出箭头的位置
//var xChange = markerWidth * Math.Cos(angleInRadians);
//var yChange = markerWidth * Math.Sin(angleInRadians);
//route[0] = new PointBase(route[0].X - xChange, route[0].Y - yChange);
return angleInRadians * 180 / Math.PI;
}
public static double TargetMarkerAdjustement(PointBase[] route, double markerWidth)
{
var angleInRadians = Math.Atan2(route[route.Length - 1].Y - route[route.Length - 2].Y, route[route.Length - 1].X - route[route.Length - 2].X);
var xChange = markerWidth * Math.Cos(angleInRadians);
var yChange = markerWidth * Math.Sin(angleInRadians);
route[route.Length - 1] = new PointBase(route[route.Length - 1].X - xChange, route[route.Length - 1].Y - yChange);
//不需要留出箭头的位置
//var xChange = markerWidth * Math.Cos(angleInRadians);
//var yChange = markerWidth * Math.Sin(angleInRadians);
//route[route.Length - 1] = new PointBase(route[route.Length - 1].X - xChange, route[route.Length - 1].Y - yChange);
return angleInRadians * 180 / Math.PI;
}