I am working on a C++ problem where I'm trying to make a utility function func() that takes as input two line segments starting points in 3d space [(x,y,z) and radius r]. If the segments can be oriented such that they end at the same point, the function should return true and print out that point. If there are multiple orientations that would produce a common endpoint, the function should choose the one that is furthest in the direction indicated by hint_direction.
The function receives these values:
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.
I am working on one of the first edge cases; where there is a single intersection point such as in the image below.
(image link = https://i.stack.imgur.com/dh9Vr.png)
My code correctly identifies this edge case, but I'm not sure how to programmatically find this intersection point.
//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 (?)
}
I have been following some guides online which lay out how to do this such as this: https://gamedev.stackexchange.com/questions/75756/sphere-sphere-intersection-and-circle-sphere-intersection Which says: "If r_1 + r_2 == d, then the intersection is a single point, located a distance of r_1 on the line from c_1 to c_2, or: c_i = c_1 + (c_2 - c_1) * r_1/d"
It's been a long time since I've done geometry like this, if I want to find the single point of intersection, how do I do that with the equation above "c_i = c_1 + (c_2 - c_1) * r_1/d" ? I understand that c_2 - c_1 is the distance between both centers which I have computed earlier in my program as float d, but I'm sure sure what's meant by "c_1 + " since c_1 refers to the whole set of cords (x,y,z).
Overall, I'm trying to find a way to get the single intersection point for example such as in my image, could somebody please help em understand the linked solution above? I am going to continue to research solutions in the meantime. Thank you.