Suppose a point in 3D space, Q.
For any other point x in that space, Let Q(x) be the unit vector pointing from x towards Q.
I also have a line L in 3D space, and a point on this line P. L = {P + k*w}, for any scalar k and a given unit vector w that points from P along L.
I also have some vector v of unit length.
Finally, I have a target value T.
I am interested in computing P' = P + q*w (which is to say, I'd like solve for q), that brings Q(P') * v as close as possible to T, where * is dot product.
Intuitively, since Q() and v are unit length and the dot product is thus cosine, I'm trying to move P to P' so that the angle formed by P -> Q and v matches a target value, or at least gets as close as possible.
This is for a real life problem that I am writing a program for, and the program needs to be efficient. As such, kudos for avoiding expensive calculations (sin, cosine, sqrt, etc.)
Edit - Example Suppose:
- P = (0,0,0)
- w = (-1, 0, 0)
- v = (0, 1, 0)
- Q = (0, 1, 0)
- T = 1/2
One solution is q = sqrt(3).
P' = P + qw = (-sqrt(3), 0, 0) Q(P') = (sqrt(3)/2, 1/2, 0) Q(P') * v = 0*sqrt(3)/2 + 1/2 * 1 = 1/2 = T
You might just want to solve a quadratic equation then.
$$\frac{(Q-P-kW)\cdot v}{||Q-P-kW||}=t$$
Let $Q-P=(a_1,a_2,a_3), W=(b_1,b_2,b_3), v=(v_1,v_2,v_3)$,
$$\frac{a_1v_1+a_2v_2+a_3v_3-(b_1v_1+b_2v_2+b_3v_3)k}{\sqrt{(a_1-b_1k)^2+(a_2-b_2k)^2+(a_3-b_3k)^2}}=t$$
Simplifying this gives you a quadratic equation in terms of $k$:
$$(b_1v_1+b_2v_2+b_3v_3-t^2(b_1^2+b_2^2+b_3^2))k^2\\-(2(a_1v_1+a_2v_2+a_3v_3)(b_1v_1+b_2v_2+b_3v_3)-t^2(a_1b_1+a_2b_2+a_3b_3))k\\+(a_1v_1+a_2v_2+a_3v_3)^2-t^2(a_1^2+a_2^2+a_3^2)=0$$
It looks complicated, but using computer to calculate the quadratic formula is not that hard.
If there are two roots or one root, it would be the answer. If there are no roots, you can find the maximum or minimum value of the quadratic function. That would be the point that is closest to zero.