0

I am planning to make a program which will have some circular shapes moving inside of a oddly shaped Polygon.

I can't seem to figure out how to do the collision detection with the edges and have the shapes bounce back correctly.

I am sure this problem has been solved before, but I can't find a nice example.

My main problems are: Figuring out if the circle has hit the edge of its surrounding polygon. Once a hit occurs calculate the normal of the hit point to figure out the reflection vector.

Can anyone point me in the right direction?

Thanks, Jason

datenwolf
  • 159,371
  • 13
  • 185
  • 298
Jason
  • 4,034
  • 4
  • 40
  • 62

1 Answers1

1

You need to do a circle line intersection test.

To make it faster, you can first check the bounding boxes. For example, if the start and end point of the line are both to the left of the leftmost coordinate of the circle, there can't be an intersection.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • Great thanks, one more questions though. What is the formula to calculate the normal to reflect around? – Jason Mar 08 '11 at 11:27
  • Jason: See this answer: http://stackoverflow.com/questions/1243614/how-do-i-calculate-the-normal-vector-of-a-line-segment – Aaron Digulla Mar 08 '11 at 12:53