リソース生成
1650 ワード
package com.jleo.pickitup;
public class Norm{
public static double normrnd(double mu, double sigma) {
double N = 12;
double x = 0, temp = N;
do {
x = 0;
for (int i = 0; i < N; i++)
x = x + (Math.random());
x = (x - temp / 2) / (Math.sqrt(temp / 12));
x = mu + x * Math.sqrt(sigma);
} while (x <= 0);
return x;
}
public static double[] addInv(double[] r) {
double[] result = new double[r.length * 2];
for (int i = 0; i < result.length; i += 2) {
result[i] = r[i / 2];
result[i + 1] = -r[i / 2];
}
return result;
}
public static double[] normrnd(double sigma, int num) {
double[] r = new double[num];
for (int i = 0; i < num; i++) {
r[i] = normrnd(0, sigma);
}
return addInv(r);
}
public static Point[] generateMap(int x1, int x2, int y1, int y2) {
int numberOfDots = 5000;
double mu = 3;
double sigma = 1;
int[] x = new int[numberOfDots];
int[] y = new int[numberOfDots];
Point[] points = new Point[numberOfDots];
for (int i = 0; i < numberOfDots; i++) {
x[i] = (int) ((normrnd(mu, sigma)-3)*((x2-x1)/6)+(x1+x2)/2);
y[i] = (int) ((normrnd(mu, sigma)-3)*((y2-y1)/6)+(y1+y2)/2);
points[i] = new Point(x[i], y[i]);
}
return points;
}
public static void main(String[] args) {
Norm.generateMap(31095278,31334871,121256104,121629639);
}
}