# Thread: Collision Detection upon Slanted lines

1. ## Collision Detection upon Slanted lines

Ok here is my problem-o, collision detection agiansnt spheres is no problem or with horizontal or vertical lines, but i have yet to figure out how to work with collision detection upon slanted lines. If someone could throw me a bone i would be very appreciative.

2. ## Re: Collision Detection upon Slanted lines

I will have to work out the math part, but by using a triangulation you could find when the ball is within X units from the flipper.

Originally posted by DragonXTC:
Ok here is my problem-o, collision detection agiansnt spheres is no problem or with horizontal or vertical lines, but i have yet to figure out how to work with collision detection upon slanted lines. If someone could throw me a bone i would be very appreciative.

3. ## Re: Collision Detection upon Slanted lines

If the shortest distance between the
sphere center and the wall is less than
the radius of the sphere, they have
collided.

4. ## Re: Collision Detection upon Slanted lines

The problem come into play when your wall is at a 45 degree angle. In the case of his flipper it could be any angle from 0 to 45 degrees.(Flipper or paddle like in pinball)

Since we could have three points to work with, the flipper's bottom, top and the ball.
My thought is to use some triangle math to find when the ball was close. If the three points would always make a right triangle it woul be easy.

Originally posted by gumby:
If the shortest distance between the
sphere center and the wall is less than
the radius of the sphere, they have
collided.

5. ## Re: Collision Detection upon Slanted lines

Generic Pseudo code for test of Circle/Sphere touching Line/Plane (Note: Circle and Line are in 2D co-ordinates only)
Code :
```scalar R                               // Radius of Circle/Sphere.
vector C                               // Centre of Circle/Sphere.
vector P                               // Any point on Line/Plane.
vector N                               // Normal (vector perpendicular to Line/Plane with unit length).
boolean Touching = FALSE // Bool indicating if Circle/Sphere touching Line/Plane (assumed false).
if (-R <= (P - C).N <= R)       // If dot product less than radius (on either side of line)...
Touching = TRUE              // Circle/Sphere is touching Line/Plane.```

6. ## Re: Collision Detection upon Slanted lines

Generic Pseudo code for test of Circle/Sphere touching Line/Plane (Note: Circle and Line are in 2D co-ordinates only)

code:
--------------------------------------------------------------------------------

scalar R // Radius of Circle/Sphere.vector C // Centre of Circle/Sphere.vector P // Any point on Line/Plane.vector N // Normal (vector perpendicular to Line/Plane with unit length).boolean Touching = FALSE // Bool indicating if Circle/Sphere touching Line/Plane (assumed false).if (-R <= (P - C).N <= R) // If dot product less than radius (on either side of line)... Touching = TRUE // Circle/Sphere is touching Line/Plane.

A few questions, im not very good with vectors, but with this code, for vector C and P, how do you define two cooridinates into C and P, im guessing using the vectors array like properties? my question about vector

7. ## Re: Collision Detection upon Slanted lines

Wrong way around. Usually you define your coordinates as a vector then pass it to OpenGL. They're the same thing you use in your glVertex() and glTranslate() calls (more or less). How you arrange them (vertex array, structure, regular array) is up to you. However, when combining vectors they must be using the same coordinate system or your results will be incorrect. There's no easy way for me to explain it any better. Maybe someone else can say more. Otherwise it's up to you and google.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•