Advertisement

Normal of circle intersection point

Started by May 12, 2012 07:48 PM
1 comment, last by dabo 12 years, 9 months ago
Hello,

I am creating a simple hockey game and I am trying to figure out how to handle puck collisions with the boards. It is pretty easy with the short and long sides since each one have only one normal but I have problems with the rounded corners, each will have lots of normals.I don't know how to calculate the normal of the intersection point between the puck and the corner. How does one usually go about doing this? I appreciate any help. I do 2d line intersection tests for the short and long sides and it works well, is it possible to do something similar between a line and a circle? And then from the intersection point calculate the normal in that point?

Thanks in advance.
Say the line segment is (x1,y1)-(x2,y2) then it can be represented parametrically as
x(t) = x1*t + (1-t)*x2
y(t) = y1*t + (1-t)*y2
each corner is the arc of a circle, let the corner circle we want to test be
(x - cx)^2 + (y - cy)^2 = r^2
where the circle has center (cx,cy) and radius r.
Plug x(t) and y(t) into the circle's equation and solve for t. Since it's quadratic you'll get two answers. Any solution where 0 <= t <= 1 is an intersection of the line segment and the circle. Use additional logic to determine if the intersection occurs in the arc of the circle that is the corner of the board.
x(t) and y(t) for a valid sloution is the point of intersection, call it (x0,y0). The normal of the circle you want then is (x0,y0)-(cx,cy) i.e. the puck should reflect relative to this line.
Advertisement
Thanks a lot!

This topic is closed to new replies.

Advertisement