球-球相交,选择正确的 theta
Sphere-Sphere Intersection, choosing right theta
我正在研究一个 C++ 问题,我正在尝试制作一个实用函数,该函数将 3d 中的两条线段起点作为输入 space [(x,y,z) 和半径 r] .如果线段的方向可以使它们在同一点结束,则该函数应该 return 为真并打印出该点。如果有多个方向会产生一个公共端点,则该函数应选择在 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://gamedev.stackexchange.com/questions/75756/sphere-sphere-intersection-and-circle-sphere-intersection。
我能够成功获得所有的交点,但是我不知道如何获得在提示方向上最远的点。
我想我也许可以使用圆和 hint_direction 之间的交点并得到该点的角度,但我不知道该怎么做。
正如 Spektre 正确指出的那样,我错过了你问题的 3D 部分,因此 4 个选项如下:
- 没有相交(或一个球体完全位于另一个球体中)
- 一个点(球体从内部或外部接触)
- 形成圆形的正常交叉点
- 两个球体完全重叠,即它们具有相同的原点和相同的半径
由于法线交点会形成一个圆,因此您需要将方向提示投影到该圆上,并计算圆与投影矢量之间的交点以获得最远的交点。
我正在研究一个 C++ 问题,我正在尝试制作一个实用函数,该函数将 3d 中的两条线段起点作为输入 space [(x,y,z) 和半径 r] .如果线段的方向可以使它们在同一点结束,则该函数应该 return 为真并打印出该点。如果有多个方向会产生一个公共端点,则该函数应选择在 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://gamedev.stackexchange.com/questions/75756/sphere-sphere-intersection-and-circle-sphere-intersection。
我能够成功获得所有的交点,但是我不知道如何获得在提示方向上最远的点。
我想我也许可以使用圆和 hint_direction 之间的交点并得到该点的角度,但我不知道该怎么做。
正如 Spektre 正确指出的那样,我错过了你问题的 3D 部分,因此 4 个选项如下:
- 没有相交(或一个球体完全位于另一个球体中)
- 一个点(球体从内部或外部接触)
- 形成圆形的正常交叉点
- 两个球体完全重叠,即它们具有相同的原点和相同的半径
由于法线交点会形成一个圆,因此您需要将方向提示投影到该圆上,并计算圆与投影矢量之间的交点以获得最远的交点。