I'm making a brainstorming program in VB.net and am struggling with drawing arrow lines. Currently I have lines that go all the way to the centre of a 'bubble' on the screen. This works very well but I want to implement lines with arrows to show flow.
I need the lines to stop just before it gets to the bounds of the bubble otherwise the arrow head will be drawn under the shape.
I've been trying for hours to get this to work. I've tried Pythagoras and sin cos tan but nothing seems to work well.
The current code I have isn't working:
Expand|Select|Wrap|Line Numbers
- If (lastPoint.X < firstPoint.X) Then
- If (lastPoint.Y < firstPoint.Y) Then
- '' bottom left
- Dim x As Double = Math.Atan((firstPoint.X - lastPoint.X) / (firstPoint.Y - lastPoint.Y))
- Dim s2 As Double = Math.Tan(x) * (endSize.Height / 2)
- Dim newX As Double = lastPoint.X + s2
- Dim newY As Double = lastPoint.Y
- alteredLastPoint = New Point(newX, newY)
- Else
- '' top left
- Dim x As Double = Math.Atan((firstPoint.X - lastPoint.X) / (firstPoint.Y - lastPoint.Y))
- Dim s2 As Double = Math.Tan(x) * (endSize.Height / 2)
- Dim newX As Double = lastPoint.X + s2
- Dim newY As Double = lastPoint.Y + endSize.Height
- alteredLastPoint = New Point(newX, newY)
- End If
- Else
- If (lastPoint.Y < firstPoint.Y) Then
- '' bottom right
- Dim x As Double = Math.Atan((firstPoint.X - lastPoint.X) / (firstPoint.Y - lastPoint.Y))
- Dim s2 As Double = Math.Tan(x) * (endSize.Height / 2)
- Dim newX As Double = lastPoint.X + s2
- Dim newY As Double = lastPoint.Y
- alteredLastPoint = New Point(newX, newY)
- Else
- '' top right
- Dim x As Double = Math.Atan((firstPoint.X - lastPoint.X) / (firstPoint.Y - lastPoint.Y))
- Dim s2 As Double = Math.Tan(x) * (endSize.Height / 2)
- Dim newX As Double = lastPoint.X + s2
- Dim newY As Double = lastPoint.Y + endSize.Height
- alteredLastPoint = New Point(newX, newY)
- End If
- End If
alteredLastPoint is the point for the where the arrow head will be drawn.
lastPoint is the centre point of the bubble where the arrow head is meant to point to
firstPoint is the centre point of the bubble where the arrow will come from
endSize is the size of the bubble where the arrow points to.
Thanks in advance,
Josh.