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, 700, 700);
37 c->SetFillColor(42);
39
40 c->Divide(2, 2);
41 c->cd(1);
43 new TGLParametricEquation("Conchoid", "1.2 ^ u * (1 + cos(v)) * cos(u)", "1.2 ^ u * (1 + cos(v)) * sin(u)",
44 "1.2 ^ u * sin(v) - 1.5 * 1.2 ^ u", 0., 6 * TMath::Pi(), 0., TMath::TwoPi());
45 p1->Draw();
46
47 c->cd(2);
49 new TGLParametricEquation("Apple", "cos(u) * (4 + 3.8 * cos(v)) ", "sin(u) * (4 + 3.8 * cos(v))",
50 "(cos(v) + sin(v) - 1) * (1 + sin(v)) * log(1 - pi * v / 10) + 7.5 * sin(v)", 0,
52 p2->Draw();
53
54 c->cd(3);
55 TGLParametricEquation *p3 = new TGLParametricEquation("Toupie", "(abs(u) - 1) ^ 2 * cos(v)",
56 "(abs(u) - 1) ^ 2 * sin(v)", "u", -1., 1., 0, TMath::TwoPi());
57 p3->Draw();
58
59 c->cd(4);
61 new TGLParametricEquation("Trangluoid trefoil", "2 * sin(3 * u) / (2 + cos(v))",
62 "2 * (sin(u) + 2 * sin(2 * u)) / (2 + cos(v + 2 * pi / 3))",
63 "(cos(u) - 2 * cos(2 * u)) * (2 + cos(v)) * (2 + cos(v + 2 * pi / 3)) / 4",
65 p4->Draw();
66}
#define c(i)
Definition RSha256.hxx:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
R__EXTERN TStyle * gStyle
Definition TStyle.h:436
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:292
void SetFrameFillColor(Color_t color=1)
Definition TStyle.h:372
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition TStyle.h:341
constexpr Double_t Pi()
Definition TMath.h:37
constexpr Double_t TwoPi()
Definition TMath.h:44