2
The code consists of calculating the volume of an uneven surface where I am using a matrix 2 x 2
of maximum size 1000 x 1000
, which represents a rectangle, so the maximum area of the land is 1.000.000 m²
, and I must use a variable y
free, which represents the height of the land, as the terrain is irregular the y
varies, in areas of slopes and slopes of the land.
I want to calculate the total volume of the land, where I should use an incremental delta applied to the coordinates X
, Y
and Z
. At each step of applying the delta to the coordinates, a calculation/addition of the volume of a small cube of volume delta³ to the total volume of the land, not exceeding the dimensions of the land or the calculation will be wrong, where here also for the coordinate Y
, I must calculate a line of interpolation between two heights Y
in order to determine the limit of cubes added for the calculation of the volume, that is, a limit for the progression of the loop that will systematically scan the height of the terrain.
When a cube crosses the boundary of the coordinate Y
interpolated is the time to end the loop that increments the coordinate Y
.
I’m doubtful how to do this I wrote a code, below follows the loop part, however an error occurs and I’m doubtful how to fix:
for(i=0; i<x; i++){ // x representa a largura do terreno
for(j=0; j<z; j++){ // z representa a profundidade do terreno
fscanf(y, "%.2f\t", altitude[i][j]); // Armazena os valores das coordenadas x e z na altura y ( DÚVIDA NESSA LINHA, SEMPRE QUE TENTO ARMAZENAR NA VARIÁVEL Y, OCORRE ERRO )
}
}
for(i=0; i<x; i++){
for(j=0; j<z; j++){
delta = aux - altitude[i][j];
volume = volume +(altitude[i][j]*delta);
aux=altitude[i][j];
}
}
printf("\n O volume do terreno é: %f\n", volume);
What error appears when you compile?
– StillBuggin
Basically the error occurs in this line fscanf(y, "%.2f t", altitude[ i ] [ j ]); the program does not compile, and I also doubt if just this loop I wrote is enough to solve my problem.
– Alan Nascimento
Yeah, your question is really unclear. First of all, okay, the program doesn’t compile... but what is the compiler error message? Second, what do you want to do in this line of
fscanf
? If you only want to store the array value in the variabley
, why didn’t you justy = altitude[i][j]
?. On the question of calculation, you are considering the terrain as being divided into discrete portions (the cells of the array), right? Maybe if you prepare an illustrative drawing of how your matrix represents your terrain this will help (even you) in understanding the problem.– Luiz Vieira
fscanf(f, "%f" , &( altitude[i][j] ))
?– JJoao