#### Archived

This topic is now archived and is closed to further replies.

# Circle - Rectangular collision detection

This topic is 5852 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''m trying to develop another Arkanoid clone in openGL/VS. At the moment I''m using vectors to detect collision between the ball and paddle. vector3 v1(-(m_sprite.position().x - m_sprite.get_frame_width() / 2.0f), 0.0f, 0.0f); vector3 v2(0.0f, m_sprite.position().y + m_sprite.get_frame_height() / 2.0f, 0.0f); vector3 top_left = v2 - v1; It would be a lot more accurate to have an algorithm that detects only circle of a certain radius. "There can be no process-based definition of intelligence. It is a resemblance between two individuals, one real and other prototypical."

##### Share on other sites
quote:
Original post by mihuljica
I''m trying to develop another Arkanoid clone in openGL/VS. At the moment I''m using vectors to detect collision between the ball and paddle.

vector3 v1(-(m_sprite.position().x - m_sprite.get_frame_width() / 2.0f), 0.0f, 0.0f);
vector3 v2(0.0f, m_sprite.position().y + m_sprite.get_frame_height() / 2.0f, 0.0f);
vector3 top_left = v2 - v1;

It would be a lot more accurate to have an algorithm that detects only circle of a certain radius.

I guess I should make a question as well...

My question is where can I get a good source, tutorial or code for detecting a collision between the circular and rectangular object using vectors?

"There can be no process-based definition of intelligence. It is a resemblance between two individuals, one real and other prototypical."

##### Share on other sites
Hi Mihul,

regarding your questions, the best way to find out if a circle as collided with a rectangle is to find out if the circle is inside the 4 plans which make the rectangle.

All you need is to know the ray of the circle, the position of a point on that plan and the normal to that plan. Using the dot product you can find if it''s inside a plan or outside a plan.

Here''s the algorithm in pseudo-code:

FOR EACH PLAN.
- Find the vector between the Circle position Cp (center) and the point located on the plan Pp (Formula must be written this way (Distance_Vector = Pp - Cp).

- Make sure that the normal of the plan is normalize
- Calculate the Dot product between the plan Normal and the Distance Vector.

- if this value is inferior to (Negative Ray) the Circle is outside, otherwise the Circle is inside.

- If outside, no collision are taking place, if inside, check the next plan.

ONCE ARE THE PLAN ARE CHECK:

If the circle was inside every plan, than it''s definitively inside the Rectangle, otherwise it''s outside.

I think this should do the trick.

Nick

1. 1
Rutin
22
2. 2
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633308
• Total Posts
3011293
• ### Who's Online (See full list)

There are no registered users currently online

×