基于点的线/平面相交

问题描述:

我在空间中有两个点L1和L2,它们定义了一条线上的两个点.

I have two points in space, L1 and L2 that defines two points on a line.

我在空间上有3个点P1,P2和P3,在平面上有3个点.

I have three points in space, P1, P2 and P3 that 3 points on a plane.

因此,有了这些输入,线在哪一点与平面相交?

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

Fx.平面方程A * x + B * y + C * z + D = 0为:

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

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

那剩下的呢?

解决这个问题的最简单(也是通用性很强)的方法就是说

The simplest (and very generalizable) way to solve this is to say that

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

它为您提供3个变量的3个方程式.求解x,y和z,然后代入任一原始方程式以得到答案.可以将其概括为做复杂的事情,例如找到4个维度中两个平面的交点.

which gives you 3 equations in 3 variables. Solve for x, y and z, and then substitute back into either of the original equations to get your answer. This can be generalized to do complex things like find the point that is the intersection of two planes in 4 dimensions.

对于另一种方法,(P2-P1)(P3-P1)的叉积N是与平面成直角的向量.这意味着可以将平面定义为点P的集合,以使PN的点积为P1N的点积.求解x使得(L1 + x*(L2 - L1)) dot N是此常数,可以在一个易于求解的变量中提供一个方程式.如果您要与此平面相交很多线,则此方法绝对值得.

For an alternate approach, the cross product N of (P2-P1) and (P3-P1) is a vector that is at right angles to the plane. This means that the plane can be defined as the set of points P such that the dot product of P and N is the dot product of P1 and N. Solving for x such that (L1 + x*(L2 - L1)) dot N is this constant gives you one equation in one variable that is easy to solve. If you're going to be intersecting a lot of lines with this plane, this approach is definitely worthwhile.

明确写出这样的意思:

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

请注意,仅 跨产品技巧可在3个维度上使用,并且仅适用于特定的飞机和直线问题.

Note that that cross product trick only works in 3 dimensions, and only for your specific problem of a plane and a line.