はじめに
Processingには正規分布に基づいた乱数生成関数randomGaussian()がある。しかし、曲線をパッと作る機能はなかったので、とりあえず用意した。
Processing
size(1000, 600);
noFill();
float sig = 1;
float u = 0;
translate(500, 500);
scale(100);
strokeWeight(0.01);
beginShape();
for (float x = -5; x < 5; x+=0.01) {
float f = 1f/sqrt(2f*PI)/sig*exp(-(x-u)*(x-u)/2f/sig/sig);
f*=10;
curveVertex(x, -f);
}
endShape();
※この画像のグラフは、横は-5〜5、縦は-0.5〜0.1となっている。つまり、かなり、上下方向に拡大されている。
式を簡略化した場合。
Processing
size(1000, 600);
noFill();
translate(500, 500);
scale(100);
strokeWeight(0.01);
beginShape();
for (float x = -5; x < 5; x+=0.01) {
float f = 4*exp(-x*x/2f);
curveVertex(x, -f);
}
endShape();
さらに、計算量少なそうな式に変更。
Processing
size(1000, 600);
noFill();
translate(500, 500);
scale(100);
strokeWeight(0.01);
beginShape();
for (float x = -5; x < 5; x+=0.01) {
float f = 4/(1+x*x);
curveVertex(x, -f);
}
endShape();