14,639,666 members
Rate this:
See more:
```#include <iostream>
using namespace std;
int main()
{
Vectorf point(3);
point.set(0,0,3.0);
point.set(1,0,2.0);
point.set(2,0,1.0);

double angle = 0.0;
float sx = 0.5, sy = 0.5;
float ax = 2.0, ay = 2.0;
float tx = 0.0, ty = 1.0;
double const Pi = 4 * atan(1.0);
angle = Pi / 6 ;
cout<< "The result of Rotation (angle).Skew(s).Scaling(a).
Translation(t) X M of point is(M') " << endl <<
(Rotate_R(Skew_s_X(Skew_s_Y(Scale_a(Translate_t(point,tx,ty),ax,ay),sx),sy),angle));
cout << endl;
return 0;
}```

i have to multiply a matrix `M={{'3'},{'2'},{'1'}};` to
`(Rotate_R(Skew_s_X(Skew_s_Y(Scale_a(Translate_t(point,tx,ty),ax,ay),sx),sy),angle));`
how to declare a matrix and multiply it to the above thing...???
Posted
Updated 14-Apr-11 19:41pm
v2

Rate this:

## Solution 1

I strongly doubt your code would compile. For instance what (the fresh hell) is `Vectorf`? Where is it declared?
Moreover, without knowing `Rotate_R,Skew_s_X`,... function prototypes, how can we guess the answer?
Rate this:

## Solution 2

I am going to make somea helluvalot assumptions, but only because I think I know what you are trying to do and am familiar with the mathematics of transformations in 3D linear space:

1. I assume all these functions Rotate_R(), Skew_s_X(), Scale_a(), etc. are linear transformations
2. Each of these functions take a point as an argument, apply a transformation on it, and return the transformed point.
3. The points are 2D points, since you only seem to be using x and y values to describe your transformations. The transformations are therefore transformations of 2-space.
4. Vectorf is a type that represents a point. The coefficients of your Vectorf are most likely floats, as you are using float variables for your transformations as well. (the 'f' suffix is also a giveaway)
5. M is a matrix of values that itself describes an as of yet undefined* linear transformation.
*I say undefined, because the definition you gave is a 3x1 matrix, or a vector rather than a 2x2 matrix as you would need to be able to 'multiply' it onto anything from 2-space. I presume you misread what M should look like, or misrepresented it here.
6. For some reason you have functions to describe transformations (see1), but the task you describe involves multiplying a matrix by the nested transformation described with the help of your functions. This causes me to assume that you defined these functions yourself, and without regard to the actual task.

Solution:
Most of the transformations (see 1) are linear transformations in 2-space, and therefore can be described as a 2x2 matrix. When you apply a transformation M (a 2x2 matrix) on a point P (a 2x1 vector), what you do, mathematically, is compute the product Q=M*P.

When you apply more than one transformation on P, you can of course concatenate this and calculate R=M2*Q=M2*(M*P). You did the same thing, by implementing each transformation as a function that transforms a point into another point and you concatenated the transformation by nesting the function calls.

Now, what do you do, when you want to apply a transformation on not just one, but on many points P1, P2, P3,... ? You could do the nested calls for each point of course. But there is a better way: Consider the formula above - R=M2*(M*P). In this formula, the multiplication is associative, you can also write it like this: R=(M2*M)*P. Now define MTotal=M2*M and you get R=MTotal*P. And for applying the concatenated transformations on many points, you can again just use MTotal and multiply it on each point, rather than step by step applying each individual transformation.

This is what you must do here: instead of defining your various transformations as functions that take a point as an argument and calculate a point as a result, define them as a matrix. Define a Matrix R for your rotation, a matrix SX and SY for your skewings, and a matrix S for your scaling transformation. Define matrix multiplication (easy enough to google for if you don't know how), and calculate your combined transformation by multiplying the matrices.

Unfortunately, a translation (I'm referring to your function Translate_t) is not a linear transformation and therefore cannot be represented as a 2x2 matrix. There are ways to resolve this, but I'm running out of time, and anyway, depending on the wording of your task it may not be neccesary to include this transformation in your final transformation matrix.

I hope my assumptions weren't completely off and this wall of text actually helps you accomplish something, or at least helps others to pick up where I left - I am off for a holiday now. Good luck!