-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforce.cpp
More file actions
74 lines (59 loc) · 1.62 KB
/
force.cpp
File metadata and controls
74 lines (59 loc) · 1.62 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Author: Nolan Schirripa, Christine Seng, Erick Martinez, Georgia Rushing, Graham Balas
* Assignment Title: Group Project (force.cpp)
* Assignment Description: defines force class that adds and sets force to ball
* Due Date: 12/09/2024
* Date Created: 10/25/2024
* Date Last Modified: 12/07/2024
*/
#include "force.h"
force::force(){
magnitude = 0;
direction = 0;
}
force::force(double m, double d){
magnitude = m;
direction = d;
}
force force::operator+(const force& other) const{
return add(other);
}
void force::apply(const force& other){
*this = add(other);
}
force force::add(const force& other) const{
force v;
double ax, ay;
double bx, by;
double theta, mag;
ax = magnitude * cos(direction);
bx = other.magnitude * cos(other.direction);
ay = magnitude * sin(direction);
by = other.magnitude * sin(other.direction);
theta = atan((ay+by)/(ax+bx));
if((ay+by) < 0 && theta > 0) theta += M_PI;
if((ay+by) > 0 && theta < 0) theta += M_PI;
mag = sqrt(pow(ax + bx, 2) + pow(ay + by, 2));
v.magnitude = mag;
v.setDirection(theta);
return v;
}
void force::setMagnitude(double m){
magnitude = m;
}
void force::setDirection(double d){
while(d > 2*M_PI ) d -= 2*M_PI;
while(d < 0) d += 2*M_PI;
direction = d;
}
double force::getMagnitude()const{
return magnitude;
}
double force::getDirection()const{
return direction;
}
force force::operator=(const force& other){
setMagnitude(other.magnitude);
setDirection(other.direction);
return *this;
}