ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
glparametric.C
Go to the documentation of this file.
1 // Show rendering of parametric surfaces.
2 // Author: Timur Pocheptsov
4 {
5  // A parametric surface is defined by three functions:
6  // S(u, v) : {x(u, v), y(u, v), z(u, v)}.
7  // To create parametric surface and draw it one has to:
8  // 1. Create canvas, which support OpenGL drawing (two ways):
9  // a. Call gStyle->SetCanvasPreferGL(kTRUE)
10  // b. Or create canvas with name, wich contains "gl".
11  // 2. create TGLParametricEquation object.
12  // TGLParametricEquation *eq = new TGLParametricEquation("name",
13  // "some FORMULA here - x(u, v)",
14  // "some FORMULA here - y(u, v)",
15  // "some FORMULA here - z(u, v)",
16  // uMin, uMax, vMin, vMax);
17  // where FORMULA is the same string (mathematical expression),
18  // as in TF2, but you should use 'u' (or 'U') instead of 'x'
19  // and 'v' (or 'V') instead of 'y'.
20  // 3. Call equation->Draw();
21  // Parametric surfaces support 21 color "schemes", you can change
22  // the color:
23  // -place mouse cursor above surface (surface is selected in pad)
24  // -press 's' or 'S'.
26  TCanvas *c = new TCanvas("canvas","Parametric surfaces with gl", 100, 10,
27  700, 700);
28  c->SetFillColor(42);
30 
31  c->Divide(2, 2);
32  c->cd(1);
34  "1.2 ^ u * (1 + cos(v)) * cos(u)",
35  "1.2 ^ u * (1 + cos(v)) * sin(u)",
36  "1.2 ^ u * sin(v) - 1.5 * 1.2 ^ u",
37  0., 6 * TMath::Pi(), 0., TMath::TwoPi());
38  p1->Draw();
39 
40  c->cd(2);
42  "cos(u) * (4 + 3.8 * cos(v)) ",
43  "sin(u) * (4 + 3.8 * cos(v))",
44  "(cos(v) + sin(v) - 1) * (1 + sin(v)) * log(1 - pi * v / 10) + 7.5 * sin(v)",
45  0, TMath::TwoPi(), -TMath::Pi(), TMath::Pi());
46  p2->Draw();
47 
48  c->cd(3);
50  "(abs(u) - 1) ^ 2 * cos(v)",
51  "(abs(u) - 1) ^ 2 * sin(v)",
52  "u",
53  -1., 1., 0, TMath::TwoPi());
54  p3->Draw();
55 
56  c->cd(4);
57  TGLParametricEquation *p4 = new TGLParametricEquation("Trangluoid trefoil",
58  "2 * sin(3 * u) / (2 + cos(v))",
59  "2 * (sin(u) + 2 * sin(2 * u)) / (2 + cos(v + 2 * pi / 3))",
60  "(cos(u) - 2 * cos(2 * u)) * (2 + cos(v)) * (2 + cos(v + 2 * pi / 3)) / 4",
61  -TMath::Pi(), TMath::Pi(), -TMath::Pi(), TMath::Pi());
62  p4->Draw();
63 }
static double p3(double t, double a, double b, double c, double d)
return c
R__EXTERN TStyle * gStyle
Definition: TStyle.h:423
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:254
void glparametric()
Definition: glparametric.C:3
void SetFrameFillColor(Color_t color=1)
Definition: TStyle.h:367
static double p2(double t, double a, double b, double c)
Double_t TwoPi()
Definition: TMath.h:45
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition: TStyle.h:337
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
static double p1(double t, double a, double b)
A parametric surface is a surface defined by a parametric equation, involving two parameters (u...
Definition: TGLParametric.h:43
Double_t Pi()
Definition: TMath.h:44
The Canvas class.
Definition: TCanvas.h:48
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1073
const Bool_t kTRUE
Definition: Rtypes.h:91