ROOT
master
Reference Guide
glparametrics2.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
klein_bottle(
TGLVertex3
&dst,
Double_t
u,
Double_t
v
)
34
{
35
using namespace
TMath
;
36
37
const
Double_t
r
= 4. * (1. -
Cos
(u) / 2.);
38
if
(u <
Pi
()) {
39
dst.
X
() = 6 *
Cos
(u) * (1. +
Sin
(u)) +
r
*
Cos
(u) *
Cos
(
v
);
40
dst.
Y
() = 16 *
Sin
(u) +
r
*
Sin
(u) *
Cos
(
v
);
41
}
else
{
42
dst.
X
() = 6 *
Cos
(u) * (1. +
Sin
(u)) +
r
*
Cos
(
v
+
Pi
());
43
dst.
Y
() = 16 *
Sin
(u);
44
}
45
dst.
Z
() =
r
*
Sin
(
v
);
46
}
47
48
void
glparametrics2()
49
{
50
gStyle
->
SetCanvasPreferGL
(
kTRUE
);
51
TCanvas
*
c
=
new
TCanvas
(
"canvas"
,
"Parametric surfaces with gl"
, 100, 10, 700, 700);
52
53
c
->Divide(2, 2);
54
c
->cd(1);
55
TGLParametricEquation
*p1 =
new
TGLParametricEquation
(
"Shell"
,
56
"1.2 ^ v * sin(u) ^ 2 * sin(v)"
,
57
"1.2 ^ v * sin(u) * cos(u)"
,
58
"1.2 ^ v * sin(u) ^ 2 * cos(v)"
,
59
0.,
TMath::Pi
(),
// 0 <= u <= pi
60
-
TMath::Pi
() / 4., 5 *
TMath::Pi
() / 2.);
// -pi/4 <= v <= 5*pi/2
61
p1->
Draw
(
""
);
62
63
c
->cd(2);
64
TGLParametricEquation
*p2 =
new
TGLParametricEquation
(
"Limpet torus"
,
65
"cos(u) / (sqrt(2) + sin(v))"
,
66
"sin(u) / (sqrt(2) + sin(v))"
,
67
"1. / (sqrt(2) + cos(v))"
,
68
-
TMath::Pi
(),
TMath::Pi
(),
69
-
TMath::Pi
(),
TMath::Pi
());
70
p2->
Draw
();
71
72
c
->cd(3);
73
TGLParametricEquation
*p3 =
new
TGLParametricEquation
(
"Klein bottle"
,
74
klein_bottle,
75
0.,
TMath::TwoPi
(),
76
0.,
TMath::TwoPi
());
77
p3->
Draw
();
78
79
c
->cd(4);
80
TGLParametricEquation
*p4 =
new
TGLParametricEquation
(
"Helicoid"
,
81
"v * cos(u)"
,
82
"v * sin(u)"
,
83
"u"
,
84
-3., 3.,
85
-3., 3.);
86
p4->
Draw
();
87
}
c
#define c(i)
Definition:
RSha256.hxx:101
TStyle::SetCanvasPreferGL
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition:
TStyle.h:325
TGLVertex3::Y
Double_t Y() const
Definition:
TGLUtil.h:121
kTRUE
const Bool_t kTRUE
Definition:
RtypesCore.h:91
TMath::Cos
Double_t Cos(Double_t)
Definition:
TMath.h:643
r
ROOT::R::TRInterface & r
Definition:
Object.C:4
TGLVertex3::X
Double_t X() const
Definition:
TGLUtil.h:119
v
@ v
Definition:
rootcling_impl.cxx:3635
TMath::Pi
constexpr Double_t Pi()
Definition:
TMath.h:37
TGLParametricEquation
A parametric surface is a surface defined by a parametric equation, involving two parameters (u,...
Definition:
TGLParametric.h:35
gStyle
R__EXTERN TStyle * gStyle
Definition:
TStyle.h:412
TGLVertex3::Z
Double_t Z() const
Definition:
TGLUtil.h:123
TMath::Sin
Double_t Sin(Double_t)
Definition:
TMath.h:639
TMath::TwoPi
constexpr Double_t TwoPi()
Definition:
TMath.h:44
TObject::Draw
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition:
TObject.cxx:197
Double_t
double Double_t
Definition:
RtypesCore.h:59
TCanvas
The Canvas class.
Definition:
TCanvas.h:23
TGLVertex3
3 component (x/y/z) vertex class.
Definition:
TGLUtil.h:84
TMath
TMath.
Definition:
TMathBase.h:35
tutorials
gl
glparametrics2.C
ROOT master - Reference Guide Generated on Tue Jan 26 2021 11:59:14 (GVA Time) using Doxygen 1.9.0