Redundant argument in TGraphPolar?

Hi everyone,

I have been learning ROOT following this guide and am confused with one of the arguments used in TGraphPolar in Chapter 4.2 Polar Graphs. The example code in the guide is

1 // Builds a polar graph in a square Canvas. 
3 void macro3(){
4     auto c = new TCanvas("myCanvas","myCanvas",600,600);
5     Double_t rmin=0.;
6     Double_t rmax=TMath::Pi()*6.;
7     const Int_t npoints=1000;
8     Double_t r[npoints];
9     Double_t theta[npoints];
10    for (Int_t ipt = 0; ipt < npoints; ipt++) {
11        r[ipt] = ipt*(rmax-rmin)/npoints+rmin;
12        theta[ipt] = TMath::Sin(r[ipt]);
13    }
14    TGraphPolar grP1 (npoints,r,theta);
15    grP1.SetTitle("A Fan");
16    grP1.SetLineWidth(3);
17    grP1.SetLineColor(2);
18    grP1.DrawClone("L");
19 }

The example code produces a graph of a fan with 3 flaps. What I am confused about is firstly the use of the variables. In the documentation the theta variable comes before the r variable, but in this example, the r and theta are interchanged. I assume this is just an issue with naming variables since r ∈ [0,6π) and it seems like it is meant to be a variable in radians.

The second issue is that the angle argument (r in the example) seems to be redundant. I have seen a similar issue in this post where the person asking the question changed the range to [0,π) and the graph still spans [0,2π). It seems that no matter what you put as the second argument the function still plots data points equally across the range [0,2π). Following the logic, the code should produce 3 overlapping sine curves wrapped around the origin. What should be the correct usage of TGraphPolar such that the angular argument is correctly implemented?

Thank you in advance. :slight_smile:

ROOT Version: 6.22.00

I’ll let @couet react on this once he’s back from vacation

Thanks for you input.

The primer is now here:

This PR update the example macro3.C