   collision detection (circles + rectangles)
  well first of all sorry if it has been asked before, but I couldn't find an answer which explained everything well enough for me, and I don't want to be a grave digger by bumping old topics.Well back to my topic, I'm trying to create a simulation game (well more of simulation than game atm, yet it's intended to be implemented into a game at some day :P). It's a ballance game at which you have to roll a ball, currently in 2d but once I'm finished with that I'll try to make it 3d. The physics are easy, being a physic student myself I know how to implement all things like distributed mass etc.However my main problem from now is at collision detection. I've been trying to read a lot about this but I couldn't find any good "answer". Well currently I use 2 "shapes": circles and rectangles. Collisions between circles is pretty straight forward,the problems is however with circle-rectangle and rectangle-rectangle collision:given a rectangle (at location X1,Y1 with size w*h, turned over D degrees - 0 being a horizontal placed rectange, 90 being a vertical placed rectangle) and a circle (at location X2,Y2 with radius r) what is the collision positiong? btw I know they're colliding at 1 point already..similarly how do I calculate the collision point from 2 given rectangles?thanks in advance,paul23   
  Rectangle-rectangle collision is only possible when they are axis-aligned, i thinkFor rotated rectangles you will probably have to do edge and line collision   ;Quote:Original post by GPxzRectangle-rectangle collision is only possible when they are axis-aligned, i thinkFor rotated rectangles you will probably have to do edge and line collisionNot quite sure what you mean by this, but a) you can easily perform intersection tests between oriented rectangles, and b) performing multiple edge-edge intersection tests is usually not the best way to do it.@The OP: The static intersection test between a circle/sphere and an oriented box usually proceeds as follows:1. Find the point on the box closest to the circle/sphere center2. If the distance between the two points is greater than the circle/sphere radius, no intersection, else...3. Compute the MTV (minimum translational vector) from the radius and the pair of closest points   ;Quote:Original post by jykQuote:Original post by GPxzRectangle-rectangle collision is only possible when they are axis-aligned, i thinkFor rotated rectangles you will probably have to do edge and line collisionNot quite sure what you mean by this, but a) you can easily perform intersection tests between oriented rectangles, and b) performing multiple edge-edge intersection tests is usually not the best way to do it.well teh what are those "easily intersection tests" for oriented rectangles? (I think this is my biggest problem, I've shred like 50 pages trying to find a working algorithm..Quote:@The OP: The static intersection test between a circle/sphere and an oriented box usually proceeds as follows:1. Find the point on the box closest to the circle/sphere center2. If the distance between the two points is greater than the circle/sphere radius, no intersection, else...3. Compute the MTV (minimum translational vector) from the radius and the pair of closest pointsthansk for the reply.. and well I was guessing something like this had to be done already :).. Though how do you get the closest point to the circle from a rectangle? - I'm thinking about describing all 4 "edges" as lines like: y=4x+8 y=1/4x+15 y=4x+12 y=1/4x+10 and then I would be able to get the shortest point pretty easily. However this translation requires pretty much work and on top of that it doesn't work for "vertical" lines.  Is there maybe a better method?;  Most intersection tests are not easy at all, and new algorithms are still being investigated to enhance and optimize them. You would do better looking for a collision detection library which someone have been developing for years. If you still want to understand many (but not all) of the collision algorithms and optimization structures, I would recommend the book "Real-Time Collision Detection". This tables shows some sources where you can find other tests:http://www.realtimerendering.com/int/   