1. ## populating matrices

hi all

im am having trouble defining my matrices i have defined them as follows

Code:
```float Tx[4][4], Ty[4][4], Tz [4][4];
float Rx[4][4], Ry[4][4], Rz [4][4];

float d, theta;```
then i have populated d and theta with variable data and try and do the following to populate matricies

Code:
```Tx[][]= { {1, 0, 0,d}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1} } ;
Rx[][]= { {1, 0, 0, 0}, {0, cos(theta), -sin(thera), 0}, {0, sin(theta), cos(theta), 0}, {0, 0, 0, 1} };```
and i keep getting lots of syntax errors. is this posible or do i have to it element wise?

jamie

2. here is the full code it might make what i said above make a little more sence.

Code:
```int i;
float d, theta;

/*----- translational motion matices----*/
float Tx[4][4], Ty[4][4], Tz[4][4];

/*----- Rotational motion matices----*/
float Rx[4][4], Ry[4][4], Rz[4][4];

float result[4][4];

for(i=1;i<index+1;i++){

struct Joint *create=&Joints[i]; /*local pointer to make addressing quicker*/

theta=(create->position)*PI/180;

struct Section *temp=&Sections[i];
d=temp->length;

/*-------------------joint actuation------*/
if(create->type=='r'){
if(create->axis=='x'){
Rx = {  {1, 0, 0, 0}, {0, cos(theta), -sin(theta), 0}, {0, sin(theta), cos(theta), 0}, {0, 0, 0, 1}  };
mult_matrices(Rx, result, result);
}
if(create->axis=='y'){
Ry[][4] = {  {cos(theta), 0, sin(theta), 0}, {0, 1, 0, 0}, {-sin(theta), 0, cos(theta), 0}, {0, 0, 0, 1} };
mult_matrices(Ry, result, result);
}
if(create->axis=='z'){
Rz[][4] = {  {cos(theta), -sin(theta), 0, 0}, {sin(theta), cos(theta), 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1} };
printf("......  %f  ....\n",Rz[1][1]);
mult_matrices(Rz, result, result);
}
}

if(create->type=='t'){
if(create->axis=='x'){
Tx[4][4] = {  {1, 0, 0, d}, {0, 1, 0, 0}, {0, 0, 1,0}, {0, 0, 0, 1}  };
mult_matrices(Tx, result, result);
}
if(create->axis=='y'){
Ty[4][4] = {  {1, 0, 0, 0}, {0, 1, 0, d }, {0, 0, 1,0}, {0, 0, 0, 1}  };
mult_matrices(Ty, result, result);
}
if(create->axis=='z'){
Tz[4][4] = {  {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, d}, {0, 0, 0, 1}  };
mult_matrices(Tz, result, result);
}
}

/*----------------section translation-------*/
mult_matrices(Tz, result, result);

/*----------Angular offset to next joint-------*/

if (i<3){
struct Joint *create2=&Joints[i+1];

if(create2->axis='x'){

}
}

}
/*multiplication of all the matricies*/

}```
it is part of a much bigger robotics simulation. the aim being to try and transfer between one cordinate frame and another, i think the problem is just the way i am trying to populate the matrices that is the problem. i have been trying to read about the subject but everyone seems to populate them when they define them which i can not do as d and theta change in real time.

thanks again

jamie

3. Try doing it this way
Code:
```   double d = 0.5;
double theta = 45.0;

double Tx[4][4] = {
1.0, 0.0, 0,d,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
};

double Rx[4][4]= {
1.0, 0.0, 0.0, 0.0,
0.0, cos(theta), -sin(theta), 0.0,
0.0, sin(theta), cos(theta), 0.0,
0.0, 0.0, 0.0, 1.0
};```
This should get rid of your compile errors and any warnings as well.

4. yeah thats how i was doing it befor, but theta and d change as the program runs as they are fetched from another structure and using this method the values in the matrix dont get updated.

5. ok thanks Kcpilot i have solved it now i think heres how if anyone is intersted

Code:
```void Robot::Posiition(int index){

/*--------------------------------------forward kinematics---------------------------------------------------------*/

int i;
float d=9, theta=1;

/*----- translational motion matices----*/
double Tx[4][4] =	{	{1, 0, 0, d},
{0, 1, 0, 0},
{0, 0, 1, 0},
{0, 0, 0, 1}
};
double Ty[4][4] =	{	{1, 0, 0, 0},
{0, 1, 0, d},
{0, 0, 1, 0},
{0, 0, 0, 1}
};
double Tz[4][4] ={	{1, 0, 0, 0},
{0, 1, 0, 0},
{0, 0, 1, d},
{0, 0, 0, 1}
};

/*----- Rotational motion matices----*/
double Rx[4][4] =	{   {1, 0,			0,			 0},
{0, cos(theta),                    -sin(theta),                               0},
{0, sin(theta),                      cos(theta),	                 0},
{0, 0,			0,			 1}
};
double Ry[4][4]=	{  {cos(theta), 0, sin(theta), 0},
{0,              1,   0,              0},
{-sin(theta),0, cos(theta), 0},
{0,              0,	0,           1}
};
double Rz[4][4] =	{  {cos(theta), -sin(theta), 0, 0},
{sin(theta), cos(theta),  0, 0},
{0,	      0,	          1,  0},
{0,	      0,	          0,  1}
};

double result[4][4] = {	{1, 0, 0, 0},	//Initalised to identity maxtix equivalant to 1
{0, 1, 0, 0},
{0, 0, 1, 0},
{0, 0, 0, 1},
};

for(i=1;i<index+1;i++){
struct Joint *create=&Joints[i]; /*local pointer to make addressing quicker*/

theta=(create->position)*PI/180;

struct Section *temp=&Sections[i];
d=temp->length;

/*-----------------------------------Joint Actuation-----------------------------------*/

/*---Rotational Joints---*/
if(create->type=='r'){
if(create->axis=='x'){
Rx[1][1] = cos(theta);
Rx[1][2] = -sin(theta);
Rx[2][1] = sin(theta);
Rx[2][2] = cos(theta);

mult_matrices(Rx, result, result);

}
if(create->axis=='y'){

Ry[0][0] = cos(theta);
Ry[0][2] = sin(theta);
Ry[2][0] = -sin(theta);
Ry[2][2] = cos(theta);

mult_matrices(Ry, result, result);

}
if(create->axis=='z'){

Rz[0][0] = cos(theta);
Rz[0][1] = -sin(theta);
Rz[1][0] = sin(theta);
Rz[1][1] = cos(theta);
mult_matrices(Rz, result, result);

}
/*---section Length translation to next joint-------*/

Tz[2][3] = d;
mult_matrices(Tz, result, result);
}

/*---Translational Joints---*/
if(create->type=='t'){
if(create->axis=='x'){

Tx[0][3]=d;
mult_matrices(Tx, result, result);

}
if(create->axis=='y'){

Ty[1][3]=d;
mult_matrices(Ty, result, result);

}
if(create->axis=='z'){

Tz[2][3] = d;
mult_matrices(Tz, result, result);

}
}

/*----------Angular offset to next joint-------*/

if (i<3){
struct Joint *create2=&Joints[i+1];

if(create2->axis='x'){

}
}

}

}```
appoliges for the indenting it all got changed when i copyed it in i have tried to tidy it up as best as possible