本文整理汇总了C++中TRandom::Sphere方法的典型用法代码示例。如果您正苦于以下问题:C++ TRandom::Sphere方法的具体用法?C++ TRandom::Sphere怎么用?C++ TRandom::Sphere使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TRandom
的用法示例。
在下文中一共展示了TRandom::Sphere方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: spheres
void spheres(Int_t nspheres=20, Int_t npoints=100000) {
// generate random points uniformly distributed over the surface
// of spheres generated at random positions.
TCanvas *c1 = new TCanvas("c1","spheres",600,600);
c1->SetFillColor(kBlack);
TView *view = new TView(1);
Double_t k=0.8;
view->SetRange( -k, -k, -k, k, k, k);
//generate sphere coordinates and radius
TRandom r;
if (nspheres <=0) nspheres = 10;
Double_t *xs = new Double_t[nspheres];
Double_t *ys = new Double_t[nspheres];
Double_t *zs = new Double_t[nspheres];
Double_t *rs = new Double_t[nspheres];
Int_t i;
for (i=0;i<nspheres;i++) {
xs[i] = r.Uniform(-1,1);
ys[i] = r.Uniform(-1,1);
zs[i] = r.Uniform(-1,1);
rs[i] = r.Uniform(0.05,0.25);
}
//generate points
TPolyMarker3D *pm = new TPolyMarker3D(npoints);
pm->SetMarkerColor(kRed);
Double_t x,y,z;
for (Int_t j=0;j<npoints;j++) {
i = (Int_t)r.Uniform(0,nspheres); //choose sphere
r.Sphere(x,y,z,rs[i]);
pm->SetPoint(j,xs[i]+x, ys[i]+y,zs[i]+z);
}
delete [] xs;
delete [] ys;
delete [] zs;
delete [] rs;
pm->Draw();
}