/// <summary>
/// 绘制箭头
/// </summary>
/// <param name="graphics"></param>
/// <param name="startPoint">起始点</param>
/// <param name="endPoint">终止点</param>
private void DrawArrowHead(Graphics graphics, PointF startPoint, PointF endPoint)
{
double distance = Math.Abs(Math.Sqrt(
(startPoint.X - endPoint.X) * (startPoint.X - endPoint.X) +
(startPoint.Y - endPoint.Y) * (startPoint.Y - endPoint.Y)));
if (distance == 0)
{
return;
}
double xa = endPoint.X + ArrowLength * ((startPoint.X - endPoint.X)
+ (startPoint.Y - endPoint.Y) / RelativeValue) / distance;
double ya = endPoint.Y + ArrowLength * ((startPoint.Y - endPoint.Y)
- (startPoint.X - endPoint.X) / RelativeValue) / distance;
double xb = endPoint.X + ArrowLength * ((startPoint.X - endPoint.X)
- (startPoint.Y - endPoint.Y) / RelativeValue) / distance;
double yb = endPoint.Y + ArrowLength * ((startPoint.Y - endPoint.Y)
+ (startPoint.X - endPoint.X) / RelativeValue) / distance;
PointF[] polygonPoints ={
new PointF(endPoint.X , endPoint.Y),
new PointF( (float)xa , (float)ya),
new PointF( (float)xb , (float)yb)};
DrawArrowHead(graphics, polygonPoints);
}
private static void DrawArrowHead(Graphics graphics, PointF[] points)
{
graphics.DrawPolygon(Pens.Red, points);
graphics.FillPolygon(new SolidBrush(Color.Red), points);
}