Logo ROOT   6.07/09
Reference Guide
glparametric.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_gl
3 /// Show rendering of parametric surfaces.
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 /// - Call gStyle->SetCanvasPreferGL(kTRUE)
10 /// - Or create canvas with name, wich contains "gl".
11 /// 2. create TGLParametricEquation object.
12 /// ~~~{.cpp}
13 /// TGLParametricEquation *eq = new TGLParametricEquation("name",
14 /// "some FORMULA here - x(u, v)",
15 /// "some FORMULA here - y(u, v)",
16 /// "some FORMULA here - z(u, v)",
17 /// uMin, uMax, vMin, vMax);
18 /// ~~~
19 /// where FORMULA is the same string (mathematical expression),
20 /// as in TF2, but you should use 'u' (or 'U') instead of 'x'
21 /// and 'v' (or 'V') instead of 'y'.
22 /// 3. Call equation->Draw();
23 /// Parametric surfaces support 21 color "schemes", you can change
24 /// the color:
25 /// - place mouse cursor above surface (surface is selected in pad)
26 /// - press 's' or 'S'.
27 ///
28 /// \macro_image(nobatch)
29 /// \macro_code
30 ///
31 /// \author Timur Pocheptsov
32 
33 void glparametric()
34 {
36  TCanvas *c = new TCanvas("canvas","Parametric surfaces with gl", 100, 10,
37  700, 700);
38  c->SetFillColor(42);
40 
41  c->Divide(2, 2);
42  c->cd(1);
44  "1.2 ^ u * (1 + cos(v)) * cos(u)",
45  "1.2 ^ u * (1 + cos(v)) * sin(u)",
46  "1.2 ^ u * sin(v) - 1.5 * 1.2 ^ u",
47  0., 6 * TMath::Pi(), 0., TMath::TwoPi());
48  p1->Draw();
49 
50  c->cd(2);
52  "cos(u) * (4 + 3.8 * cos(v)) ",
53  "sin(u) * (4 + 3.8 * cos(v))",
54  "(cos(v) + sin(v) - 1) * (1 + sin(v)) * log(1 - pi * v / 10) + 7.5 * sin(v)",
55  0, TMath::TwoPi(), -TMath::Pi(), TMath::Pi());
56  p2->Draw();
57 
58  c->cd(3);
60  "(abs(u) - 1) ^ 2 * cos(v)",
61  "(abs(u) - 1) ^ 2 * sin(v)",
62  "u",
63  -1., 1., 0, TMath::TwoPi());
64  p3->Draw();
65 
66  c->cd(4);
67  TGLParametricEquation *p4 = new TGLParametricEquation("Trangluoid trefoil",
68  "2 * sin(3 * u) / (2 + cos(v))",
69  "2 * (sin(u) + 2 * sin(2 * u)) / (2 + cos(v + 2 * pi / 3))",
70  "(cos(u) - 2 * cos(2 * u)) * (2 + cos(v)) * (2 + cos(v + 2 * pi / 3)) / 4",
71  -TMath::Pi(), TMath::Pi(), -TMath::Pi(), TMath::Pi());
72  p4->Draw();
73 }
static double p3(double t, double a, double b, double c, double d)
return c
R__EXTERN TStyle * gStyle
Definition: TStyle.h:418
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:255
void SetFrameFillColor(Color_t color=1)
Definition: TStyle.h:362
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:332
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:42
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:35
Double_t Pi()
Definition: TMath.h:44
The Canvas class.
Definition: TCanvas.h:41
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:1089
const Bool_t kTRUE
Definition: Rtypes.h:91