I need to draw an arc in pygame, through three points, however pygame's arc function doesn't seem to support this. I have researched three point arcs, both in and out of pygame, however cannot find anything that I understand and is useful.
I would ideally like a full code however any hints will be useful
Here are some hints, which will require a little mathematics to finish. If you need more help, show more of your work and ask.
Let's say you want to draw a circular arc from point
a=(ax, ay) through point
b=(bx, by) to point
c=(cx, cy). You want to use the function
pygame.draw.arc(Surface, color, Rect, start_angle, stop_angle, width=1)
So you need to find
Rect, the bounding rectangle (which will be a square) of the circle, and the start and stop angles. Here is an outline.
u=(ux, uy). If that calculation raises a divide-by-zero or overflow error, the points are (nearly) in a straight line, so just draw a line segment from point
cand you are done.
c, it doesn't matter). That will be the radius of the desired circle.
uand the radius to calculate the parameters of the bounding rectangle
Rect. The rectangle will actually be a square, and point
uwill be its center.
a: this (almost) will be
start_angle. Be careful, since Cartesian coordinates have increasing y go up, while in pygame increasing y goes down. Also calculate the direction angle from point
c: this (almost) will be
stop_angle. Then calculate the direction angle from point
You now have
stop_angle. This outline ignores some subtle issues such as rounding to integers, but I'll leave those to you.