gpt4 book ai didi

c# - 找到两点之间的限制点

转载 作者:太空狗 更新时间:2023-10-30 00:56:23 24 4
gpt4 key购买 nike

  • 我有 A 点和另一点(如 B、C 或 D)的坐标。
  • 我还有 A 点和另一点之间的距离。
  • 我知道 A 点和另一点之间的最大允许距离(用紫色线和假想的圆圈表示)。
  • 问题:如何找到红点(B1 或 C1 或 D1)的坐标。
  • 示例:A=(-1,1), E=(3,-8),最大允许距离 = 4。E1 点的坐标是多少?

这是问题的图片: problem

注意:我发现了另外 2 个非常相似或相同的问题,但我无法解决这些问题: Finding coordinates of a point between two points?

How can I find a point placed between 2 points forming a segment using only the partial length of the segment?

附言这不是家庭作业,我需要这个来解决编程问题,但我忘记了我的数学...

最佳答案

假设 A 是位置向量,B 是位置向量,maxLength 是您允许的最大长度。

ABVector2的(正如您标记此问题的 )。

// 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;

关于c# - 找到两点之间的限制点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7860428/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com