Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
33void 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",
72 p4->Draw();
73}
#define c(i)
Definition RSha256.hxx:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
R__EXTERN TStyle * gStyle
Definition TStyle.h:433
The Canvas class.
Definition TCanvas.h:23
A parametric surface is a surface defined by a parametric equation, involving two parameters (u,...
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:274
void SetFrameFillColor(Color_t color=1)
Definition TStyle.h:369
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition TStyle.h:339
constexpr Double_t Pi()
Definition TMath.h:37
constexpr Double_t TwoPi()
Definition TMath.h:44