0

So i have two 3d line segments A and B the only givens are the origins of both line segments and their lenghts. I need to oriente the two line segments in a way that they end at the same position. EX:

point3d common_end_position;
bool result= intersect_line_segments(
{0, 0, 0},              // position_0
2.0,                    // length_0
{2, 0, 0},              // position_1
2.0,                    // length_1
{0, 0, 1},              // hint_direction
&common_end_position);  

The funciton should return true with the common end postion being {1, 0, 1.7321} If they cannont be oriented so that they end at the same endpoint then the function would return false

Astros257
  • 13
  • 6
  • 1
    Interpret your line segments as spheres (`position` is the center and `length` is the radius). Then calculate the intersection plane of those spheres. The resulting plane will be a circle. Every point that lies on the edge of that circle satisfies your requirements. – Timo Jan 05 '20 at 12:16
  • Do you have problems with programming or math? BTW: Please read [ask], since you're not actually asking a question. As a new user here, also take the [tour]. – Ulrich Eckhardt Jan 05 '20 at 12:39
  • Is provided `hint_direction` always normal to end-end line? – MBo Jan 05 '20 at 12:43
  • I have problems with the math around and and then translating it into code. The hint direction is used for when there are multiple solution then it should return the one furthest in the direction indicated by hint_direction – Astros257 Jan 05 '20 at 12:51
  • [Here](https://gamedev.stackexchange.com/questions/75756/sphere-sphere-intersection-and-circle-sphere-intersection) is a very good explanation of the maths. Translating that into code should be straight forward. If not, upate your question or create a new one. – Timo Jan 05 '20 at 13:19

1 Answers1

0

Let positions are C1 and C2, difference vector is D = C2-C1, distance is d = |D|, lengths are r and R.

Common end P does not exist if d > R + r or d < abs(R-r)

Otherwise projection of P onto C1C2 has length

x = (d^2 + R^2 - r^2) / (2d)

enter image description here

(mathworld page)

and distance of P from C1C2 is

 y = sqrt(R^2-x^2)

If it is guaranteed that hint vector H is perpendicular to D, then the rest is simple:

1) Get normalized vector ud = D / d
2) Find projection point P' = C1 + ud * x
3) Add perpendicular vector P = P' + H * y (assuming unit H vector)

If H might be not perpendicular (but not parallel to C1C2!) then find

H' = ud x (H x ud)

using two vector multiplications and use H' instead.

MBo
  • 77,366
  • 5
  • 53
  • 86
  • Hello this kinda has me confused. How would all this tell me what the common 3d endpoint is? also the HInt direction is just that a hint in the general direction of where the your ednpoint lies if there are more than one common endpoint to the line segment. – Astros257 Jan 06 '20 at 23:21
  • Look at the 2d picture at linked page. Your segment lengthes are equal to R and r and common endpoint lies at circles intersection (in your case spheres intersection, but math us the same). – MBo Jan 07 '20 at 13:34