Belief distributions for a non-sensing robot after moving for several steps in two dimensions. The diagram was generated using the following c++ code, hereby licensed under the same license as the diagram itself:
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <fstream>
#include <sstream>
using namespace std;
const int M = 2000;
const long double
ANGLE_NOISE = 0.04,
ANGLE_P_NOISE = 0.0002,
ANGLE_R_NOISE = 0.02,
R_NOISE = 3,
R_P_NOISE = 0.008,
PI = 3.1415926535897932384626433832795028;
struct particle {
long double x, y;
long double theta;
};
vector<particle>z;
particle qwer;
fstream fout("particle2d.svg", fstream::out);
ostringstream poly;
inline long double noise() {
return (rand()/(long double)RAND_MAX) - (rand()/(long double)RAND_MAX) + (rand()/(long double)RAND_MAX) - (rand()/(long double)RAND_MAX);
}
void move(long double r, long double t) {
qwer.theta += t;
qwer.x += r*cos(qwer.theta);
qwer.y += r*sin(qwer.theta);
for(int i=0; i<M; i++) {
z[i].theta += t + r*ANGLE_P_NOISE*noise() + ANGLE_NOISE*noise() + t*ANGLE_R_NOISE*noise();
z[i].x += r*cos(z[i].theta) + R_NOISE*noise() + r*R_P_NOISE*noise();
z[i].y += r*sin(z[i].theta) + R_NOISE*noise() + r*R_P_NOISE*noise();
fout << " <circle cx='" << z[i].x << "' cy='" << z[i].y << "' r='1' style='fill:#000;opacity:0.8;'/>" << endl;
}
fout << " <circle cx='" << qwer.x << "' cy='" << qwer.y << "' r='6' style='fill:#f30;'/>" << endl;
fout << " <path d='M" << qwer.x - r/2.4*cos(qwer.theta) << "," << qwer.y - r/2.4*sin(qwer.theta)
<< "L" << qwer.x - r/2*cos(qwer.theta - 0.05) << "," << qwer.y - r/2*sin(qwer.theta - 0.05)
<< "L" << qwer.x - r/2*cos(qwer.theta + 0.05) << "," << qwer.y - r/2*sin(qwer.theta + 0.05) << "' style='fill:#f30;'/>" << endl;
poly << qwer.x << ',' << qwer.y << ' ';
}
int main() {
particle start;
start.x = 800;
start.y = 100;
start.theta = 0;
qwer = start;
for(int i=0; i<M; i++) {
z.push_back(start);
}
fout << "<svg xmlns='http://www.w3.org/2000/svg' version='1.1' width='1600px' height='1000px'>" << endl;
fout << " <circle cx='" << qwer.x << "' cy='" << qwer.y << "' r='5' style='fill:#f30;'/>" << endl;
poly << qwer.x << ',' << qwer.y << ' ';
move(200, 0);
move(200, 0);
move(200, 0);
move(200, PI/2);
move(200, 0);
move(200, 0);
move(200, PI/2);
move(200, 0);
move(200, 0);
move(200, 0);
move(200, 0);
move(200, 0);
fout << "<polyline points='" << poly.str() << "' style='fill:none;stroke:#f30;stroke-width:2px' />" << endl;
fout << "</svg>" << endl;
fout.close();
}