Sign in to follow this  

Transformations

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am reading about Transformation. I googled it and found that it combines rotations, shears, scalings, and so on, all in one. Is gluLookAt(...) from glut, an example of an affine transformation that combines translation and rotations ?

Share this post


Link to post
Share on other sites
Quote:
Is gluLookAt(...) from glut, an example of an affine transformation that
combines translation and rotations ?
Yes, it is :)

'Look-at' functions, in general, do the following:

1. Build a rigid-body (i.e. rotation and translation only) transform given a position, a target position, and an up vector for reference.

2. Invert the transform.

The transform is inverted so that it can be used as a view/camera transform. A 'look-at' transform without the inversion is essentially an 'aim-at' transform, which can be used (for example) for billboard effects.

Share this post


Link to post
Share on other sites
Another question.

So I am reading that the contraction and expansion in the horizontal direction
is given by the matrix
M =
[k 0]
[0 1]

and the contraction and expansion in the vertical direction is given by
N =
[1 0]
[0 k]

So that essentially is scaling the object. How would I apply this to an object.

Say I have a rectangle defined by the points: (0,1),(1,1),(0,1),(0,0).
How would I scale the rectangle? Would I represent the rectangle by a matrix and
multiply it by either M or N? Can you show me an example please? Thanks.

Share this post


Link to post
Share on other sites
Vector math does not allow to multiply 2 matrices where the number of columns in the left matrix is different from the number of rows in the right matrix. So you cannot packetize an arbitrary (here 4) amount of vectors to build a matrix for a specific matrix product.

Instead, you would multiply each point vector by the transformation matrix, so that you get the same amount of (transformed) vertices at the end. E.g.
pi' = M * pi where i = 1,...,4
Here M (i.e. the matrix on th left) has 2 columns, so the points pi (the matrix on the right) needs to have 2 rows. Because the pi has only 2 values, it is therefore a matrix with 2 rows and 1 column. Hence it is named a "column vector".

You can also try the other way around:
qi' = qi * M where i = 1,...,4
Here M (i.e. the matrix on the right) has 2 rows, so qi needs to have 2 columns by 1 row. Hence it is named a "row vector".

This distinction is important due to matrix multiplication isn't commutative. The conversion between the 2 kinds is named "transposition" (a mirroring about the left-top to bottom-right diagonal). To be precise, the M's in the both formulas above are also not the same, because the one M must be the transpose of the other M.

EDIT: Forgotten to say:
The matrix product goes as follows: The value of the resulting matrix at column j and row k is the sum of all particular products of the values of the k-th row of the left argument matrix by the j-th column of the right argument matrix.
/EDIT

Now, using row vectors as an example, the products are
p1' = p1 * M = ( k * 0 + 0 * 1, 0 * 0 + 1 * 1 ) = ( 0, 1 )
p2' = p2 * M = ( k * 1 + 0 * 1, 0 * 1 + 1 * 1 ) = ( k, 1 )
p3' = p2 * M = ( k * 1 + 0 * 0, 0 * 1 + 1 * 0 ) = ( k, 0 ) // the OP has a faulty point here
p4' = p2 * M = ( k * 0 + 0 * 0, 0 * 0 + 1 * 0 ) = ( 0, 0 )
so you can see a scaling in the horizontal direction.

[Edited by - haegarr on February 14, 2010 2:09:04 AM]

Share this post


Link to post
Share on other sites
Oh, cool. Thanks for that sweet lesson, although I haven't grasped what
some of the technical term means, at least I understand the main part.

So its essentially is like multiply like so :

Let M =
[k 0]
[0 1]

Let a Rectangle R be defined by the points, tl = (0,1), tr = (1,1),
br = (0,1), bl = (0,0).

Then the new set of points is calculated by the following multiplication, right?

tl *= M;
tr *= M;
br *= M;
bl *= M;

where are represent t* and b* as a column vector, and M as a 2x2 matrix?

Share this post


Link to post
Share on other sites
Quote:
Then the new set of points is calculated by the following multiplication, right?

tl *= M;
tr *= M;
br *= M;
bl *= M;

where are represent t* and b* as a column vector, and M as a 2x2 matrix?
It depends on how the *= operator is implemented. Typically, v *= M would be equivalent to v = v * M, meaning that the vectors would be row vectors rather than column vectors.

Share this post


Link to post
Share on other sites
Oh. I see thank you. BTW, how would I appropriately define the coordinates
of the rectangle? Would it be a good idea to define it as a matrices like
R =
[x y]
[x y+1]
[x+1 y+1]
[x+1 y]

and then pass it onto a function called Matrix scaleHoritontal(const Matrix& m);
where it does the necessary transformation. I'm just trying to visualize how
one would implement one of these transformation, static methods, an Algorith
class, or what ?

Share this post


Link to post
Share on other sites
Quote:
Original post by Concentrate
Oh. I see thank you. BTW, how would I appropriately define the coordinates
of the rectangle? Would it be a good idea to define it as a matrices like
R =
[x y]
[x y+1]
[x+1 y+1]
[x+1 y]

and then pass it onto a function called Matrix scaleHoritontal(const Matrix& m);
where it does the necessary transformation. I'm just trying to visualize how
one would implement one of these transformation, static methods, an Algorith
class, or what ?
I'm not sure what the advantage of storing the coordinates in a matrix would be. Typically, you would just store the vertices in a container of some sort, and apply the transform matrix to each in turn (as described in haegarr's post).

Note that a quad doesn't necessarily require special handling. A triangle has three vertices; a quad has four; an n-sided polygon might have more than four. Each of these shapes (and many others) can be represented in exactly the same way: as a collection of vertices and (optionally) connectivity information (e.g. indices).

There are occasions where it may be advantageous to use a custom data structure for a particular type of shape, but in general you should think of geometric transformations as operating on a sequence of vertices, without regard for what shape they happen to represent. In other words, the function that applies the transform doesn't care (and doesn't even need to know) that the vertices it's working with represent a quad.

Share this post


Link to post
Share on other sites
Quote:
Original post by Concentrate
Oh I see, but would I still need to know how many vertices the polygon has
per a face?
I think that really depends on what problem you're trying to solve. There are many possible scenarios here - submitting geometry to a graphics API such as OpenGL or Direct3D, transforming geometry for the purpose of collision detection, manipulating geometry in a level editor or modeling program, etc. Each of these cases has different requirements, and you'd probably do things differently in each case.

Another way to answer the question would be, you'll know once you start writing the code. If you're writing the code and you reach a point in the logic where it's necessary to know how many vertices the polygon has, then yes, you need to know how many vertices the polygon has :)

So is there a particular problem you're trying to solve? Or are you just trying to gain a better understanding of geometric transforms in general?

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this