Notices
Results 1 to 6 of 6

Thread: What is a proper way to detect if a line in 3D space, has collided with another object?

  1. #1 What is a proper way to detect if a line in 3D space, has collided with another object? 
    Forum Ph.D.
    Join Date
    Jan 2013
    Posts
    922
    First off, my collision algorithm will use bounding box for my collision, and a line(vector).
    I have been thinking all day about this for several days, and yet, i can't think of a way to do this.

    I understand, and have done collision detection between a point, a bounding box.

    I now have a problem with vector's collision detection.

    Kindly note:
    1. I have Camera position.
    2. I have the LookAt vector (this is a unit vector).
    3. The minx,maxx,miny,maxy,minz,maxz of the bounding box.
    4. The line in 3D space i am talking about is the line of the lookAt, passing through the camera position.
    5. No collision must be detected for anything facing behind the camera.
    You could assume that the line goes on to infinite, but if that is not possible, i would set a high magnitude for the line.

    Google didn't come out with what I need.

    Anyone care to contribute any suggestions of the methods that could be used?
    Small/Big suggestions will help a lot.
    Help is greatly appreciated!


    Quote Originally Posted by jocular View Post
    If thy right nipple offend thee, pluck it off! Goes for the other, too!
    Reply With Quote  
     

  2.  
     

  3. #2  
    Forum Radioactive Isotope MagiMaster's Avatar
    Join Date
    Jul 2006
    Posts
    3,440
    Such bounding boxes are called axis aligned bounding boxes, often abbreviated AABB. Searching for 3D AABB line collision gives better results: Ray-Box Intersection Ľ www.scratchapixel.com.


    Reply With Quote  
     

  4. #3  
    Forum Ph.D.
    Join Date
    Jan 2013
    Posts
    922
    I've written a pseudo code on how to do it, but i have a problem with the last part on collision detection with a plane.
    This is my pseudo code:
    In order find if there is an intersection between the ray and the 3D AABB:

    The bounding box must have 6 faces and must be a cuboid:
    1) The face with the min on x
    2) The face with the max on x
    3) The face with the min on y
    4) The face with the max on y
    5) The face with the min on z
    6) The face with the max on z


    3D AABB object collision function:
    a) Test if the origin is in the box.
    if min x is smaller than max x,
    and min y is smaller than max y,
    and min z is smaller than max z,
    then the origin is in the box.
    b) For each of the AABB faces, test if the ray may intersect with it:
    c) Split each face (W) up into its UV coordinate system.
    d) Pass in the value of the W face, and it's max and minimum U and V into the plane collision function to test for ray collision for each of these faces.
    e) If the ray intercepts any single face of the AABB, there is collision with the AABB.
    return true,else false.


    AABB face collision function
    a) For the U coordinate,
    use V = U/V*W + CameraEye to get the V intercept of the AAplane.
    b) For the V coordinate,
    use U = V/U*W + CameraEye to get the U intercept of the AAplane.
    c) If the V intercept is between min V and max V,
    and the U intecept is between min U and max U,
    then the ray intercepts the plane,
    return true,else false
    the problem i have is with the UV cartesian plane.
    i don't exactly get what i need to calculate the intercept on that axis aligned plane.

    anyway, i'm using the forumla y=mx+c to get the point where the ray intercepts the plane.
    i don't know what is x in y=mx+c is supposed to mean, and how should i use it in the UV coordinates?

    p.s. the pseudo code for the face collision function is messy, as it's nowhere near completion.
    Quote Originally Posted by jocular View Post
    If thy right nipple offend thee, pluck it off! Goes for the other, too!
    Reply With Quote  
     

  5. #4  
    Forum Radioactive Isotope MagiMaster's Avatar
    Join Date
    Jul 2006
    Posts
    3,440
    You need to apply y = m x + b to each coordinate, in which case the y and x variables are badly named, so rename them. You can instead say , and . You have a point at t = 0 (the starting point of your line) and depending on how your ray is defined you'll either have another point which you can set as t = 1, or you'll have the information to calculate the slopes. Either way, you then solve for t when you hit the plane in the one easy coordinate, and then plug that t into the other two coordinates to see where on the plane it hit.

    Renaming the coordinates of your box faces is probably not worth doing as your going to have to rename the coordinates of your ray as well, which is going to get confusing unless you're really careful.

    Also, your "test if origin is in box" code doesn't make sense as written. min x is always less than max x.
    Reply With Quote  
     

  6. #5  
    Forum Ph.D.
    Join Date
    Jan 2013
    Posts
    922
    can i make the camera the origin, by getting all the new AABB vertices values by adding the old AABB vertices values with the camera position? so that the c (the cartesian origin is now the camera) in y=mx+c is zero?

    or did i get the formula confused?



    i wonder how to calculate c of the ray, as my camera is not at the origin. its tedious to do, so i was wondering if i could make my camera the origin.
    Quote Originally Posted by jocular View Post
    If thy right nipple offend thee, pluck it off! Goes for the other, too!
    Reply With Quote  
     

  7. #6  
    Forum Radioactive Isotope MagiMaster's Avatar
    Join Date
    Jul 2006
    Posts
    3,440
    You can if you want. I doubt it'll really be all that useful in the end though.
    Reply With Quote  
     

Similar Threads

  1. Can an object be at rest in space??
    By Ayushman in forum General Discussion
    Replies: 21
    Last Post: October 24th, 2013, 12:18 PM
  2. Motion of an object in infinite space
    By thinkatron in forum General Discussion
    Replies: 4
    Last Post: February 26th, 2013, 04:50 AM
  3. Replies: 4
    Last Post: May 8th, 2012, 03:15 AM
  4. Releasing the object from Space Elevator
    By Eagle9 in forum Astronomy & Cosmology
    Replies: 5
    Last Post: July 6th, 2011, 01:45 PM
  5. Replies: 3
    Last Post: March 29th, 2010, 02:16 PM
Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •