Re: [ROOT] Filling in an area

From: Rene Brun (Rene.Brun@cern.ch)
Date: Wed Aug 14 2002 - 22:28:49 MEST


Hi Ray,

May be you will get some inspiration from the following example:

Rene Brun

void ray() {
   TCanvas *c1 = new TCanvas("c1");
   TF1 *f1 = new TF1("f1","0.7*x*x*x+x*x",0,4);
   f1->Draw();
   TF1 *f2 = new TF1("f2","x*x*x-x*x",0,4);
   f2->Draw("lsame");
   c1->Update();
   const Int_t np = 10, npf = 20;
   
   //first fill area below a sub-range of f2
   Double_t x[np+3], y[np+3];
   Double_t xmin = 2; Double_t xmax = 3;
   Double_t dx = (xmax-xmin)/(np-1);
   for (Int_t i=0;i<np;i++) {
      x[i] = xmin + dx*i;
      y[i] = f2->Eval(x[i]);
   }
   x[np]   = x[np-1]; y[np]   = c1->GetUymin();
   x[np+1] = x[0];    y[np+1] = y[np];
   x[np+2] = x[0];    y[np+2] = y[0];
   TGraph *gr = new TGraph(np+3,x,y);
   gr->SetFillStyle(3008);
   gr->SetFillColor(2);
   gr->Draw("lf");
   
   //second fill area between f1 and f2
   Double_t xf[2*npf+1], yf[2*npf+1];
   Double_t xfmin = 1.5; Double_t xfmax = 3.5;
   Double_t dxf = (xfmax-xfmin)/(npf-1);
   for (Int_t i=0;i<npf;i++) {
      xf[i] = xfmin + dxf*i;
      yf[i] = f2->Eval(xf[i]);
      xf[npf+i] = xfmax - dxf*i;
      yf[npf+i] = f1->Eval(xf[npf+i]);
   }
   xf[2*npf] = xf[0]; yf[2*npf] = yf[0];
   TGraph *grf = new TGraph(2*npf+1,xf,yf);
   grf->SetFillStyle(3024);
   grf->SetFillColor(4);
   grf->Draw("lf");
}

On Wed, 14 Aug 2002, Ray Fliller III wrote:

> 
>   Hello Rooters,
> 
>     I have two TF1's.  lets call them f1 and f2.  I want to draw them
>   both on the same canvas, and fill in the area between them.  It draw
>   them on the same canvas is easy, but how do I fill in the area between
>   them??
> 
>     Even more generally, I have some enclosed area on a TPad, how would I
> fill in this area?  For example to show integral(x^3-x^2,x=2..3) 
> graphically.
> 
> 
> -- 
> 
>  RAINMAN
>       "How much does a piece of gum cost Ray?"
>       "About $100."
>       "How much does a new car cost Ray?"
>       "`Bout $100."
>       "There goes working for NASA!"
> 
> ==================================================================
> Ray Fliller: rfliller@bnl.gov      Office Phone: (631)-344-6124 
> C-A Accelerator Physics            Dept. Fax: (631)-344-5954
> Building 911B
> Brookhaven National Lab
> Upton, NY 11973                    Office: Room 211
> 
> http://www.agsrhichome.bnl.gov/People/rfliller/
> ==================================================================
> 



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:04 MET