Suppose I have two input vectors with nonzero magnitudes:
Vector3 t;
Vector3 o;
I need to find the normalized vector v
such that out of all normalized vectors that are orthogonal to o
, v
is the one that is closest to this t
"target" vector. I also need to know if t
and o
are colinear in which case no one such single v
exists.
Illustration of this relationship:
For a concrete example, suppose I have a game where the player will occasionally see a certain compass-like object on a surface in the environment. The player will have to point the needle on this compass towards a pictured object that was placed randomly somewhere in the game world. When the player selects the needle's position, I need to know how far off the player's selection is from the "true" direction of the object.
The compass needle is fixed to rotate around an axis with world direction o
(perhaps this is the compass's transform.forward
), and the direction of the pictured game object is t
.
When t
and o
are not orthogonal, the compass needle will not be able to point directly in t
, so I want to know: How can I get the closest possible direction the compass needle can point at, which is v
? This way, I can measure the angle between this goal direction and the player's selected direction. And, when that angle is below some threshold, the player is successful.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…