• Create Account

## Pixel-based collision detection with sphere

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1Hairie  Members

109
Like
0Likes
Like

Posted 28 September 2012 - 07:07 AM

Hello,

I am currently making a pixel based 2D table tennis game where I need to to find the exact point the ball hits the table.
For simplicity reasons I have't programmed the spin of the ball yet.
Can anyone help me with formulas or something else helpful?

Thanks!

### #2m_a_s_gp  Members

107
Like
0Likes
Like

Posted 28 September 2012 - 10:33 AM

You can get the contact point using this formula:

Pc = C - n[(C-P)dot(n)]

Pc: contact point
C: ball's center
n: the unit vector normal to the table and pointing upward
P: any point on the surface of the table

The quantity [(C-P)dot(n)] is the closest distance from the ball's center to the table. If this distance is greater than the ball's radius, there is no collision..

Edited by m_a_s_gp, 28 September 2012 - 10:34 AM.

### #3Inferiarum  Members

739
Like
0Likes
Like

Posted 28 September 2012 - 01:47 PM

If you want an analytic solution, neglecting friction:

y(x) = y0 + vy*(x-x0)/vx - 0.5 * g * [(x-x0)/vx]^2

vx,vy : initial speed in x and y directions
y0,x0 : initial position
g : acceleration due to gravity

impact is when y(x) = h + r
where h is the height of the table and r the radius of the ball

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.