Hello.
It is not allowed to do something like this:
|
coords[i] = {x_point[i], y_point[i], z_point[i]};
|
That list of numbers including curly braces on the right hand side is called "Array Initialization List", which is allowed only when you "initialize" the array.
From what I know, I can think of no better solution than assigning them one by one like this:
1 2 3 4 5 6 7 8 9
|
const int COORD_X_INDEX = 0;
const int COORD_Y_INDEX = 1;
const int COORD_Z_INDEX = 2;
for( int i = 0; i < n_atoms; i++ )
{
coords[i][COORD_X_INDEX] = x_point[i];
coords[i][COORD_Y_INDEX] = y_point[i];
coords[i][COORD_Z_INDEX] = z_point[i];
}
|
Or If you want to save a little more line, notice that if you line up x_point, y_point, and z_point in row and read in vertical way, one column becomes each point.
/*x_point*/ { 1, 2, 3, 4, 5, ...}
/*y_point*/ { 2, 3, 4, 5, 6, ...}
/*z_point*/ { 3, 4, 5, 6, 7, ...}
-> {1, 2, 3}, {2, 3, 4}, {3, 4, 5}, ... if you read column by column.
Then this is possible:
1 2 3 4 5 6 7 8 9 10 11 12
|
// Create array of pointer to doubles.
double* xyz[] = { x_point, y_point, z_point };
// Array is treated as pointer here.
// array name in expression returns pointer to the first element of the array.
for( int i = 0; i < n_atoms; i++ )
{
for( int j = 0; j < 3; j++ )
{
coords[i][j] = xyz[j][i];
}
}
|
Sorry if I misunderstand what you want to do again. English is not my native language.