Circle - Rectangular collision detection
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."
"There can be no process-based definition of intelligence. It is a resemblance between two individuals, one real and other prototypical."
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."
"There can be no process-based definition of intelligence. It is a resemblance between two individuals, one real and other prototypical."
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement