简体   繁体   English

从一个点到三个维度(x,y,z)的增量移动

[英]move from one point to another in 3 dimensions (x,y,z) in increments

I have a question. 我有个问题。 For example i have two points in 3d space: 例如,我在3D空间中有两个点:

    float X1 = 100.44f, 
          X1 = 454.33f, 
          Z1 = 344.32f,

          X2 = 120.1f, 
          Y1 = 454.30f, 
          Z2 = 344.32f;

What i want to do is to move from point A (X1,Y1,Z1) to point B(X2,Y2,Z2) in increments Inc and also calculate heading. 我想做的是以增量Inc从点A(X1,Y1,Z1)移到点B(X2,Y2,Z2)并计算航向。

I was googling quite a bit to find a function that would do that or something similar. 我在谷歌上搜索了很多可以找到实现该功能的函数。

Thanks to anyone who will provide any help (and sorry for my bad English ... i hope its clear what i want to achieve). 感谢任何将提供帮助的人(对我的英语不好,深表歉意……我希望它清楚我想要实现的目标)。

Basically, you want to move along the vector from A to B using linear interpolation: 基本上,您想使用线性插值沿着矢量从A移到B:

// Compute vector from A to B by subtracting A from B
var dX = X2-X1;
var dY = Y2-Y1;
var dZ = Z2-Z1;

// Start at A and interpolate along this vector
var steps = 10;
for (var step = 0; step <= steps; step++) 
{
  var factor = step / steps; // runs from 0 to 1 inclusive
  var x = X1 + dX * factor;
  var y = Y1 + dY * factor;
  var z = Z1 + dZ * factor; 
  DoSomethingAt(x, y, z);
}

However, I highly suggest you take the advice in the comments and read up on vector math and interpolation to understand more about what you're trying to do. 但是,我强烈建议您在注释中采纳建议,并阅读矢量数学和内插法,以了解有关您要执行的操作的更多信息。

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

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