查找两个球之间的单个交点

问题描述 投票:0回答:1

[我正在研究一个C ++问题,我试图使一个实用函数func()以3d空间[[x,y,z)和radius r中的两个线段的起点作为输入。如果段的方向可以使它们在同一点结束,则函数应返回true并打印出该点。如果有多个方向会产生一个公共端点,则该函数应选择在hint_direction指示的方向上最远的方向。]

该函数接收这些值:

bool func(
point3d position_0,               // origin of first line segment.
float length_0,                   // length of first line segment.
point3d position_1,               // origin of second line segment.
float length_1,                   // length of second line segment.
vector3d hint_direction,          // in the event there are multiple solutions, return the one furthest in this direction.
point3d *out_common_end_position) // if result is true, point where both line segments can be oriented to end. otherwise uninitialized.

我正在处理第一个极端情况;下图所示为一个相交点。

(图像链接= https://i.stack.imgur.com/dh9Vr.png

我的代码正确地识别了这种边缘情况,但是我不确定如何以编程方式找到该相交点。

//calling function with example from image above, cords, radius, and hint
bool result = func({1, 1, 0}, 1.0, {3, 1, 0}, 1.0, {0, 0, 1}, &common_end_position);

bool func(point3d position_0, float length_0, point3d position_1, float length_1,vector3d hint_direction,point3d *out_common_end_position){

    //if statement detecting single intersection
    if(length_0 + length_1 == d){
        printf("intersection at a single point\n");
        //find single intersection point (?)
    }

我一直在网上关注一些指南,其中列出了如何执行此操作,例如:https://gamedev.stackexchange.com/questions/75756/sphere-sphere-intersection-and-circle-sphere-intersection表示:“如果r_1 + r_2 == d,则交点为单个点,位于从c_1到c_2的直线上r_1的距离,或者:c_i = c_1 +(c_2-c_1)* r_1 / d”] >

自完成这样的几何图形以来已有很长时间了,如果我想找到单个相交点,那么如何使用上面的方程“ c_i = c_1 +(c_2-c_1)* r_1 / d ?我知道c_2-c_1是我在程序中先前计算为float d的两个中心之间的距离,但是我确定“ c_1 +”是什么意思,因为c_1指的是整个电线(x,y ,z)。

[总体上,我正试图找到一种方法来获取单个交点,例如在我的图像中,有人可以帮助他们理解上面的链接解决方案吗?同时,我将继续研究解决方案。谢谢。

[我正在研究一个C ++问题,我试图使一个实用函数func()以3d空间[[x,y,z)和radius r中的两个线段的起点作为输入。如果段可以是...

c++ geometry computational-geometry intersection
1个回答
0
投票

我知道c_2-c_1是两个中心之间的距离

© www.soinside.com 2019 - 2024. All rights reserved.