Matrix Transformationa

Status
Not open for further replies.

jfmiller28

Ars Centurion
206
Subscriptor
Help:

I need an algorithm that will take points and vectors in one Frame of reference and transform them to another.

Details:

I have 2 RF call them this and other, bothe are 3d Carteasians(sp?).

I want to find the coordinates of points and vectors currently defined relitive to 'other' in 'this.' I therfore need a 3X3 matrix to operate on these points.

here's what I know:

3 unit vectors pointing in the direction of the x,y,&z-axies of other relitive to this.

you may do any of the following:

any standard vector operations (dot cross magnitude etc...)

any standard Matrix operations (det, mult, etc...)

you may also describe a rotation to be applied to the matrix as a right-hand rotation of some angle about some axis(vector).

once again the goal is to find a matrix M that when multiplied bw a vector in the 'other' reference fram will give me that vector in the 'this' reference frame.

Thanks for the help.

JFMILLER
 
You will need the third to determine the orientation unless the orientations is given by, say, the wedge (or cross or vector) product of the two other directions (taken as vectors).
Which it will be since the 2 vectors in the equations above are not swappable. You know which one maps to which other one. See them as i and j in the local system... given those 2, it's easy to compute z. So 2 vectors should be enough.
 

Emil Hedevang

Smack-Fu Master, in training
79
In fact if you know the mapping of the basis vector x, y, and z to the basis vectors x', y' and z', you are done since any vector v = ax+by+cz vil map to v'=ax'+by'+cz'. If (x,y,z) is the standard basis of R^3 or you have the coordinazation (a,b,c) of the vector v, this is easy.

But I do not like the idea of assuming that the third basis vector is given by the two others. In general this is not the case.
 

Emil Hedevang

Smack-Fu Master, in training
79
SPOILER ALERT!

Allow me to give the full solutions to the problem.

Let B = (b_1, ... , b_n) and B' = (b'_1, ... , b'_n) be ordered basis of R^n (the n-dimensional euclidian space). Now a vector v in R^n can be written uniquely the sum v = r_1 b_1 + ... + r_n b_n. The coordinazation of v relative to B is the v_B = (r_1, ... , r_n).

Form the matrix M_B = [b_1, ... , b_n] with b_i as column vectors. Then M_B v_B = v. In the same manner M_B' v_B' = v, so we have M_B v_B = M_B' v_B'. Since the matrices M_B and M_B' are invertible (their columns form bases), we have v_B' = ((M_B')^-1 M_B) v_B.
 
But I do not like the idea of assuming that the third basis vector is given by the two others. In general this is not the case.
Unless your space is skewed (which doesn't seem to be the case here since he's talking about reference frames, which I'd assume all use orthonormal bases), the 3rd vector can be computed from the first two. I'll agree the general solution is better though, but it's already been a year since I've done that stuff and I've forgotten too much of it :)

Edit:
3 unit vectors pointing in the direction of the x,y,&z-axies of other relitive to this.
That's what I was talking about, in simpler terms.
 

Emil Hedevang

Smack-Fu Master, in training
79
If (x,y,z) is an orthonormal basis for one frame, then so is (x,y,-z) but the latter has the oposite orientation of the first.

Anyhow, if both frames have orthonormal bases and the oritentation is preserved when going from one frame to another (a right screw is still a right screw in the new frame), then change-of-coordinate matrix is orthogonal with determinant 1. If orientation is not preserved, the determinant is -1.

The 2-dimensional case is easy to picture. The basis is just rotated around the origin if orientation id preserved. If orientation is not preserved, then also one of the basis vectors will have the opposite sign.

Rotation in 2D through an angle of A is given by the matrix whose first column is [cos A, sin A] an second is [-sin A, cos A].

Man, I would love the ability to include inline PDF-files. That would make communicating mathematics so much easier!
 

jfmiller28

Ars Centurion
206
Subscriptor
Hi all, thanks for all the help!

Let me clarify a little:

I have a class, RFrame, which contains vectors and points in a linked list. It also contains other RFrames who are defined by 2 unit vectors one that points in the -z (Out) direction the other that points in the "up" direction. Up need not be orthogonal to -z. I then forn x = -z X up, where "X" denotes the cross product. y can be defined as the unit vector orthogonal to x and z for a right handed system. There is also a vector which gives displacement to the origian, but it is easy to ignore this because in a 4X4 matrix, it constitutes the 4th column. What I need to know is how to derive the 3x3 rotation portion of the matrix.

Follow this link to see what I already know.

My problem becomes finding which rotations are necessary to find orientation of the points and vectors in the first frame as seen by the second one. I had thought that the following would work but it seems to give the wrong answers for non trivial cases (ie not 90 deg rotations).

code:<HR>
Code:
Matrix mChangeFrame(Vect front, Vect up)
{
	Matrix m;
    Vect x_prime = Cross(front,up); //find a vector in the x direction
	front.Unit();// make |front| = 1 so asin will be correct
	//Cross front with the negitave z axis store rotation and front'
        double rad = asin(front.Cross(Vect (0.0,0.0,-1.0))); 
	m.Rotate(-rad,front); // rotate front to the -z axis using front'
	x_prime.Transform(m); //rotate x to the new frame
    x_prime.Unit();
	rad =asin(x_prime.Cross(Vect(1.0,0.0,0.0))); //find the angle between x and x'
  	m.Rotate(-rad,x_prime); // rotate up to x axis
	return m;
}

Now it is certianly possible that the underlying functions are errent and that this is correct, but I have spent a good deal of time testing and debugging them and I am fairly certian that this is the source of the problem.

JFMILLER
 

Emil Hedevang

Smack-Fu Master, in training
79
I have begun reading the artivle right now. Then I encounter

The set of special orthogonal matrices is a closed set. What does that mean, and why do we care?

A question like this is usually discussed only in an upper-division set theory class, which is a class for seniors majoring in math on the theoretical side.

So I yell "WHAT?" Why do I do that, you may ask? Because the answer is simple. (Assume that all the following matrices are n times n-matrices). A is an orthogonal matrix, if and only if det(A) is either -1 or 1. The determinant is a continuous mapping from the vector space of n times n-matrices to the set of real numbers. A function f from X to Y is continuous if and only if the pre-image of an open set in Y is an open set in X, that is f^{-1}(B) is open in X for all open B in Y.
The same holds if you replace the word "open" with "closed". Since the set {-1,1} is a closed set in the set of real numbers and det^{-1}({-1,1}) is the set of orthogonal matrices, this set is closed.

Therefore I see no need for scarying the reader as the author does. Basic knowledge about point set topologi is enough.

As for you debugging, JFMiller, I can only suggest writing down the actual mathematical steps and then later optimize the code. If you do not want to do that, I can say that random line or character swapping is usefull for me.
 
Status
Not open for further replies.