Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a point's position from an angle and the length of the line

I'm programming a game in Python, with pygame, and I'd like to make a function that draws a line in a specific direction from a point, with a specific length, for example, the definition of the funcion would be: def draw_line(position1: (int, int), angle: int, line_length: int, line_width: float, color: Color):

What can I do for calculating the second point to draw the line?

I have a little schematic of the problem, I want to get position2, to draw the line with pygame.

enter image description here

like image 414
Arnyminer Z Avatar asked Jan 23 '26 09:01

Arnyminer Z


1 Answers

This is a math problem, but ok, the x and y coordinate of point 2 are:

(x2,y2) = (x1 + line_length*cos(angle),y1 + line_length*sin(angle))
like image 71
ViG Avatar answered Jan 26 '26 00:01

ViG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!