Robin Rodricks
Robin Rodricks

Reputation: 113946

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);

Upvotes: 5

Views: 12208

Answers (3)

Andrew
Andrew

Reputation: 24846

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

Upvotes: 0

Lee Louviere
Lee Louviere

Reputation: 5262

Normalize the vectors. Check if the normals match.

Find the greatest value, divide all of the other values by that value so you get a vector normal.

Any point on a line should have the same vector normal.

Upvotes: 6

Martin Beckett
Martin Beckett

Reputation: 96119

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.

Upvotes: 3

Related Questions