-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClusterCreator.C
More file actions
71 lines (46 loc) · 1.21 KB
/
ClusterCreator.C
File metadata and controls
71 lines (46 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <time.h>
#include <math.h>
using namespace std;
int main(){
ofstream out;
out.open("Cluster.dat");
srand(7834);
cout<<"2D cluster generator"<<endl;
double x = 0;
double y = 0;
//Background field
for (int i = 0 ; i < 1000; i++){
x = (rand() % 10000)/10.;
y = (rand() % 10000)/10.;
out<<x<<" "<<y<<endl;
cout<<"x: "<<x<<"y: "<<y<<endl;
}
for (int i = 0 ; i < 60 ; i++ ){
double xc = (rand() % 10000)/10.;
double yc = (rand() % 10000)/10.;
double r = (rand() %1000)/20. + 5;
int Pop = (rand() % 100 + 10);
cout<<" Cluster :"<<i <<"Position : "<< xc <<" "<<yc<<endl;
cout<<" Population: "<<Pop<<"radius :"<<r <<endl;
int j = 0;
while( j < Pop){
double r1 = (rand() % 100 )/100.*2*r;
double r2 = (rand() % 100 )/100.*2*r;
double x1 = xc -r + r1;
double y1 = yc -r + r2;
if( sqrt((r-r1)*(r-r1) + (r-r2)*(r-r2)) < r){
if(( x1 > 0)&&(x1 < 1000)){
if(( y1 > 0)&&(y1 < 1000)){
out<<x1<<" "<<y1<<endl;
}
}
j = j +1;
}
//cout<<" stars"<<j<<endl;
}
}
return 0;
}