Point / line intersection

I have two points in space, L1 and L2, which define two points on the line.

I have three points in space, P1, P2 and P3, which are 3 points in the plane.

So, given these inputs, at what point does the line cross the plane?

Fx. plane equation A * x + B * y + C * z + D = 0:

A = p1.Y * (p2.Z - p3.Z) + p2.Y * (p3.Z - p1.Z) + p3.Y * (p1.Z - p2.Z)
B = p1.Z * (p2.X - p3.X) + p2.Z * (p3.X - p1.X) + p3.Z * (p1.X - p2.X)
C = p1.X * (p2.Y - p3.Y) + p2.X * (p3.Y - p1.Y) + p3.X * (p1.Y - p2.Y)
D = -(p1.X * (p2.Y * p3.Z - p3.Y * p2.Z) + p2.X * (p3.Y * p1.Z - p1.Y * p3.Z) + p3.X * (p1.Y * p2.Z - p2.Y * p1.Z))

But what about the rest?

+5
source share
2 answers

The easiest (and very generalized) way to solve this is to say that

L1 + x*(L2 - L1) = (P1 + y*(P2 - P1)) + (P1 + z*(P3 - P1))

which gives you 3 equations of 3 variables. Solve for x, y, and z, and then return to one of the original equations to get the answer. This can be generalized to accomplish complex things, such as finding a point that is the intersection of two planes in 4 dimensions.

N of (P2-P1) (P3-P1) - , ​​. , P , P N P1 N. x , (L1 + x*(L2 - L1)) dot N , , . , .

:

N = cross(P2-P1, P3 - P1)
Answer = L1 + (dot(N, P1 - L1) / dot(N, L2 - L1)) * (L2 - L1)

cross([x, y, z], [u, v, w]) = x*u + y*w + z*u - x*w - y*u - z*v
dot([x, y, z], [u, v, w]) = x*u + y*v + z*w

, .

+8

. , (XNA) , , .

var lv = L2-L1;
var ray = new Microsoft.Xna.Framework.Ray(L1,lv);
var plane = new Microsoft.Xna.Framework.Plane(P1, P2, P3);

var t = ray.Intersects(plane); //Distance along line from L1
///Result:
var x = L1.X + t * lv.X;
var y = L1.Y + t * lv.Y;
var z = L1.Z + t * lv.Z;

, , XNA.

+1

All Articles