给定 2 点和从第一点到我必须找到的点的范围.如何找到我必须找到的点(在3D空间上)

Given 2 point and a range from first point to the point that I have to find. How to find the point I have to find (on 3D Space)

本文关键字:何找 空间 范围 3D 给定 一点      更新时间:2023-10-16

我不知道如何找到我所说的第三点。

但是,我尝试编写代码编写以下内容:

float extraX; // x of the third point
float extraY; // y of the third point
float extraZ; // z of the third point
void CalculateExtraPoint(float x1, float y1, float z1, float x2, float y2, float z2){
    float range = extraRange; //range from the first point to third point 
    float d_x = x1-x2; 
    float d_y = y1-y2;
    float d_z = z1-z2;
    distance1_2 = sqrt(pow(d_x,2)+pow(d_y,2)+pow(d_z,2));
    float temp = (range/distance1_2)+1;
    extraX = x2 + (temp*d_x);
    extraY = y2 + (temp*d_y);
    extraZ = z2 + (temp*d_z);
}

它来自向量方程 r=(x2,y2,z2( + (lambda([x1-x2,y1-y2,z1-z2]。 r 是任意点。

正确吗?提前谢谢。

是的,这是正确的。

稍微简单一点,更方便的变体。在这里,更清楚的是,我们从第一点开始考虑范围:

float temp = range/distance1_2;
extraX = x1 + (temp*d_x);
extraY = y1 + (temp*d_y);
extraZ = z1 + (temp*d_z);