-
Notifications
You must be signed in to change notification settings - Fork 0
/
circle_charge.cpp
41 lines (28 loc) · 1.09 KB
/
circle_charge.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
#include "header.h"
#include <cmath>
CircleCharge::CircleCharge(int x, int y, int size, double value) : Charge(x, y, size, value){}
bool CircleCharge::isPointInside(int tx, int ty){
return ( (pow(x-tx, 2) + pow(y-ty, 2)) <= pow(size, 2) );
}
double CircleCharge::potInPoint(int tx, int ty){
double distance = sqrt( pow(tx-x, 2) + pow(ty-y, 2) );
return (k0*(value)) / distance;
}
//SFML takes as size radius not diameter in CircleShape constructor
void CircleCharge::drawCharge(sf::RenderWindow& window){
sf::CircleShape shape(size);
shape.setFillColor(GREY_CHARGE);
shape.setPosition(x-size , y-size);
window.draw(shape);
}
Vector CircleCharge::elFieldInPoint(int tx, int ty){
double distance = sqrt( pow(tx-x, 2) + pow(ty-y, 2) );
double alpha = mainField.angleFromPoints(tx,ty,x,y);
double intensity = (k0*value)/pow(distance,2);
return Vector(cos(alpha)*intensity,sin(alpha)*intensity,intensity,alpha);
}
Point CircleCharge::externalPoint(double alpha){
int tx = round(x+((size)*cos(alpha)));
int ty = round(y+((size)*sin(alpha)));
return Point(tx, ty, alpha);
}