我正在使用Point3D和Vector3D类,需要帮助通过给定的距离调整点。
- 点A - 坐标为0,0,0的点。
- 点B - 坐标为1,1,1的点。
- 向量AB - 向量AB告诉我点A和点B之间的距离是distance = 1.73205078。
代码:
Point3D A = new Point3D { X = 0, Y = 0, Z = 0 };
Point3D B = new Point3D { X = 1, Y = 1, Z = 1 };
Vector3D AtoB = A - B;
Double distanceBetweenAandB = AtoB.Length; // the distance will be 1.73205078 here.
我希望调整点B。我想将点A和点B之间的距离减小到0.5,而不是1(如图所示调整到位置C)。我正在努力想出如何做到这一点。
已知点A(0,0,0),已知点B(1,1,1),已知需要调整的距离(0.5)。如何计算?
伪代码:
Point3D A = new Point3D { X = 0, Y = 0, Z = 0 };
Point3D B = new Point3D { X = 1, Y = 1, Z = 1 };
Double distanceToAdjust = 0.5;
Point3D newCoordinate = B - distanceToAdjust; // this doesnt work!
下图中显示了调整后的点B:
我正在使用自己定义的Point3D类和Vector3D类。
[1 1 1]
的长度不是1,而是SQRT(3) = 1.732(...)
。 - J...