Dear all,
I’ve been trying to draw some small animations using TGraph and TGraph2D. My aim is to draw particle trajectories on a TCanvas that keeps updating and lets the user see the motion as it happens. I’m using ROOT version 5.34/12 (now compiled with debug symbols, since I’ve tried to look deeper into the matter).
As far as TGraph is concerned, everything works fine. For example, this snippet of code draws the trajectory of a particle going around in a circle:
[code]//WORKING CODE
{
TCanvas *c = new TCanvas;
TGraph *g = new TGraph;
const Double_t pi = TMath::Pi();
for(Int_t i=0; i<100; ++i) {
g->SetPoint(i,cos(pi/50*i),sin(pi/50*i));
g->Draw("ALINE");
c->Modified();
c->Update();
}
}
//END OF WORKING CODE[/code]
My problem is, when I try to do the exact same thing with a TGraph2D (which a naive user would think to behave in the same way), I get a very weird behaviour and in the end at most two points are drawn on canvas. This is a macro that is supposed to draw a spiral:
[code]//BROKEN CODE
{
TCanvas *c = new TCanvas;
TGraph2D *g = new TGraph2D;
Double_t pi = TMath::Pi();
/*add the first two points to set the scale beforehand
(I'm aware there are better ways to do it)*/
g->SetPoint(0,-1,-1,0);
g->SetPoint(1,1,1,180);
for(Int_t i=0; i<200; ++i) {
g->SetPoint(i+2,cos(pi/50*i),sin(pi/50*i),i);
g->Draw("ALINE");
c->Modified();
c->Update();
}
/* everything works fine if I move Draw(), Modified() and
Update() down here, out of the loop, but then I wouldn't get to "see" the motion */
}
//END OF BROKEN CODE[/code]
Any help is greatly appreciated, thanks in advance.