简体   繁体   English

使用距原点的距离作为第三个参数,确定由两个 3D 点定义的线上任意点的 x、y、z 坐标?

[英]Determine the x,y,z coordinates of any point on a line defined by two 3D points using distance from origin-point as the third parameter?

If we have two points in 3D space, does C# have any high-level libraries that would return the x,y,z coordinates of a point that is a specified distance along the line defined by the two points, using one of the points as origin?如果我们在 3D 空间中有两个点,那么 C# 是否有任何高级库可以返回一个点的 x、y、z 坐标,该点是沿由两个点定义的线的指定距离,使用其中一个点作为起源?

     extrapolatedPoint = FindPoint( origin3dPoint, second3dPoint, distanceFromOrigin)

PS The line defined by the points isn't a line-segment with the two points as endpoints, but a line that passes through the points. PS由点定义的线不是以两点为端点的线段,而是通过点的线。

Calculate unit direction vector (perhaps there are ready-to-use functions in C# math library - I see Vector.Normalize if it's suitable)计算单位方向向量(也许在 C# 数学库中有现成的函数——我看到Vector.Normalize如果合适的话)

dx = P2.x - P1.x
dy = P2.y - P1.y
dz = P2.z - P1.z
Len = sqrt(dx*dx+dy*dy+dz*dz)
dx /= Len 
dy /= Len 
dz /= Len 

Now you can define point at line with distance D from the first point (in direction of P2 !) as现在,您可以将点与第一个点的距离为D的线(在P2的方向上!)定义为

x  = P1.x + D * dx
y  = P1.y + D * dy
z  = P1.z + D * dz

Note that there are two points with distance D from the origin on the line, so I emphasized direction.请注意,线上有两个距离原点为D的点,所以我强调了方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM