Skip to content
This repository was archived by the owner on Dec 6, 2021. It is now read-only.

Commit 05c86eb

Browse files
author
OverPoweredDev
committed
added sine plotting
1 parent be9a25b commit 05c86eb

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

cpp_implementation/sine_encoder/plotter.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#include <graphics.h>
33
#define PI 3.141
44

5-
void drawAxes(int offset_x, int freq) {
5+
void drawAxes(int offset_x, int period) {
66
line(0, getmaxy() / 2, getmaxx(), getmaxy() / 2);
7-
for(int x = offset_x; x < getmaxx(); x += freq){
7+
for(int x = offset_x; x < getmaxx(); x += period){
88
circle(x, getmaxy()/2, 3);
99
}
1010
line(offset_x, 0, offset_x, getmaxy());
@@ -13,8 +13,10 @@ void drawAxes(int offset_x, int freq) {
1313
void sine_wave(double offset_x, double amplitude, double phase_shift, double time_period){
1414
double y;
1515
for (double angle = 0, x = offset_x; x < getmaxx(); x += 1, angle += 1) {
16+
// angle = 0, x = offset_x for wave starting at origin,
17+
// angle = -phase_shift, x = offset_x-phase_shift for wave starting at 0 degrees
1618
//angle is in degrees, not radians
17-
// y = amplitude * sin((((360.0/151.0)*(angle + rads)) * PI / 180.0));(2*PI/time_period)*
19+
//x is also basically just angle, its just easier to manage them separately cause graphics.h has a weird graph system
1820
y = amplitude * sin((angle + phase_shift)*(2*PI/time_period));
1921
y = getmaxy()/2 - y;
2022

@@ -29,13 +31,13 @@ int main() {
2931
double offset_x = 100;
3032

3133
//assignment variables
32-
double rollnum = 49.0;
34+
double roll_num = 49.0;
3335
int amplitude = 100;
3436
// double time_period = 360;
3537
// double rads = 0;
36-
double time_period = 200 - rollnum; // 151
37-
double rads = rollnum/20.0; // 2.45
38-
double phase_shift = rads*(time_period/(2*PI)); // 140.4
38+
double time_period = 200 - roll_num; // 151
39+
double rads = roll_num/20.0; // 2.45
40+
double phase_shift = rads*(time_period/(2*PI)); // 140.4
3941

4042
initgraph(&gd, &gm, nullptr);
4143
drawAxes(offset_x, time_period);

0 commit comments

Comments
 (0)