8 return RandSquare(PointNum, lowerleft.
x, upperright.
x, lowerleft.
y, upperright.
y);
18 base_generator_type generator;
19 boost::random::uniform_real_distribution<> dist;
20 while (counter < PointNum)
22 ran[0] = dist(generator);
23 ran[1] = dist(generator);
24 point.
x = ((Rmax - Rmin)*ran[0] + Rmin)*cos(ran[1] * 2 * M_PI) + xc;
25 point.
y = ((Rmax - Rmin)*ran[0] + Rmin)*sin(ran[1] * 2 * M_PI) + yc;
32 vector<Vector2D>
RandSquare(
int PointNum,
double xl,
double xr,
double yd,
40 base_generator_type generator;
41 boost::random::uniform_real_distribution<> dist;
42 for (
int i = 0; i < PointNum; ++i)
44 ran[0] = dist(generator);
45 ran[1] = dist(generator);
46 point.
x = ran[0] * xc + xl;
47 point.
y = ran[1] * yc + yd;
53 vector<Vector2D>
RandSquare(
int PointNum, boost::random::mt19937 &eng,
double xl,
double xr,
double yd,
61 boost::random::uniform_real_distribution<> dist;
62 for (
int i = 0; i < PointNum; ++i)
66 point.
x = ran[0] * xc + xl;
67 point.
y = ran[1] * yc + yd;
73 vector<Vector2D>
RandPointsRa(
int PointNum,
double Rmin,
double Rmax,
double alpha,
76 base_generator_type generator;
77 boost::random::uniform_real_distribution<> dist;
79 double A = pow(Rmax*Rmin, alpha)*(alpha - 1) / (pow(Rmax, alpha)*Rmin - Rmax*pow(Rmin, alpha));
83 res.reserve(static_cast<size_t>(PointNum));
84 while (counter < PointNum)
86 ran[0] = pow(pow(Rmin, 1 - alpha) - dist(generator)*(alpha - 1) / A, 1.0 / (1 - alpha));
87 ran[1] = dist(generator);
88 point.
x = ran[0] * cos(ran[1] * 2 * M_PI) + center.
x;
89 point.
y = ran[0] * sin(ran[1] * 2 * M_PI) + center.
y;
90 if ((point.
x<upperright.
x) && (point.
x>lowerleft.
x) && (point.
y < upperright.
y)
91 && (point.
y > lowerleft.
y))
100 vector<Vector2D>
RandPointsR(
int PointNum,
double xl,
double xr,
double yd,
101 double yu,
double minR,
double xc,
double yc)
105 double maxR = sqrt(2.0)*
max(
max(
max(xr - xc, yu - yc), yc - yd), xc - xl);
106 vector<Vector2D> res;
108 base_generator_type generator;
109 boost::random::uniform_real_distribution<> dist;
110 while (counter < PointNum)
112 ran[0] = dist(generator);
113 ran[1] = dist(generator);
114 point.
x = maxR*ran[0] * cos(ran[1] * 2 * M_PI) + xc;
115 point.
y = maxR*ran[0] * sin(ran[1] * 2 * M_PI) + yc;
116 if (
abs(point) > minR)
118 if (point.
x > xl&&point.
x<xr)
119 if (point.
y>yd&&point.
y < yu)
121 res.push_back(point);
130 double xc,
double yc,
double xmax,
double ymax,
double xmin,
double ymin)
132 const double Nphid = sqrt(PointNum * 2 * M_PI / log(Rmax / Rmin));
133 const int Nr =
static_cast<int>(Nphid*log(Rmax / Rmin) / (2 * M_PI));
134 const int Nphi =
static_cast<int>(floor(Nphid + 0.5));
135 const double dphi = 2 * M_PI / Nphi;
136 vector<Vector2D> res;
137 for (
int i = 0; i < Nr; ++i)
139 const double r = Rmin*exp(2 * M_PI*i / Nphi);
140 for (
int j = 0; j < Nphi; ++j)
142 const Vector2D pos(r*cos(dphi*j) + xc, r*sin(dphi*j) + yc);
143 if (pos.
x<xmax&&pos.
x>xmin && pos.
y<ymax&&pos.
y>ymin)
151 double xc,
double yc,
double xmax,
double ymax,
double xmin,
double ymin)
153 const double x = sqrt(Rmin / Rmax);
154 const int Nr = int(sqrt(2 * PointNum*(1 - x) / (1 + x) / M_PI));
155 const double A = 4 * pow(1 / sqrt(Rmin) - 1 / sqrt(Rmax), 2) / (Nr*Nr);
156 vector<Vector2D> res;
157 for (
int i = 0; i < Nr; ++i)
159 const double r = 4 * Rmin / pow(2 - sqrt(A*Rmin)*i, 2);
160 const double Nphi = int(2 * M_PI / sqrt(A*r));
161 const double dphi = double(2 * M_PI / Nphi);
162 for (
int j = 0; j < Nphi; ++j)
164 const Vector2D pos(r*cos(dphi*j) + xc, r*sin(dphi*j) + yc);
165 if (pos.
x<xmax&&pos.
x>xmin && pos.
y<ymax&&pos.
y>ymin)
173 double xmax,
double ymax,
double xmin,
double ymin,
double xc,
double yc)
175 const double A = sqrt(M_PI*(Rmax*Rmax - Rmin*Rmin) / PointNum);
176 const int Nr = int((Rmax - Rmin) / A);
177 const double dr = (Rmax - Rmin) / Nr;
178 vector<Vector2D> res;
179 for (
int i = 0; i < Nr; ++i)
181 const double r = Rmin + i*dr;
182 const int Nphi = int(2 * M_PI*r / A);
183 const double dphi = A / r;
184 for (
int j = 0; j < Nphi; ++j)
186 const Vector2D pos(r*cos(dphi*j) + xc, r*sin(dphi*j) + yc);
187 if (pos.
x<xmax&&pos.
x>xmin && pos.
y<ymax&&pos.
y>ymin)
200 assert(upper_right.
x > lower_left.
x);
201 assert(upper_right.
y > lower_left.
y);
203 vector<Vector2D> res;
204 const double dx = (upper_right.
x - lower_left.
x) /
205 static_cast<double>(nx);
206 const double dy = (upper_right.
y - lower_left.
y) /
207 static_cast<double>(ny);
208 for (
double x = lower_left.
x + 0.5*dx; x < upper_right.
x; x += dx){
209 for (
double y = lower_left.
y + 0.5*dy; y < upper_right.
y; y += dy)
216 (
size_t point_number,
218 Vector2D const& center,
double angle_start,
double angle_end)
220 vector<Vector2D> res(point_number);
221 for (
size_t i = 0; i < point_number; ++i)
223 const double angle = (angle_end - angle_start) *
double(i) / double(point_number) + angle_start;
224 res[i] = center +
pol2cart(radius, angle);
229 vector<Vector2D>
Line(
int PointNum,
double xmin,
double xmax,
double ymin,
double ymax)
231 double dy = ymax - ymin, dx = xmax - xmin;
232 double angle = atan2(dy, dx);
233 double length = sqrt(dy*dy + dx*dx);
234 double dl = length / PointNum;
236 vector<Vector2D> res;
239 for (
int i = 0; i < PointNum; ++i)
241 temp.
Set(xmin + dl*(i + 0.5)*cos(angle), ymin + dl*(i + 0.5)*sin(angle));
256 double alpha,
double angle_start,
double angle_end)
258 const double N0 = sqrt(PointNum * 4 * M_PI*(alpha + 1) /
259 (pow(Rmax, 2 * (alpha + 1)) -
260 pow(Rmin, 2 * (alpha + 1))));
261 const int Nr = int(floor((pow(Rmax, alpha + 1) -
262 pow(Rmin, alpha + 1))*N0 / (2 * M_PI*(alpha + 1))));
263 vector<Vector2D> res;
264 for (
int i = 0; i < Nr; ++i)
266 const double r = pow(2 * M_PI*i*(alpha + 1) / N0 +
267 pow(Rmin, alpha + 1), 1.0 / (alpha + 1));
268 const int Nphi = int(floor(N0*pow(r, 1 + alpha) + 1.5));
269 const double dphi = 2 * M_PI / Nphi;
270 double cur_phi = angle_start;
271 while(cur_phi < angle_end)
273 const Vector2D pos(r*cos(cur_phi) + xc, r*sin(cur_phi) + yc);
274 if (pos.
x<xmax&&pos.
x>xmin && pos.
y<ymax&&pos.
y>ymin)
std::vector< Vector2D > Line(int PointNum, double xmin, double xmax, double ymin, double ymax)
Creates a line of evenly spaced points y=slope*x+b.
std::vector< Vector2D > CirclePointsRmax_2(int PointNum, double Rmin, double Rmax, double xc=0, double yc=0, double xmax=1, double ymax=1, double xmin=-1, double ymin=1)
Generates a round grid with 1/r^2 point density confined to a rectangle given by xmin,xmax,ymin and ymax.
boost::mt19937_64 base_generator_type
Alias for random number generator.
std::vector< Vector2D > circle_circumference(size_t point_number, double radius, Vector2D const ¢er, double angle_start=0, double angle_end=2 *M_PI)
Creates a circle of evenly spaced points.
std::vector< Vector2D > CirclePointsRmax_1(int PointNum, double Rmin, double Rmax, double xc=0, double yc=0, double xmax=1, double ymax=1, double xmin=-1, double ymin=-1)
Generates a round grid with 1/r point density confined to a rectangle given by xmin,xmax,ymin and ymax.
std::vector< Vector2D > RandPointsR(int PointNum, double xl=-0.5, double xr=0.5, double yd=-0.5, double yu=0.5, double minR=0, double xc=0, double yc=0)
Generates a rectangular grid with random 1/r point density.
double max(vector< double > const &v)
returns the maximal term in a vector
double y
Component in the y direction.
Vector2D pol2cart(double radius, double angle)
Converts from polar coordinates to cartesian coordinates.
Set of functions to generate points.
std::vector< Vector2D > CirclePointsRmax_a(int PointNum, double Rmin, double Rmax, double xc, double yc, double xmax, double ymax, double xmin, double ymin, double alpha, double angle_start=0, double angle_end=2 *M_PI)
Generates a round grid with r^alpha point density confined to a rectangle given by xmin...
void Set(double ix, double iy)
Set vector components.
std::vector< Vector2D > RandPointsRa(int PointNum, double Rmin, double Rmax, double alpha, Vector2D const &lowerleft, Vector2D const &upperright, Vector2D const ¢er=Vector2D(0, 0))
Generates a random round grid with r^(1-a) point density.
std::vector< Vector2D > cartesian_mesh(int nx, int ny, Vector2D const &lower_left, Vector2D const &upper_right)
Generates a cartesian mesh.
std::vector< Vector2D > RandSquare(int PointNum, Vector2D const &lowerleft, Vector2D const &upperright)
Generates a random rectangular grid with uniform point density and a constant seed.
double abs(Vector3D const &v)
Norm of a vector.
std::vector< Vector2D > RandPointsRmax(int PointNum, double Rmin, double Rmax, double xc=0, double yc=0)
Generates a random round grid with 1/r point density.
std::vector< Vector2D > CirclePointsRmax(int PointNum, double Rmin, double Rmax, double xmax, double ymax, double xmin, double ymin, double xc=0, double yc=0)
Generates a round grid with constant point density.
double x
Component in the x direction.