Skip to main content
GameDev.net gamedev.net
🔒 Locked

Point on line?

Started by RegularKid May 24, 2002 at 6:50 PM 3 replies 400+ views
Original Post
RegularKid
RegularKid
Anyone know how to check if a 3D point and a 3D line intersect (that is, the point is ON THE LINE)? Thanks.
Fruny
Fruny
Substitute the coordinates of the point in the line equations (e.g. parametric (x,y,z)=(x0,y0,z0)+t.(dx,dt,dz)) and look if it is a valid solution.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
RegularKid
RegularKid
Ok, so I just put x0, y0, z0 as the point and t.(dx, dy, dz) as the vector from point A to point B (the line segment vector)? If I do that, then what consists of a valid solution? Could you explain a little more. That would be great! Thanks.
Fruny
Fruny
Your line is a point (x0,y0,z0) and a vector (dx,dy,dz).
The point you''re testing is (x,y,z)
Find if there is a value t for which the equation is true.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Ronin_54
Ronin_54
Hehe... Other solution:

Line is a point and a vector (lx, ly, lz for the point, lu, lv, lw for the vector). The vector should be lenght 1.

The point is simply a point (px, py, pz)

First, get the shortest distance from the line-point to the point-point:
distance = |(lx - px, ly - py, lz - pz)|.

Now the cool part: if the point is on the line, one of these two is true:
(lx, ly, lz) + (distance * (lu, lv, lw)) == (px, py, pz)
or
(lx, lym lz) + (-distance * (lu, lv, lw)) == (px, py, pz)


The point of this? Well, it ain't recursive! ^_^

[edited by - Ronin_54 on May 25, 2002 2:51:58 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.