Jump to content

File:Particle2dmotion.svg

Page contents not supported in other languages.
This is a file from the Wikimedia Commons
From Wikipedia, the free encyclopedia

Original file (SVG file, nominally 1,600 × 1,000 pixels, file size: 1.74 MB)

Summary

Description
English: 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();
}
Date
Source Own work
Author Daniel Lu

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

25 March 2013

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current07:57, 25 March 2013Thumbnail for version as of 07:57, 25 March 20131,600 × 1,000 (1.74 MB)DlluUser created page with UploadWizard

Global file usage

The following other wikis use this file:

Metadata