#### Archived

This topic is now archived and is closed to further replies.

# Convert a point using a matrix

This topic is 5264 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Suppose you have the point (x,y,z) and you want to convert it to something nasty like ((2x+5z)/(z+3),5,(y+2)/(z+3)) using a matrix. How do you go about doing this?? My knowledge of matrices is very limited. I've asked some buddies of mine currently enroled in Linear Algebra about a problem like this but they were also stumpted. [edited by - Nobles on March 2, 2003 10:34:21 PM]

##### Share on other sites
Why exactly do you want it done with a matrix? Just do the math, using a matrix isn''t going to give you any advantage.

Anyway I don''t think you can do transformations like the one you showed with a matrix. Notice the linear in linear algebra.

##### Share on other sites
This is a confusing question. I agree with Dobbs here, using a matrix makes no sense in this case. Do you have a specific goal you''re trying to accomplish, or what?

##### Share on other sites
Short answer, you can''t do that transformation with a matrix because of the 1/(z+3) terms, unless you believe in storing points with homgeneous coordinates. (in which case you''re transforming (x, y, z, 1) to (2x + 5z, 5z + 15, y + 2, z + 3).

The matrix to do <B> that </B> is

| 2, 0, 5, 0 |
| 0, 0, 5, 15 |
| 0, 1, 0, 2 |
| 0, 0, 1, 3 |

Anthony Serrano

##### Share on other sites
That''s exactly what I was looking for. I forgot about homogeneous coordinates!

Thanks Anthony

##### Share on other sites
I submitted this answer as part of a field trip for the class Introduction to 3D Game Programming, taught at Gameversity (http://www.gameversity.com)

(k_bukie)

Homogenization would be the way to go, but not all transformations can be represented with a matrix, and the one you suggest has certain singularities that you need to be aware of. For instance, it is invalid for z = -3, which is more visible before homogenization than after, though it is implied in the transformation.

Full solution:

Hom(| a11 a12 a13 a14 |) | x | | (2x + 5z)/(z + 3) |
(| a21 a22 a23 a24 |) | y | = | 5 |
(| a31 a32 a33 a34 |) | z | | (y + 2)/(z + 3) |
(| a41 a42 a43 a44 |) | w | | 1 |

So, the 4 linear equations are:

1. (a11*x + a12*y + a13*z + a14*w)/(a41*x + a42*y + a43*z + a44*w) = (2x + 5z)/(z+3)
2. (a21*x + a22*y + a23*z + a24*w)/(a41*x + a42*y + a43*z + a44*w) = 5
3. (a31*x + a32*y + a33*z + a34*w)/(a41*x + a42*y + a43*z + a44*w) = (y + 2)/(z + 3)
4. (a41*x + a42*y + a43*z + a44*w)/(a41*x + a42*y + a43*z + a44*w) = 1

Equation 4 is obvious, and doesn''t help anything at this time.

Starting with equation 1:
(a11*x + a12*y + a13*z + a14*w)/(a41*x + a42*y + a43*z + a44*w) = (2x + 5z)/(z+3)
According to the right side, the x coefficient is 2/(z+3). According to the left size, it is a11/(a41*x + a42*y + a43*z + a44*w).
This would suggest that a11 = 2, a41 = 0, a42 = 0, a43 = 1, and a44*w = 3. (Note that no assumptions are made about w quite yet).

The z coefficient, similarly, is 5/(z+3). Therefore, a13 = 5.

Now, the y coefficient is 0, so a12/(z+3) = 0. Therefore, a12 = 0. Similar for a14 = 0.

So, after the first equation, we have a matrix
| 2 0 5 0 |
| ? ? ? ? |
| ? ? ? ? |
| 0 0 1 ? |

Now, let''s look at equation #3 (cause it''s easier right now):
(a31*x + a32*y + a33*z + a34*w)/(a41*x + a42*y + a43*z + a44*w) = (y + 2)/(z + 3)

Similar to equation #1, the y coefficient is 1/(z+3), so a32 = 1. Since the x and z coefficients must be 0, a31 = a33 = 0.
Now, for the fourth coefficient, we have 2/(z+3). Looking at the left side of the equation, a34w/(z + 3). So, a34w = 2. This is where we need to make an assumption about w. For this set of equations, it works for w = 1, but this is a dangerous assumption, because we assume that we can find a solution before we know one exists. So, assuming w = 1, a34 = 2. Also making that assumption, a44 = 3.

So here''s our matrix:

| 2 0 5 0 |
| ? ? ? ? |
| 0 1 0 2 |
| 0 0 1 3 |

Now for equation 2:
(a21*x + a22*y + a23*z + a24*w)/(a41*x + a42*y + a43*z + a44*w) = 5
Assuming the solution exists, and assuming w = 1, we can do the following:

a21*x + a22*y + a23*z + a24*w = 5(0 + 0 + z + 3) = 5z + 15 (invalid for z = -3)

Therefore, based on that equation, the x coefficient is 0, and the y coefficient is 0, so a21 = a22 = 0. However, with the modification in the equation, the z coefficient is 5, which on the left side is now just a23, so a23 = 5.
The w coefficient is 15, so assuming w = 1, a24 = 15.

Therefore, the transformation matrix is:
| 2 0 5 0 |
| 0 0 5 15|
| 0 1 0 2 |
| 0 0 1 3 |

This was done using 2 dangerous assumptions: First that a solution exists and each equation satisfied that solution, and that w = 1.

(Yes, I know the solution was already included, but I had to do one for class, and I had a dispute as to whether the solution was so simple and/or valid in all cases).

##### Share on other sites
Long story short, pick up a good linear algebra book

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5
frob
12

• 9
• 21
• 11
• 9
• 17
• ### Forum Statistics

• Total Topics
632606
• Total Posts
3007383

×