Draw Straight and Curved Arrows






4.88/5 (29 votes)
Render custom arrows on any graphics
ArrowRenderer
routines. Drawing random colored curved arrows.Introduction
This article presents some useful routines that help drawing custom arrows on any Graphics
object. It allows to choose whether an arrow should be straight or curved. In the second case, the main arrow line is drawn using the Bezier curve.
Background
I know that any question about how to draw an arrow is probably answered quickly, advising the inquirer to read something about different line ending caps. That is true, however one doesn't have a big influence on how the final arrow will be like. Pissed about that, I decided to write my own library that allows a user to draw custom arrows both straight and curved.
Code
Width
- Gets or sets width (in pixels) of the full base of the arrowheadTheta
- Gets or sets angle (in radians) at the arrow tip between the two sides of the arrowheadFillArrowHead
- Gets or sets flag indicating whether or not the arrowhead should be filledNumberOfBezierCurveNodes
- Gets or sets the number of nodes used to calculate the Bezier curve
DrawArrow
- Renders the arrow on given graphics using desired parametersDrawArrowOnCurve
- Renders the curved arrow on given graphics using desired parametersDrawArrows
- Draws arrows between consecutive points
Points of Interest
This code is especially useful when graphs need to be rendered. DrawArrows
is particularly useful for that.
Sample Usage
Last semester, I was developing a program that solves the Vehicle Routing Problem for a project at Operational Research. That approach used genetic algorithms. The following picture was generated using my renderer that utilizes, among others, the presented ArrowRenderer
class. Grey circles represent depots, while red ones are cities that need to be visited. Arrows are used to show how the route should be performed.

Credit
- Routine that generates the Bezier curve nodes array is a refined version of the one found in "Beziers and Other Splines" chapter from "Programming Microsoft Windows with C#" by Charles Petzold.
- Simple
Vector
structure was found long ago somewhere on the Internet. If you own this piece of code, please let me know so I can give you credit.
History
- 30.01.2007 - First version