-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphysics.cpp
62 lines (57 loc) · 1.86 KB
/
physics.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**\brief Implementation of functions defined in physics.h
* \author Henry J Schmale
* \date March 11, 2015
* \file physics.cpp
*/
#include "physics.h"
#include <glog/logging.h>
#include "config.h"
#include "constants.h"
using namespace std;
void calcElectroForceVecs(){
int i = 0;
double Et = 0;
for(double x = XMIN; x <= XMAX; x += DXY_RES){
for(double y = YMIN; y <= YMAX; y += DXY_RES){
if(i >= VECCOUNT){
continue;
}
Et = 0;
for(int n = 0; n < NUMSRCS; n++){
Et = (abs(ELECTRIC_FORCE * CHARGE_PROTON *
charges[n].m_charge) /
pow(calcDistance(&charges[n], x, y), 2));
double angle = atan2((y - charges[n].m_yPos),
(x - charges[n].m_xPos));
if(charges[n].m_charge > 0){
vectors[i].m_xC -= cos(angle) * Et;
vectors[i].m_yC -= sin(angle) * Et;
}else{
vectors[i].m_xC += cos(angle) * Et;
vectors[i].m_yC += sin(angle) * Et;
}
}
i++;
}
}
}
void calcUpdatedBallState(pithBall *b, double dT){
double F;
CHECK_NOTNULL(b);
CHECK(dT > 0);
b->px = b->cx; // Mv Current x&y to prevs
b->py = b->cy;
for(int n = 0; n < NUMSRCS; n++){
F = (abs(ELECTRIC_FORCE * b->charge * charges[n].m_charge) /
pow(calcDistance(&charges[n], b->cx, b->cy), 2));
double angle = atan2((b->cx - charges[n].m_yPos),
(b->cy - charges[n].m_xPos));
if(charges[n].m_charge > 0){
b->fx -= cos(angle) * F;
b->fy -= sin(angle) * F;
}else{
b->fx += cos(angle) * F;
b->fy += sin(angle) * F;
}
}
}