#include <vector>
#include <iterator>
#include <cmath>
#define MAX_PLOT_FIELD_NORM 100
#define PLOT_FIELD_SCALE .002
#define MESH_SIZE 40
#define V_MIN -10
#define V_MAX 20
#define NB_V_CONTOURS 20
#define NB_STALLED_FRAMES 20
#define NB_FRAMES_1 200
#define NB_FRAMES_2 100
#define MOTION_X0 .3
#define MOTION_Y0 -.5
#define MOTION_AMPLITUDE 2
#define ROTATION_VIEW .1
int main(int argc, char* argv[]) {
if(argc != 2) {
std::cout << "Usage : " << argv[0] << " run | elec-plot.py" << std::endl
<< " " << argv[0] << " run | elec-plotV.py" << std::endl;
return 0;
}
std::vector<elec::Particle> particles;
particles.push_back(
elec::proton ({-MOTION_X0, MOTION_Y0 }));
particles.push_back(
elec::proton ({ MOTION_X0, MOTION_Y0 }));
particles.push_back(
elec::electron({ 0, MOTION_Y0 + MOTION_AMPLITUDE }));
std::vector<elec::Point>
mesh;
std::vector<elec::Point> Efield;
std::vector<double> Vfield;
elec::mesh(min,max,MESH_SIZE,MESH_SIZE,std::back_inserter(mesh));
double a = 20;
Efield.clear();
elec::E(particles.begin(), particles.end(),mesh.begin(), mesh.end(),std::back_inserter(Efield));
Vfield.clear();
elec::V(particles.begin(), particles.end(),mesh.begin(), mesh.end(),std::back_inserter(Vfield));
for(unsigned int frame_id = 0; frame_id < NB_STALLED_FRAMES; ++frame_id, a+=ROTATION_VIEW) {
plot.begin_frame("frame","jpg");
plot.set_view(15,a);
plot.__plot_potential(mesh.begin(), mesh.end(), Vfield.begin(), Vfield.end(), V_MIN, V_MAX, NB_V_CONTOURS);
plot.__plot_field(mesh.begin(), mesh.end(), Efield.begin(), Efield.end(),PLOT_FIELD_SCALE,MAX_PLOT_FIELD_NORM);
plot.__plot_particles(particles.begin(), particles.end());
plot.end_frame();
}
for(unsigned int frame_id = 0; frame_id < NB_FRAMES_1; ++frame_id, a+=ROTATION_VIEW) {
particles[2].pos.y = MOTION_Y0 + MOTION_AMPLITUDE*(NB_FRAMES_1-1-frame_id)/(double)(NB_FRAMES_1-1);
Efield.clear();
Vfield.clear();
elec::E(particles.begin(), particles.end(),mesh.begin(), mesh.end(),std::back_inserter(Efield));
elec::V(particles.begin(), particles.end(),mesh.begin(), mesh.end(),std::back_inserter(Vfield));
plot.begin_frame("frame","jpg");
plot.set_view(15,a);
plot.__plot_potential(mesh.begin(), mesh.end(), Vfield.begin(), Vfield.end(), V_MIN, V_MAX, NB_V_CONTOURS);
plot.__plot_field(mesh.begin(), mesh.end(), Efield.begin(), Efield.end(),PLOT_FIELD_SCALE,MAX_PLOT_FIELD_NORM);
plot.__plot_particles(particles.begin(), particles.end());
plot.end_frame();
}
for(unsigned int frame_id = 0; frame_id < NB_FRAMES_2; ++frame_id, a+=ROTATION_VIEW) {
double r = MOTION_X0;
double theta = M_PI_2*(frame_id)/(double)(NB_FRAMES_2-1);
particles[2].pos = O +
elec::Point(std::cos(theta),std::sin(theta))*r;
Efield.clear();
Vfield.clear();
elec::E(particles.begin(), particles.end(),mesh.begin(), mesh.end(),std::back_inserter(Efield));
elec::V(particles.begin(), particles.end(),mesh.begin(), mesh.end(),std::back_inserter(Vfield));
plot.begin_frame("frame","jpg");
plot.set_view(15,a);
plot.__plot_potential(mesh.begin(), mesh.end(), Vfield.begin(), Vfield.end(), V_MIN, V_MAX, NB_V_CONTOURS);
plot.__plot_field(mesh.begin(), mesh.end(), Efield.begin(), Efield.end(),PLOT_FIELD_SCALE,MAX_PLOT_FIELD_NORM);
plot.__plot_particles(particles.begin(), particles.end());
plot.end_frame();
}
for(unsigned int frame_id = 0; frame_id < NB_STALLED_FRAMES; ++frame_id, a+=ROTATION_VIEW) {
plot.begin_frame("frame","jpg");
plot.set_view(15,a);
plot.__plot_potential(mesh.begin(), mesh.end(), Vfield.begin(), Vfield.end(), V_MIN, V_MAX, NB_V_CONTOURS);
plot.__plot_field(mesh.begin(), mesh.end(), Efield.begin(), Efield.end(),PLOT_FIELD_SCALE,MAX_PLOT_FIELD_NORM);
plot.__plot_particles(particles.begin(), particles.end());
plot.end_frame();
}
return 0;
}