Hi everybody.

I used TGraph2D->Draw(“tri”) to triangulate a set of points. It worked very well. I would like now to write in an ASCII file the “tringulated” data like e.g. a list of triangles. I don’t know where to take the data from.

Thank you.

Hi everybody.

I used TGraph2D->Draw(“tri”) to triangulate a set of points. It worked very well. I would like now to write in an ASCII file the “tringulated” data like e.g. a list of triangles. I don’t know where to take the data from.

Thank you.

I looked. Where I get the poiter to TGraphDelaunay from?

I filled a TGraph2D with points than draw it:

```
TTree t;
t.ReadFile("SomeFile","x/F:y:z");
t.Draw("x:y:z","","goff");
TGraph2D* pGr2D = new TGraph2D("2DGraph", 2DGraph", t.GetEntriesFast(), t.GetV1(), t.GetV2(), t.GetV3());
pGr2D->Draw("triw");
```

TGraph2D don’t contain any pointer to the TGraphDelaunay.

Example:

```
{
Double_t P = 5.;
Int_t npx = 20 ;
Int_t npy = 20 ;
Double_t x = -P;
Double_t y = -P;
Double_t z;
Int_t i, k = 0;
Double_t dx = (2*P)/npx;
Double_t dy = (2*P)/npy;
TGraph2D *graph2d = new TGraph2D(npx*npy);
graph2d->SetName("Graph2DA");
graph2d->SetNpy(40);
graph2d->SetNpx(40);
for (i=0; i<npx; i++) {
for (Int_t j=0; j<npy; j++) {
z = sin(sqrt(x*x+y*y))+1;
graph2d->SetPoint(k,x,y,z);
k++;
y = y+dy;
}
x = x+dx;
y = -P;
}
TGraphDelaunay *gd = new TGraphDelaunay(graph2d);
gd->SetMaxIter(100000);
gd->SetMarginBinsContent(0);
gd->ComputeZ(0,0);
gd->FindAllTriangles();
Int_t Ndt = gd->GetNdt();
printf("Ndt = %d\n",Ndt);
Int_t *MT = gd->GetMTried();
Int_t *NT = gd->GetNTried();
Int_t *PT = gd->GetPTried();
for (i=0; i<Ndt; i++) printf("%d %d %d\n",MT[i],NT[i],PT[i]);
}
```

YES it worked!

I tried similarly without the lines:

```
gd->SetMaxIter(100000); // I thought this is default
gd->SetMarginBinsContent(0);
gd->ComputeZ(0,0);
```

I got then Ndt=0.

Why it didn’t worked?

Thank you again

ComputeZ creates the triangles data structure.

Hi again,

I used TGraph2D to triangulate a peaked form (see picture). The Draw option a used was TRIW (wire frame).

I would like now to get exactly the triangles of the wire frame. How can this be done? As I was looking into the triangles of the TGraphDelaunay I found that these are not the same as those of the wire frame.

Cheers

I d not understand you points. The triangles drawn *are* the triangles of the TGraphDelaunay.

I saved the triangles as follows:

```
TTree *pT = new TTree; // data tree
pT->ReadFile(sFilename, "x/F:y:z"); // read data file
pT->Draw("x:y:z"); // get the vectors
//__________________ create the 2D Graph & triangulate
TGraph2D *pG2D = new TGraph2D("Rifi","Rifi", pT->GetEntriesFast(), pT->GetV1(), pT->GetV2(), pT->GetV3());
TGraphDelaunay *pDelGraph = new TGraphDelaunay(pG2D);
pDelGraph->SetMaxIter(nIter);
pDelGraph->SetMarginBinsContent(0);
pDelGraph->ComputeZ(0,0);
pDelGraph->FindAllTriangles();
//__________________ save the results
Int_t nNdt = pDelGraph->GetNdt();
printf("Ndt = %d\n",nNdt);
Int_t *MT = pDelGraph->GetMTried();
Int_t *NT = pDelGraph->GetNTried();
Int_t *PT = pDelGraph->GetPTried();
Point p1, p2, p3;
for (int ii=0; ii<nNdt; ii++){
pT->GetEntry(MT[ii]);
p1.X = fX;
p1.Y = fY;
p1.Z = fZ;
pT->GetEntry(NT[ii]);
p2.X = fX;
p2.Y = fY;
p2.Z = fZ;
pT->GetEntry(PT[ii]);
p3.X = fX;
p3.Y = fY;
p3.Z = fZ;
writeTriangle(p1, p2, p3);
}
```

Maybe the save part is wrong.

What is wrong for you ? the vertices values ? the way the vertices are grouped in triangles ?

Are the triangles build the way I did?

Some of them are really weird.