private void DrawArrow(Graphics gr, Pen pen, PointF p1, PointF p2, EndpointStyle style1, EndpointStyle style2) { // Draw the shaft. gr.DrawLine(pen, p1, p2); // Find the arrow shaft unit vector. float vx = p2.X - p1.X; float vy = p2.Y - p1.Y; float dist = (float)Math.Sqrt(vx * vx + vy * vy); vx /= dist; vy /= dist; float length = dist / 4; if (dist < 4) // do not try to paint arrow with length < 1 { if (dist >= 1) // paint nothing if line is < 1 { gr.DrawLine(pen, p1, p2); } return; } // Draw the start. if (style1 == EndpointStyle.ArrowHead) { DrawArrowhead(gr, pen, p1, -vx, -vy, length); } else if (style1 == EndpointStyle.Fletching) { DrawArrowhead(gr, pen, p1, vx, vy, length); } // Draw the end. if (style2 == EndpointStyle.ArrowHead) { DrawArrowhead(gr, pen, p2, vx, vy, length); } else if (style2 == EndpointStyle.Fletching) { DrawArrowhead(gr, pen, p2, -vx, -vy, length); } }
// Draw arrow heads or tails for the // segment from p1 to p2. private static void DrawArrow(DrawingContext gr, Pen pen, Point p1, Point p2, double length, EndpointStyle style1, EndpointStyle style2) { // Draw the shaft. gr.DrawLine(pen, p1, p2); // Find the arrow shaft unit vector. double vx = p2.X - p1.X; double vy = p2.Y - p1.Y; float dist = (float)Math.Sqrt(vx * vx + vy * vy); vx /= dist; vy /= dist; // Draw the start. if (style1 == EndpointStyle.ArrowHead) { DrawArrowhead(gr, pen, p1, -vx, -vy, length); } else if (style1 == EndpointStyle.Fletching) { DrawArrowhead(gr, pen, p1, vx, vy, length); } // Draw the end. if (style2 == EndpointStyle.ArrowHead) { DrawArrowhead(gr, pen, p2, vx, vy, length); } else if (style2 == EndpointStyle.Fletching) { DrawArrowhead(gr, pen, p2, -vx, -vy, length); } }