这是问题的图像:

注意:我发现其他2个非常相似或相同的问题,但我无法解决这些问题: 找到两点之间点的坐标?
PS这不是家庭作业我需要这个编程问题,但我忘了我的数学......
假设A是位置向量,B是位置向量,maxLength是您允许的最大长度.
// Create a vector that describes going from A to B
var AtoB = (B - A);
// Make a vector going from A to B, but only one unit in length
var AtoBUnitLength = Vector2.Normalize(AtoB);
// Make a vector in the direction of B from A, of length maxLength
var AtoB1 = AtoBUnitLength * maxLength;
// B1 is the starting point (A) + the direction vector of the
// correct length we just created.
var B1 = A + AtoB1;
// One liner:
var B1 = A + Vector2.Normalize(B - A) * maxLength;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
636 次 |
| 最近记录: |