View Full Version : transforming vector 'p' to vector 'q'
Spudman
04-18-2006, 05:53 AM
I have two normalised vectors 'p' and 'q'. I wish to create a transform matrix
to map from 'p' to 'q' - any ideas ?
Wernaeh
04-18-2006, 06:15 AM
Problem: Find matrix A, so that A * p = q, with p, q in Rn
This problem has more than a single solution, considering that you have n equations (one for each vector element), and n * n variables, as the entries within the matrix A.
So what to do ? Pick arbitrary n * n - n variables, and set them to zero, and hope that the remaining n variables still form a valid equation system with a single solution.
However, there is another trick:
Pick only the diagonal elements of A, set all remaining ones to zero. This yields n equations of the form variable_i * p_i = q_i, which only depend on a single variable per equation, and are solvable if p_i == 0 for all i implies q_i == 0. Effectively, this creates a scaling transformation matrix to transform the vectors one into another.
Of course (as suggested by the solution criterion above), you cannot scale-transform vectors missing components into each other, so you need to handle these cases specially.
Another approach, limited to the R3 at max, is to determine the angle between the vectors, using a dot product. Then, using the cross product, build a normal vector thats perpendicular to your two vectors. From the normal vector and the angle, build a rotation matrix (perhaps have a look at the hexagon matrix FAQ for this).
Cheers,
- Wernaeh
Spudman
04-18-2006, 08:59 AM
Thinking about it... there is obviiously an infinite set of solutions. What I
want to do is to tilt a flat plane ( normal 0,1,0 ) so that its normal is the
new vector. Hmmm
Reedbeta
04-18-2006, 09:50 AM
Try doing a rotation, where the axis of rotation is the cross product (normalized) of p and q, and the angle of rotation can be found by computing the arc-cosine of their dot product. There are functions for computing an axis-angle rotation matrix all over the Internet and in many 3D APIs. (This is just what Wernaeh suggested in his last paragraph, btw.)
zavie
04-20-2006, 05:58 PM
You are basically implementing a billboard?
All you need to reduce the number of solutions is another vector, which for example could forbid your plane to turn.
Maybe this article about billboards (http://www.flipcode.com/articles/article_rtr2billboards.shtml) can help you to get toward your solution.
Spudman
05-02-2006, 05:30 PM
No... not billboards, I just wanted to orient one surface to another. The post above worked ok. (ie. rotate around the cross-product... ),
If your original normal is always as simple as [0,1,0], then you shouldn't waste time on inverse trigonometric functions.
Let n be the new normal of your plane. You want for matrix to transform [0,1,0] into n, so n is the second column of your matrix. The two remaining columns is a chosen orthogonal basis for the new plane of yours defined by n. The x-product between the new and the old normal will give you one choice of one of these vectors (in case n is not parallell to [0,1,0]) and the second can be gotten by taking the x-product again.
Explicitly: Let u= [0,1,0] x n and v= n x u. Your matrix is now [u | n | v].
Of course, it simplifies in your case since your original normal is very simple: if n = [n1, n2, n3], then the rotation matrix above is just
[ n3 n1 -n1*n2 ]
[ 0 n2 n1^2 + n3^2]
[-n1 n3 -n2*n3 ]
Thanks,I happened to find the thread , which gives me an idea on how to translate a vector3 to another vector3.
I 'm doing a filght simulation game.My games supports inside viewtype.So I need a vector3 variable HeadUp to build the view matrix.
The origin vector3 is (0 , 1 , 0) ; the attitude of my plane is planeAttitude ;
Before today , I do the calculation myself and get the fomular below:
{-Sin(Roll)Cos(Yaw),
Cos(Roll)Cos(Pitch)-Sin(Yaw)Sin(Roll)Sin(Pitch),
-Sin(Yaw)Sin(Roll)Cos(Pitch)-Cos(Roll)Sin(Pitch)}
Not tidy , isn't it?
After I read the thread , I use
Headup = Vector3.TranslationNormal(new Vector3(0 , 1 , 0) , Matrix.RotationYawPitchRoll(Yaw , Pitch , Roll) );
instead .
It's a much more clearly way to do , aha?
vBulletin, Copyright ©2000-2009, Jelsoft Enterprises Ltd.