Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
inside.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphics
3/// \notebook -js
4/// \preview Test the IsInside methods of various graphics primitives.
5///
6/// \macro_image
7/// \macro_code
8///
9/// \author Olivier Couet
10
11void inside()
12{
13 auto el = new TEllipse(0.75, 0.25, .2, .15, 45, 315, 62);
14 el->Draw();
15
16 auto gr = new TGraph();
17 double gr_x1[5] = {0.1, 0.3388252, 0.03796561, 0.4176218, 0.1};
18 double gr_y1[5] = {0.5, 0.9644737, 0.7776316, 0.6960526, 0.5};
19 gr = new TGraph(5, gr_x1, gr_y1);
20 gr->Draw("L");
21
22 auto bx = new TBox(.7, .8, .9, .95);
23 bx->Draw();
24
25 auto pv = new TPave(.05, .1, .3, .2);
26 pv->Draw();
27
28 auto di = new TDiamond(.05, .25, .3, .4);
29 di->Draw();
30
31 auto cr = new TCrown(.5, .5, .1, .15);
32 cr->SetFillColor(19);
33 cr->Draw();
34
35 for (int i = 0; i < 10000; i++) {
36 double x = gRandom->Rndm();
37 double y = gRandom->Rndm();
38 auto p = new TMarker(x, y, 7);
39 p->Draw();
40 if (el->IsInside(x, y) || bx->IsInside(x, y) || pv->IsInside(x, y) || di->IsInside(x, y) || cr->IsInside(x, y) ||
41 gr->IsInside(x, y)) {
42 p->SetMarkerColor(kGreen);
43 } else {
44 p->SetMarkerColor(kRed);
45 }
46 }
47}
@ kRed
Definition Rtypes.h:66
@ kGreen
Definition Rtypes.h:66
winID h TVirtualViewer3D TVirtualGLPainter p
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
Create a Box.
Definition TBox.h:22
To draw a Crown.
Definition TCrown.h:19
Draw a Diamond.
Definition TDiamond.h:17
Draw Ellipses.
Definition TEllipse.h:23
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
virtual Int_t IsInside(Double_t x, Double_t y) const
Return 1 if the point (x,y) is inside the polygon defined by the graph vertices 0 otherwise.
Definition TGraph.cxx:1843
void Draw(Option_t *chopt="") override
Draw this graph with its current attributes.
Definition TGraph.cxx:833
Manages Markers.
Definition TMarker.h:22
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:292
A TBox with a bordersize and a shadow option.
Definition TPave.h:19
Double_t Rndm() override
Machine independent random number generator.
Definition TRandom.cxx:559
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
TGraphErrors * gr
Definition legend1.C:25