where the array index represents latitude and longitude horizontally and vertically, respectively. The elements contain the elevation above sea level, which is of type double.
I’m unsure of a way in which I can store this data so that I can plot a 3D surface in ROOT. If anyone could guide me I’d appreciate it.
You can do this with a TH2D:
Assuming you have a 2D Array which stores the sea levels and 2 1DArrays which store the latitude and longitude corresponding to the indices and the Arrays are of length M, N and MxN, you can use the following code:
Double_t longitude[M];
Double_t latitude[N];
Double_t sealevel[M][N];
// Fill the arrays here
TH2D* hSeaLevel = new TH2D("hSeaLevel", "Sea Level", M, longitude, N, latitude);
for (Int_t i = 1; i <= M; i++)
for (Int_t j = 1; j <= N; j++)
hSeaLevel->SetBinContent(i, j, sealevel[i-1][j-1]);
hSeaLevel->Draw("SURF");
Hi,
i think a simpler way is using a TGraph2D: https://root.cern.ch/doc/v614/classTGraph2D.html
In this case one doesnt need to care about binnings, empty bins etc.
Painting methods are essentially same as for TH2.
Of course @OSchaile is right, it’s much easier with a TGraph2D, I should not post in the morning without coffee. XD
I’ve rewritten you the example:
Double_t longitude[M];
Double_t latitude[N];
Double_t sealevel[M][N];
// Fill the arrays here
TGraph2D* tgSeaLevel = new TGraph2D(M*N);
for (Int_t i = 0; i < M; i++)
for (Int_t j = 0; j < N; j++)
tgSeaLevel->SetPoint(i*N+j, longitude[i], latitude[j], sealevel[i][j]);
tgSeaLevel->Draw("SURF");