Results 1 to 7 of 7

Thread: Collision Detection upon Slanted lines

  1. #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.
    -=( DragonXTC )=-

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    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. #3
    Senior Member Regular Contributor
    Join Date
    Mar 2002
    Posts
    103

    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. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    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. #5
    Senior Member Regular Contributor
    Join Date
    Jan 2002
    Location
    Kingston, Jamaica, W.I.
    Posts
    282

    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. #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
    -=( DragonXTC )=-

  7. #7
    Senior Member Regular Contributor
    Join Date
    Jan 2002
    Location
    Kingston, Jamaica, W.I.
    Posts
    282

    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.

Similar Threads

  1. Collision Detection
    By DjStunt in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-25-2005, 10:59 AM
  2. Collision detection and Lines
    By Andrew Davey in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 04-24-2004, 01:14 PM
  3. Collision Detection
    By s_fonden in forum OpenGL: Advanced Coding
    Replies: 20
    Last Post: 05-23-2001, 05:24 PM
  4. collision detection contest: collision crazy
    By in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 09-19-2000, 02:33 AM
  5. Collision detection
    By CyBBe in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-18-2000, 10:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean