I would like to know if there are any routines that, given

a line (x1,y1)-(x2,y2), will automatically draw an arrow-

head on it pointing in the right direction.

a line (x1,y1)-(x2,y2), will automatically draw an arrow-

head on it pointing in the right direction.

Private Function Arrow(x1 As Long, y1 As Long, x2 As Long, y2 As Long, Direction As Long) As Long

Dim xdiff As Long

xdiff = x2 - x1

xdiff = xdiff / 5

Form1.Line (x1, y1)-(x2, y2)

If Direction = 1 Then

x1 = x2 - xdiff

y1 = y2 - xdiff

Form1.Line (x2, y2)-(x1, y1)

y1 = y1 + (xdiff * 2)

Form1.Line (x2, y2)-(x1, y1)

Else

x2 = x1 + xdiff

y2 = y1 - xdiff

Form1.Line (x1, y1)-(x2, y2)

y2 = y2 + (xdiff * 2)

Form1.Line (x1, y1)-(x2, y2)

End If

End Function

Just pass it the four endpoints of the line, and the direction you want the arrow to point. 1 is right and 2 is left. It could be expanded to also include up and down, and probably diagonals also.

Private Type LineType

xStart As Integer

yStart As Integer

xEnd As Integer

yEnd As Integer

End Type

as the argument.

Private Sub DrawLineWithArrow(MyLine As LineType)

Dim xTemp As Single

Dim yTemp As Single

' Rotation coefficients

Dim sCos As Single

Dim sSin As Single

Dim xDiff As Integer

Dim yDiff As Integer

' Arrow coordinates

Dim xTip As Single

Dim yTip As Single

Dim xCorner1 As Single

Dim yCorner1 As Single

Dim xCorner2 As Single

Dim yCorner2 As Single

' Arrow dimensions. Set them to comply with your scale.

Const xOffset = 5 'Lenght

Const yOffset = 2 'Width

With MyLine

' Calculate rotation coefficients

xDiff = .xEnd - .xStart

yDiff = .yEnd - .yStart

sCos = xDiff / Sqr(xDiff * xDiff + yDiff * yDiff)

sSin = Sqr(1 - sCos * sCos)

If yDiff < 0 Then

sSin = -Abs(sSin)

End If

If xDiff < 0 Then

sCos = -Abs(sCos)

End If

' Calculate arrow coordinates assuming horizontally

' positioned arrow at the line end point

xTip = .xEnd

yTip = .yEnd

' Translate origo to the the arrow tip

xCorner1 = -xOffset '.xEnd - xOffset - xTip etc

yCorner1 = yOffset

xCorner2 = -xOffset

yCorner2 = -yOffset

' Rotate and translate points

xTemp = xCorner1 * sCos - yCorner1 * sSin

yTemp = xCorner1 * sSin + yCorner1 * sCos

xCorner1 = xTemp + xTip ' translate to original coordinates

yCorner1 = yTemp + yTip

xTemp = xCorner2 * sCos - yCorner2 * sSin

yTemp = xCorner2 * sSin + yCorner2 * sCos

xCorner2 = xTemp + xTip ' translate to original coordinates

yCorner2 = yTemp + yTip

'Draw line

Picture1.Line (.xStart, .yStart)-(.xEnd, .yEnd)

' Draw arrow

Picture1.Line (xTip, yTip)-(xCorner1, yCorner1)

Picture1.Line (xTip, yTip)-(xCorner2, yCorner2)

End With

End Sub

This one is on us!

(Get your first solution completely free - no credit card required)

UNLOCK SOLUTION
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy

Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif

Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster

CTP, Sr Infrastructure Consultant

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Connect with Certified Experts to gain insight and support on specific technology challenges including:

- Troubleshooting
- Research
- Professional Opinions

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.