Calculating the volume of uneven terrain [closed]

2

The code is to calculate the volume of an irregular surface where I am using a 2 x 2 array of maximum size 1000 x 1000 , which represents a rectangle, so the maximum area of the terrain is 1.000.000 m² , and I must use a variable y free, which represents the height of the terrain, as the terrain is irregular y varies, in regions of slopes and slopes of the terrain.

I want to calculate the total terrain volume, where I should use an incremental delta applied to the X , Y , and Z coordinates. At each step of the application of the delta to the coordinates, a calculation / addition of the volume of a small cube of delta³ volume must be made to the total volume of the terrain, not exceeding the dimensions of the terrain or the calculation will be wrong, where here also for the coordinate Y , I must compute an interpolation line between two Y heights in order to determine the cube limit added for the volume calculation, ie a limit for the progression of the loop that will systematically sweep the terrain height .

When a cube transposes the coordinate limit Y interpolated it will be the time to end the loop that increments the Y coordinate.

I'm wondering how to do this I wrote a code, below follows the part of the loop, 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);
    
asked by anonymous 06.12.2015 / 03:12

1 answer

0

I do not quite understand what you want to do on the line with the fscanf statement, but if you are trying to write the result to a file, the best would be to use the fputs statement. Take a look at here .

But if you just want to calculate the total terrain volume, you just add up all the heights you stored in the array. Something like this:

// inicializa volume com 0 para acumular no loop
int volume = 0;
for(i=0; i<x; i++){
    for(j=0; j<z; j++){
      // adiciona o volume de cada área
      volume += altitude[i][j];
    }
}

At the end of this loop, the variable volume will have the total terrain volume.

    
06.12.2015 / 03:39