## Drawing arrowheads which follow the direction of the line in PyGame

python quiver example
how to make a character move in python
pygame move object with arrow keys
matplotlib quiver 3d
matplotlib quiver arrow size
python movement code
how to make an object move in python
pygame move sprite with arrow keys

In Pygame, how can I calculate the coordinates for the three points of the head of an arrow, given a start point and an end point for the arrow, so that the arrowhead points in the same direction as the line?

```def __draw_arrow(self, screen, colour, start, end):
start = self.__coordinate_lookup[start]
end = self.__coordinate_lookup[end]
dX = start - end
dY = -(start - end)
print m.degrees(m.atan(dX/dY)) + 360
pygame.draw.line(screen,colour,start,end,2)
```

I've tried playing around with angles and with the gradient of the line, the fact the Y coordinates increase downwards instead of upwards is throwing me off and I would really appreciate a nudge in the right direction.

This should work:

```def draw_arrow(screen, colour, start, end):
pygame.draw.line(screen,colour,start,end,2)
rotation = math.degrees(math.atan2(start-end, end-start))+90
```

Sorry for the poorly organized code. But as you said, the coordinates starting in the top-left do require some math to be flipped. Also, if you want to change the triangle from being equalatiral to something else you just have to change the `rotation +/- 120` in line 4, or the `20*` for a different radius.

Hope this helps :)

Python turtle arrowheads not facing in correct direction, Drawing The arrow line brush.penup() brush.goto(StartPointX, StartPointY) brush.pendown() brush.setheading(brush.towards(MaxX, MaxY))� In Pygame, how can I calculate the coordinates for the three points of the head of an arrow, given a start point and an end point for the arrow, so that the arrowhead points in the same direction a

I denote start and end coordinates as `startX, startY, endX, endY` ```dX = endX - startX
dY = endY - startY

//vector length
Len = Sqrt(dX* dX + dY * dY)  //use Hypot if available

//normalized direction vector components
udX = dX / Len
udY = dY / Len

//perpendicular vector
perpX = -udY
perpY = udX

//with length L and half-width H
arrowend  = (end)

leftX = endX - L * udX + H * perpX
leftY = endY - L * udY + H * perpY

rightX = endX - L * udX - H * perpX
rightY = endY - L * udY - H * perpY
```

Using Pygame to move your gaming player around, In this article, we'll use Pygame to add keyboard controls so you can direct window for output as you press the right, left, and up arrows, or the A, D, The first two lines are for context (you already have them in your code, if you've been following along), so add only the last three: player_list.draw(world) Drawing lines in pygame . The last shape to cover is a line (a line technically isn’t a shape… but we still need to know how to draw one!). There are four line drawing functions we can use however I’m just going to cover the most basic one in this tutorial.

Vladimir's answer is great! For anyone visiting in the future, here's the function with control over every aspect of the arrow:

```def arrow(screen, lcolor, tricolor, start, end, trirad):
pg.draw.line(screen,lcolor,start,end,2)
rotation = math.degrees(math.atan2(start-end, end-start))+90