i follow this article -->>https://math.stackexchange.com/questions/2805113/line-touching-a-sphere
but is give me wrong answer even for sample case. what you would you like to add in this article so that we solve this problem perfeclty. the article is missing something regrading this problem .where i'm lacking in this problem. help ?
@lastchance and @keskiverto thanks i think i got that.
r2 = |C - P|2 - | (Qt - P).(C - P) / (Qt - P) |2
Please tell me if am right.
Also guide me on how can i code this to solve 2 degree equation in t.
Your last term of the equation has been bracketed dubiously, but is basically correct.
Write Q(t) as Q0 + t d
Then multiply your equation by |(Q(t) - P) |2 and do (a lot of) rearranging. I hope that you understand where this equation comes from.
You will get a quadratic in t. (Sometimes it degenerates to a linear equation if the leading coefficient is zero ... the case for the codechef example.)
Just solve that quadratic for the positive root (or the linear equation if it degenerates).
The picture I drew for this is https://imgur.com/F8sxzBP
You don't need sin(theta) - just the fact that the other two things are equal to it (and hence to each other).
A(x,y,z) at time (t)=0 where A moves in a straight line with constant velocity with direction vector D(dx,dy,dz) as a function of time(t) given by A(t)=A(0)+(D.t).I could not figure out what this mean?... I have calculated the Points of A at time t as ( x+(dx * t) , y+(dy * t) , z+(dz * t) ) but this gives me wrong answers . Can any one help me derieve the equation for points of A at time t. Thanks in advance.
@lastchance @keskiverto
Yes.@lastchance.
r2 = |C - P|2 - | (Qt - P).(C - P) / (Qt - P) |2
The equation comes from the picture that you attached in one of your replies.
Can you please tell the simplified version of a,b & c.(That you mentioned in one of your replies).
And @Wasp please tell something in this thread if you infer something further regarding this problem
@lastchance
Your last term of the equation has been bracketed dubiously, but is basically correct.
Write Q(t) as Q0 + t d
then what put at d , i think dx+dy+dz. am i correct ?
Yes you are right for "d".
But can someone simplify the expression of "t" in terms of "a","b" and "c".
That is solve the equation that @lastchance mentioned.
@wasp @lastchance
i think this should by correct d= sqrt( dx*dx+dy*dy+dz*dz ) ?
@lastchance
No.
In the context Q(t) = Q0 + t d
then d is a vector.
Wasp wrote:
I tried a lot but the expression becomes too long and eventually i miss some terms and the answer is lost
I'm deadly serious when I suggest (all of you) read https://www.mathsisfun.com/algebra/vectors.html
first. You will find it considerably easier to manipulate and simplify terms if you use vector notation well. Expanding out into coordinates too early is just wasting a lot of ink.
Can you just tell me about r^2?
r2 = |C - P|2 - | (Qt - P).(C - P) / (Qt - P) |2
Why do we have Q(t) - P in the numerator and denominator?
Shouldn't it cancel out well?
So, C-P=PC(vector)
Q(t) - P =PQ(t)(vector) where Q(t)=Q(0) + d(t)
So we need to write Q(t) in terms of "T" and then manipulate.
@lostchance
Please can you find the values of "a","b" and "c" so that we can put it in the determinant equation and find the roots?
Why do we have Q(t) - P in the numerator and denominator?
Shouldn't it cancel out well?
You STILL haven't read the reference about vectors, have you?. There is a dot product in the numerator and a magnitude in the denominator. So no, they won't cancel. Vectors don't behave like scalars.
The equation is slightly more accurately written
r2 = |C - P|2 - { (Q(t) - P).(C - P) }2 / |Q(t) - P |2
or
r2 = { mag(C - P) }2 - { dotProduct( Q(t) - P, C - P ) }2 / { mag( Q(t) - P ) }2
You need to multiply the whole lot through by |Q(t) - P |2 and write Q(t) = Q0+td. After multiplying out you will get a quadratic in t. Leave dot products as dot products as long as possible. (In fact, if you represent your vectors as 3-member structs in c++ code then you can conveniently write a function that will just do a dot product for you.)
the1marvellous wrote:
Please can you find the values of "a","b" and "c" so that we can put it in the determinant equation and find the roots?
If I simply did that then you would have put no effort at all into solving this problem.
You will find it considerably easier to manipulate and simplify terms if you use vector notation well. Expanding out into coordinates too early is just wasting a lot of ink.
Indeed. This can continue from the drawing board to the code:
1 2 3 4 5 6 7 8 9 10 11
class vec3d {
// code
};
int main() {
vec3d P = ...
vec3d c = ...
auto PC = c - P;
auto PCdist2 = dot(PC, PC); // |c - P|^2
...
}
ipg wrote:
i follow this article -->>https://math.stackexchange.com/questions/2805113/line-touching-a-sphere
but is give me wrong answer even for sample case. what you would you like to add in this article so that we solve this problem perfeclty. the article is missing something regrading this problem .where i'm lacking in this problem.
Yes, that has a critical difference:
I am having 2 points let us say P(x1,y1,z1) and Q(x2+t,y2+t,z2+t) , here I know the values of x1,y1,z1 and x2,y2,z2.
Note how the Q(t) is Q(0)+t, where the t is a vector. In your problem the t is a scalar and there is vector d.
The problems would be the same, if your d would be (1,1,1), because then vector t*d is (t,t,t). In other words, that linked problem is a special (simpler) case of your problem. You have to insert the d into the equation.
@lastchance.. Is t a vector? But it is time shouldn't it be scalar..also please help us in deriving expansion of Q(t) ..
Is this correct ( x+(dx * t) , y+(dy * t) , z+(dz * t) for Q(t) ?