glparametric.C

Go to the documentation of this file.
00001 // Show rendering of parametric surfaces.
00002 // Author: Timur Pocheptsov
00003 void glparametric()
00004 {
00005    // A parametric surface is defined by three functions:
00006    // S(u, v) : {x(u, v), y(u, v), z(u, v)}.
00007    // To create parametric surface and draw it one has to:
00008    //  1. Create canvas, which support OpenGL drawing (two ways):
00009    //     a. Call gStyle->SetCanvasPreferGL(kTRUE)
00010    //     b. Or create canvas with name, wich contains "gl".
00011    //  2. create TGLParametricEquation object.
00012    //     TGLParametricEquation *eq = new TGLParametricEquation("name",
00013    //     "some FORMULA here - x(u, v)",
00014    //     "some FORMULA here - y(u, v)",
00015    //     "some FORMULA here - z(u, v)",
00016    //     uMin, uMax, vMin, vMax);
00017    //     where FORMULA is the same string (mathematical expression),
00018    //     as in TF2, but you should use 'u' (or 'U') instead of 'x'
00019    //     and 'v' (or 'V') instead of 'y'.
00020    //  3. Call equation->Draw();
00021    //     Parametric surfaces support 21 color "schemes", you can change
00022    //     the color:
00023    //     -place mouse cursor above surface (surface is selected in pad)
00024    //     -press 's' or 'S'.
00025    gStyle->SetCanvasPreferGL(kTRUE);
00026    TCanvas *c = new TCanvas("canvas","Parametric surfaces with gl", 100, 10,
00027                             700, 700);
00028    c->SetFillColor(42);
00029    gStyle->SetFrameFillColor(42);
00030 
00031    c->Divide(2, 2);
00032    c->cd(1);
00033    TGLParametricEquation *p1 = new TGLParametricEquation("Conchoid",
00034                                 "1.2 ^ u * (1 + cos(v)) * cos(u)",
00035                                 "1.2 ^ u * (1 + cos(v)) * sin(u)",
00036                                 "1.2 ^ u * sin(v) - 1.5 * 1.2 ^ u",
00037                                 0., 6 * TMath::Pi(), 0., TMath::TwoPi());
00038    p1->Draw();
00039 
00040    c->cd(2);
00041    TGLParametricEquation *p2 = new TGLParametricEquation("Apple",
00042         "cos(u) * (4 + 3.8 * cos(v)) ",
00043         "sin(u) * (4 + 3.8 * cos(v))",
00044         "(cos(v) + sin(v) - 1) * (1 + sin(v)) * log(1 - pi * v / 10) + 7.5 * sin(v)",
00045         0, TMath::TwoPi(), -TMath::Pi(), TMath::Pi());
00046    p2->Draw();
00047 
00048    c->cd(3);
00049    TGLParametricEquation *p3 = new TGLParametricEquation("Toupie",
00050                                         "(abs(u) - 1) ^ 2 * cos(v)",
00051                                         "(abs(u) - 1) ^ 2 * sin(v)",
00052                                         "u",
00053                                         -1., 1., 0, TMath::TwoPi());
00054    p3->Draw();
00055 
00056    c->cd(4);
00057    TGLParametricEquation *p4 = new TGLParametricEquation("Trangluoid trefoil",
00058         "2 * sin(3 * u) / (2 + cos(v))",
00059         "2 * (sin(u) + 2 * sin(2 * u)) / (2 + cos(v + 2 * pi / 3))",
00060         "(cos(u) - 2 * cos(2 * u)) * (2 + cos(v)) * (2 + cos(v + 2 * pi / 3)) / 4",
00061                         -TMath::Pi(), TMath::Pi(), -TMath::Pi(), TMath::Pi());
00062    p4->Draw();
00063 }

Generated on Tue Jul 5 15:44:17 2011 for ROOT_528-00b_version by  doxygen 1.5.1