View Full Version : Collision Detection upon Slanted lines

DragonXTC

05-02-2002, 10:36 AM

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.

nexusone

05-02-2002, 12:59 PM

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.

gumby

05-02-2002, 07:50 PM

If the shortest distance between the

sphere center and the wall is less than

the radius of the sphere, they have

collided.

nexusone

05-03-2002, 06:35 AM

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.

Furrage

05-03-2002, 06:38 AM

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

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.

DragonXTC

05-03-2002, 08:18 AM

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

Furrage

05-06-2002, 06:08 AM

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.

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.