Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDraw arrows
Keywordsarrow, arrowhead, lines
CategoriesGraphics
 
If is a vector between two points, then <-v2, v1> is a perpendicular vector of the same length. The new vector minus the original vector is <-v2 - v1, v1 - v2> gives a vector in the proper direction for one barb on the arrowhead. Minus the perpendicular vector minus the original vector gives a new vector in the direction for the other barb. The code uses similar vector algebra to find the vectors for arrow fletchings.
 
' Draw an arrow head at (x2, y2) for a vector from
' (x1, y1). Draw a tail at (x1, y1). Make the barbs
' anf fletchings point at a 45 degree angle away
' from the shaft.
Private Sub DrawArrow45(ByVal pic As Object, ByVal x1 As _
    Single, ByVal y1 As Single, ByVal x2 As Single, ByVal _
    y2 As Single, ByVal length As Single, Optional ByVal _
    draw_head As Boolean = True, Optional ByVal _
    num_fletchings As Integer = 0, Optional ByVal _
    fletching_gap As Single = 60)
Dim vx As Single
Dim vy As Single
Dim dist As Single
Dim ax As Single
Dim ay As Single
Dim barb_scale As Single
Dim i As Integer
Dim gap_dx As Single
Dim gap_dy As Single

    ' Draw the shaft.
    pic.Line (x1, y1)-(x2, y2)

    ' Find the arrow shaft unit vector.
    vx = x2 - x1
    vy = y2 - y1
    dist = Sqr(vx * vx + vy * vy)
    vx = vx / dist
    vy = vy / dist

    ' See if we need to draw multiple fletchings.
    If num_fletchings > 1 Then
        ' Get the fletching spacing vector.
        gap_dx = vx * fletching_gap
        gap_dy = vy * fletching_gap
    End If

    ' Draw the right barb.
    ax = -vy - vx
    ay = vx - vy

    ' Set the proper length.
    ax = ax * length
    ay = ay * length
    If draw_head Then pic.Line (x2, y2)-Step(ax, ay)
    For i = 0 To num_fletchings - 1
        pic.Line (x1 + i * gap_dx, y1 + i * _
            gap_dy)-Step(ax, ay)
    Next i

    ' Find the left barb.
    ax = (vy - vx) * length
    ay = (-vx - vy) * length
    If draw_head Then pic.Line (x2, y2)-Step(ax, ay)
    For i = 0 To num_fletchings - 1
        pic.Line (x1 + i * gap_dx, y1 + i * _
            gap_dy)-Step(ax, ay)
    Next i
End Sub
 
For more information on graphics including drawing routines (splines and other curves), graphing, fractals, three-dimensonal graphics, ray tracing, and lots more, see the book Visual Basic Graphics Programming.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated