I am writing a 2D game in which there are fixed walls and a circle that can move. I determine that they collided using the previous position of the circle and the current one (in order to exclude such that the circle at high speeds can fly over the wall). Accordingly, I determine the moment of the collision (the position of the circle) in order to calculate its further movement. There are no problems with determining the collision from one side of the wall, but there is a problem with the angle of the wall. I can also determine the point of the corner from which the circle has crashed. Then there is the question of mathematics: How to determine the position (red in the figure) of the circle. Figure to make everything clear Yellow shows all the points that are known. From the center of the red circle to the corner point = R of the circle. The angle of the direction of movement of the circle in radians is also known.

  • you need to determine whether two straight lines intersect, one of the sides of the wall and one of the tangents to two circles - rjhdby
  • I do so, the point is not to determine whether the circle has collided or not. And to find where he collided - K. Sizov
  • The height from the corner of the wall to the direct connecting centers. The hypotenuse is equal to the radius of the circle. - rjhdby
  • In principle, the calculation of the collision can be redone to the central line. Height must be longer than R - rjhdby
  • @rjhdby so, well, now I will try to figure it out - K. Sizov

1 answer 1

x1, y1 - coordinates of the center of the first circle

x2, y2 - coordinates of the center of the second circle

R is the radius of the circle

A - the angle between the center of the line and the radius from the center of the required circle to the corner of the wall

xx, yy - coordinates of the wall angle

Direct connecting centers:

(y1-y2)X+(x2-x1)y+(x1y2-x2y1)=0 A*X+B*Y+C=0 

The distance from the corner of the wall to straight centers:

 D=|A*xx+B*yy+C|/sqrt(A*A+B*B) 

Collision was if D < R

 sin(A)=D/C 

PS Well, then the banal task of finding the coordinates of the vertices of a right triangle