@lastchance
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. |
I tried to implement this on paper first. But, still am getting wrong ans. Please guide me
So, I used the property of dot product of two vector a.b as (ax*bx+ay*by):
the coordinates of Q,C and P are represented as qx,qy,qz and cx,cy,cz and so on.
Let a=qx-px,b=qy-py,c=qz-pz,d=cx-px,e=cy-py and f=cz-pz:
cooeficients of quadratic eq of t:
A=pow(dx*r,2)+pow(dy*r,2)+pow(dz*r,2)+pow(dx*d,2)+pow(dy*e,2)+pow(dz*f,2);
B=2*(a*dx*pow(r,2)+pow(r,2)*b*dy+pow(r,2)*c*dz+a*dx*pow(d,2)+b*dy*pow(e,2)+c*dz*pow(f,2));
C=pow(a*r,2)+pow(b*r,2)+pow(c*r,2)-pow(d,2)-pow(e,2)-pow(f,2)+pow(a*d,2)+pow(b*e,2)+pow(c*f,2);
Please point out the wrong calculation.