3D垂直点上线从三维点 [英] 3D Perpendicular Point on Line From 3D point

查看:221
本文介绍了3D垂直点上线从三维点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题已经在参考2D问过。这个问题延伸到3D。如何找到从三维空间中的点线垂直相交点?如果我的线由(X1,Y1,Z1)&放定义; (X2,Y2,Z2)和我还有点(X3,Y3,Z3)的空间。

This question has been asked before in reference to 2D. This question extends it to 3D. How do I find the perpendicular intersected point on a line from a point in 3D space?. If my line is defined by points (x1,y1,z1) & (x2,y2,z2) and I have a point (x3,y3,z3) in space.

如何找到点的垂直相交(X4,Y4,Z4)从行(X3,Y3,Z3)?

How do I find the perpendicular intersection of point (x4,y4,z4) on the line from (x3,y3,z3)?

推荐答案

对于初学者来说,pretty的多少需要一些实施 Vector3类型类,无论你写的你自己,找到一个独立的实现在互联网上的某个地方,或使用包含一个像 XNA <库/ A>或 Sharp3D.Math

For starters, you pretty much need some implementation of a Vector3 class, whether you write your own, find a standalone implementation on the internet somewhere, or use a library that contains one like XNA or Sharp3D.Math.

通常在三维空间线不重新两点psented $ P $,而是由参数方程和载体,而不是标量操作的。您的参数方程将是以下形式:

Typically lines in 3d space are not represented by two points, but by parametric equations and operated on by vectors and not scalars. Your parametric equation would be of the form:

x = x1 + t(x2-x1), y = y1 + t(y2-y1), z = z1 + t(z2-z1)

向量 U T 的系数来定义的。 &LT; X2-X1,Y2,Y1,Z2-Z1&GT;

The vector u is defined by the coefficients of t. <x2-x1, y2-y1, z2-z1>.

向量 PQ 是由您选择的点定义的问:减去一个点的 P 就行了。线路上的任何点都可以选择,所以这将是最简单的只使用线 T = 0 ,它简化为X1,Y1,Z1和。 &LT; X3,X1,Y3-Y1,Z3-Z1&GT;

The vector PQ is defined by your chosen point Q minus a point P on the line. Any point on the line can be chosen, so it would be simplest to just use the line t = 0, which simplifies to x1, y1, and z1. <x3-x1, y3-y1, z3-z1>

的点和在3-空间中的线之间的最短距离的定义如下:

The definition of the shortest distance between a point and a line in 3-space is as follows:

D = || PQ X U || / || U ||

D = ||PQ x u|| / ||u||

其中, X 是跨产品运算符, || ... || 获取所含的向量的大小。根据您选择哪个库,你的code可能会有所不同,但它应该是非常相似的:

Where x is the cross product operator, and || ... || gets the magnitude of the contained vector. Depending on which library you choose, your code may vary, but it should be very similar:

Vector3 u = new Vector3(x2 - x1, y2 - y1, z2 - z1);
Vector3 pq = new Vector3(x3 - x1, y3 - y1, z3 - z1);

float distance = Vector3.Cross(pq, u).Length / u.Length;

修改:我只是意识到你想交集的实际点,而不是距离。找点实际的公式是有点不同。你需要使用内积空间来获得 U 垂直于 PQ 的组件。要做到这一点,你需要找到的成分 U 的方向发展 PQ

Edit: I just realized you wanted the actual point of intersection, and not the distance. The formula to find the actual point is a bit different. You need to use inner product space to get the component of u perpendicular to PQ. To do that, you need to find the component of u in the direction of PQ:

(( PQ U )/ || U || ^ 2)* U

((PQ · u) / ||u||^2) * u

这会让我们在 W1 成分,但我们希望 W2 ,这是Q和线之间的组件:

This gets us the w1 component, but we want w2, which is the component between Q and the line:

PQ = W1 + W2

W2 = PQ - W1

从那里,我们采取的 W2 并把它添加到该点问:以获得上线最近的问:点。在code这将是:

From there, we take w2 and add it to the point Q to get the point on the line nearest Q. In code this would be:

Vector3 p1 = new Vector3(x1, y1, z1);
Vector3 p2 = new Vector3(x2, y2, z2);
Vector3 q = new Vector3(x3, y3, z3);

Vector3 u = p2 - p1;
Vector3 pq = q - p1;
Vector3 w2 = pq - Vector3.Multiply(u, Vector3.Dot(pq, u) / u.LengthSquared);

Vector3 point = q - w2;

其中, point.X X4 point.Y Y4 point.Z Z4

这篇关于3D垂直点上线从三维点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆