Best way to find the Coordinates of a Point on a Line-Segment a specified Distance Away from another Point [closed]?

Up vote 0 down vote favorite share g+ share fb share tw.

Image of the problem at: In my code I have 4 points: Q, R ,S , T. I know the following Coordinates for R, T, and S; That segment RT However I need to get the coordinates for Q and I need it to be a relatively efficient calculation. I have several solutions for this problem but they are all so convoluted and long I know I must be doing something wrong.

I feel certain there must a simple elegant way to solve this. The best solution would be one that minimizes the number of more intensive calculations but that also isn't ridiculously long. Math optimization language-agnostic computational-geometry link|improve this question edited Sep 2 '11 at 7:07Bart Kiers42.6k74272 asked Sep 2 '11 at 6:45David1.

Ask on math.stackexchange.com/questions" rel="nofollow">math.stackexchange.com/questions – Manoj R Sep 2 '11 at 7:03 as Manoj said - this does not belong here - but If you choose to post this into math.stackexchange.com a short hint from my side: write what you allready did! If you want us to solve your homework you can tell us at least what you've tried so far. – Carsten König Sep 2 '11 at 7:13 Perhaps you should post your solution and ask if it can be shortened.

Your question is now of-topic on SO, IMO. – Bart Kiers Sep 2 '11 at 7:13 Are you sure your list of what is known is complete? I don't see how the coordinates of Q can be reduced below a range of possibilities with only those two facts.

– lashleigh Sep 2 '11 at 7:17 The list of what is known is missing a crucial fact from the title: d is also given. Since it is strictly between RT and RS, the solution is unique. – Christopher Creutzig Sep 2 '11 at 7:19.

Q is the intersecting point between a circle of radius d around R and the line TS, which leads to a quadratic equation with a number of parameters in the coefficients. I don't know if the following if “the best” solution (it may even be better to use a numerical solver in between), but it is completely worked out. Because I think it's more readable, I've changed your coordinate names to put T at (T1, T2), S at (S1, S2) and, to keep the formulas shorter, R at (0, 0) – just adjust S and T and the returned values accordingly.

Tmp1 = S1^2 - S2*T2 - S1*T1 + S2^2; tmp2 = sqrt(- S1^2*T2^2 + S1^2*d^2 + 2*S1*S2*T1*T2 - 2*S1*T1*d^2 - S2^2*T1^2 + S2^2*d^2 - 2*S2*T2*d^2 + T1^2*d^2 + T2^2*d^2); tmp3 = S1^2 - 2*S1*T1 + S2^2 - 2*S2*T2 + T1^1 + T2^2; t = (tmp1 + tmp2)/tmp3; if (0 > t || t > 1) { // pick the other solution instead t = (tmp1 - tmp2)/tmp3; } Q1 = S1+t*(T1-S1); Q2 = S2+t*(T2-S2); Obviously, I take no warranties that I made no typos etc. :-) EDIT: Alternatively, you could also get a good approximation by some iterative method (say, Newton) to find a zero of dist(S+t*(T-S), R)-d, as a function of t in 0,1. That would take nine seven multiplications and one division per Newton step, if I count correctly. Re-using the names from above, that would look something like this: t = 0.5; d2 = d^2; S1T1 = S1 - T1; S2T2 = S2 - T2; do { tS1T1 = S1 - t*S1T1; tS2T2 = S2 - t*S2T2; f = tS1T1*tS1T1 + tS2T2*tS2T2 - d2; fp = 2*(S1T1*tS1T1 + S2T2*tS2T2); t = t + f/fp; } while (f > eps); Set eps to control your required accuracy, but do not set it too low – computing f does involve a subtraction that will have serious cancellation problems near the solution.

Actually an approximation would be more then sufficient as long as it's within a reasonable % of error and if it's less computationally intense. – David Sep 2 '11 at 7:38.

Since there are two solutions Q on the (TS) line (with only one solution between T and S), any solution probably involves some choice of sign, or arccos(), etc. Therefore, a good solution is probably to put Q on the (TS) line like so (with vectors implied): (1) TQ(t) = t * TS (where O is some origin). Requiring that Q be at a distance d from R gives a 2nd degree equation in t, which is easy to solve (again, vectors are implied): d^2 = |RQ(t)|^2 = |RT + TQ(t)|^2 The coordinates of Q can then be obtained by putting a solution t0 into equation (1), via OQ(t0) = OT + TQ(t). The solution 0 Now, it may happen that the final formula has some simple interpretation in terms of trigonometric functions… Maybe you can tell us what value of t and what coordinates you find with this method and we can look for a simpler formula?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions