Results 1 to 9 of 9

Thread: distance between a line and a point in 3d

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2001
    Posts
    7

    distance between a line and a point in 3d

    Does anybody know how to calculate the distance between a line and a point in 3d (not 2d) space? Please give a closed formula or code if possible. Thanks

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Aug 2000
    Location
    Cardiff University
    Posts
    653

    Re: distance between a line and a point in 3d

    Do you mean the shortest distance, i.e. the perpendular distance from the line?

    gav

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2001
    Posts
    7

    Re: distance between a line and a point in 3d

    Yes. I meant the shortest distance.

  4. #4
    Member Newbie
    Join Date
    Dec 2000
    Location
    Donetsk, Ukraine
    Posts
    48

    Re: distance between a line and a point in 3d

    If we have line in 3D space, which is defined by
    x=x1+l*t
    y=y1+m*t
    z=z1+n*t
    and point M0=(x0,y0,z0) then distance between them is given by a formulae:

    d = sqrt(det(A)^2 + det(B)^2 + det(C)^2)/sqrt(l^2+m^2+n^2)

    A,B and C are 2x2 matrices of following form:
    A=
    [ vy vz]
    [ m n]

    B=
    [ vz vx]
    [ n l]

    C=
    [ vx vy]
    [ l m]

    vx = x1-x0 vy = y1-y0 vz = z1-z0
    det(M) means determinant M where M is a square matrix. In our occasion if M is 2x2 matrix
    [a b]
    [c d]
    then det(M)=a*d-b*c. Hope, this will help



    [This message has been edited by Randolph (edited 03-22-2001).]

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    3,574

    Re: distance between a line and a point in 3d

    Is there, perhaps, a shorter formula? One requiring less computation?

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,502

    Re: distance between a line and a point in 3d

    Given any point q on the line, and the test point p, let P=p-q. Let l be a unit vector parallel to the line. Then d, the shortest distance from p to the line is:

    d=sqrt(PP-(lP)^2)



    [This message has been edited by DFrey (edited 03-22-2001).]

  7. #7
    Member Newbie
    Join Date
    Jul 2000
    Location
    Millis, MA USA
    Posts
    36

    Re: distance between a line and a point in 3d

    Originally posted by DFrey:
    Given any point q on the line, and the test point p, let P=p-q. Let l be a unit vector parallel to the line. Then d, the shortest distance from p to the line is:

    d=sqrt(PP-(lP)^2)

    [This message has been edited by DFrey (edited 03-22-2001).]
    Hmmm. Doesn't that assume the line passes through the origin?

  8. #8
    Member Newbie
    Join Date
    Jul 2000
    Location
    Millis, MA USA
    Posts
    36

    Re: distance between a line and a point in 3d

    Originally posted by EricK:
    Hmmm. Doesn't that assume the line passes through the origin?
    Oops. Let me answer my own question, NO.

  9. #9
    Member Newbie
    Join Date
    Dec 2000
    Location
    Donetsk, Ukraine
    Posts
    48

    Re: distance between a line and a point in 3d

    Of course, if you have UNIT vector, parallel to a line, you may simplify that formula! I gave formula with most common requirements. Normalizing vector also requires computation, although if you have to find distances from multiple points to one line this will give you huge boost of effectiveness.

Similar Threads

  1. Find a cartesian line from distance of 4 points
    By __bob__ in forum OpenGL: General
    Replies: 1
    Last Post: 03-10-2016, 04:06 AM
  2. algorithm on calculating point to line distance
    By amhood in forum OpenGL: General
    Replies: 2
    Last Post: 08-23-2004, 09:04 PM
  3. Distance Point To Line
    By Andrew Jameson in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 04-21-2003, 03:17 AM
  4. How can I set up the distance between the curve line (pixel) ?
    By randychou in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-08-2002, 03:54 AM
  5. How can I set up the distance between the curve line (pixel) ?
    By randychou in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 07-07-2002, 08:24 PM

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