'Check if a point is on a 3d line?
I know how to check if a point is on a 2d line or not, but I'd like to do this in 3D. Any ideas?
// slope from point 1 to point 3
var p13:Number = (Math.atan2 (end.x - start.x, end.y - start.y)) * toDegrees;
// slope from point 1 to point 2 -- matches?
var p12:Number = (Math.atan2 (point.x - start.x, point.y - start.y)) * toDegrees;
return Math.round(p12) == Math.round(p13);
Solution 1:[1]
A point can never be 'on' a line in real coords. what you need to do is calculate the distance to the closest point to the line and decide if this is close enough for you.
Solution 2:[2]
The equation of a line is
v(t) = v0 + t*dir
Where v0 is some point on a line and dir is it's direction. Simply check if your point match this linear equation with enough accuracy
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Martin Beckett |
| Solution 2 | Andrew |
